[rspec-users] Problem specing application layout, missing partial?

David Chelimsky dchelimsky at gmail.com
Mon Jul 5 12:16:57 EDT 2010


On Jul 5, 2010, at 9:52 AM, Pixel wrote:

> In an effort to teach myself BDD I'm trying it out.  I'm trying to do a simple (should be straightforward) spec on my application.html.haml file first looking for a div tag with the class 'nav'  it seems that rspec isn't able to render the app/views/layouts/application.html.haml file.  
> Gist with command/error/backtrace: http://gist.github.com/463978#file_gistfile1.txt

Short version:

Don't pass anything to render() in the spec. It'll do the right thing as long as you name the template in the string passed to describe:

require "spec_helper"

describe "layouts/application.html.haml" do
  it "displays a navigation area" do
    render
    rendered.should have_selector('div#nav')
  end
end

Only slightly longer version:

There are some confusing things about the render() method in ActionView::Base, which is ultimately what renders the the template. View specs handle this for you by building the hash that Rails' render() is looking for when you don't pass anything to render. In this case, the example above results in the equivalent of:

require "spec_helper"

describe "layouts/application.html.haml" do
  it "displays a navigation area" do
    render :template => "layouts/application.html.haml"
    rendered.should have_selector('div#nav')
  end
end

HTH,
David


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100705/cb94c025/attachment.html>


More information about the rspec-users mailing list