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


_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to