[rspec-users] Rspec: rendering a certain template with a certain layout is needed

Vadim A. Venediktov me at installero.com
Thu Nov 18 12:52:57 EST 2010


Hello!

I was trying render my view with a custom layout:

render :template => "cards/show.html.erb", :layout => 'application'

And caught an error:

 Failure/Error: render :text => 'Text', :layout => 'application'
 Missing template /application with {:handlers=>[:rhtml, :rxml, :erb,
:rjs, :builder], :locale=>[:ru, :ru], :formats=>[:html]} in view paths
"/home/install/webdev/pkl/app/views",
"/home/install/webdev/pkl/.bundle/ruby/1.8/gems/devise-1.1.3/app/views"

After searching for a while I ran against this thread:
http://forums.pragprog.com/forums/95/topics/3952

I wonder what should I do if I have controller/action specific
translations in my layout, like this:

<% @title = t("#{controller.controller_name}.#{controller.action_name}.title")
if @title.blank? %>

BTW, do you find it reasonable? I'm using this variable two times in
my layout, and I want to check whether my page is translated properly,
so I write a macros with a spec:

it "should be translated" do
  render
  rendered.should_not have_selector('span', :class => 'translation_missing')
end

but it does not render layout, so everything is fine even if I don't
have my title: 'Title' set in i18n yml files.

I have a spec to test my layout, but is knows nothing about
controller, so it can't test @title's translated properly niether.

I know, that I can do something like <%= yield :title %> in my layout
and test content for title in every view spec, but this causes me to
set :content_for 'title' in every view template, which does not sound
great. What could you advise for this tricky situation?


More information about the rspec-users mailing list