rspec/rspec-rails — Issue #509: Missing partial in view specs with template inheritance
Author: cwadding
Created: 2012-02-28 04:24:47+00:00
State: open

I am writing view specs and using template inheritance in my rails app as in:

http://railscasts.com/episodes/269-template-inheritance

My rails app has no problem finding my templates through inheritance but my view spec cannot render the template since it can't find the template. I can manually specify exactly where the partial is in my view but that would defeat the purpose of template inheritance. Is there some workaround or a fix to test my views and have them pass when I have templates that inherit from partials from one another.

Here is an example

class BaseController < ApplicationController
# base controller logic
end

class SourcesController < BaseController
# source controller logic
end

/base/_resources.html.erb

Some HTML view content

/sources/index.html.erb

<%= form_tag multiple_sources_path, :method => :put, :remote => true do %>
<%= render "resources", :items => @sources %>
<% end %>

/spec/views/sources/index

before(:each) do
@sources = assign(:sources, Kaminari.paginate_array([
stub_model(Source, :name => "Source1", :cameras => [stub_model(Camera, :name => "Cam1")]),
stub_model(Source, :name => "Source2", :cameras => [stub_model(Camera, :name => "Cam2")])
]).page(1))
end
it "renders the resources partial" do
render
rendered.should render_template(:partial => "resources", :locals => { :items => @sources })
end