[rspec-users] Testing layouts with RSpec on Rails

David Chelimsky dchelimsky at gmail.com
Mon Oct 22 05:51:24 EDT 2007


On 10/22/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> Actually, it turns out that you can do this in a view spec:
>
> render "/path/to/my/file.html.erb", :layout => "application"
>
> and it will render with the layout. So you *could* (in theory, I
> haven't done this yet) do something like this:

Actually - I had tried this before I sent the email - I just forgot to
edit this part :)

It does work. It's not perfect, but it does work.

>
> # spec/resources/views/layout_example.html.erb
> <div>yielded from layout</div>
>
> # spec/views/layouts/application.html.erb_spec.rb
> require File.dirname(__FILE__) + '/../../spec_helper'
>
> describe "/layouts/application" do
>
>   it "should yield" do
>     render "/../../spec/resources/views/layout_example.html.erb",
> :layout => "application"
>     response.should have_tag('div','yielded from layout')
>   end
>
>   it "should have title" do
>     render "/../../spec/resources/views/layout_example.html.erb",
> :layout => "application"
>     response.should have_tag("div.idbar","My Killer App")
>   end
>   ...
> end
>


More information about the rspec-users mailing list