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

Evgeniy Dolzhenko dolzenko at gmail.com
Thu Nov 25 08:24:03 EST 2010

Speaking of `controller.controller_name`: inside of the view spec
controller is an instance of TestController and
`controller.controller_name` and `controller.action_name` won't return
you anything useful.
Though RSpec tries to help us here a little bit by inferring
`controller.controller_path` and `request.path_parameters` [1]. That's
what I ended up using instead of `action_name` in my views.

[1] https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/example/view_example_group.rb#L151

On Thu, Nov 18, 2010 at 8:52 PM, Vadim A. Venediktov <me at installero.com> wrote:
> 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?
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list