Hi guys,

I am a Rspec newbie and am having problems creating a spec for a RoR helper
method.

I have in fact already implemented the helper method and am trying to create
retrospective specs. I know its the wrong way to do it but I am still
learning Rspec.

In my view I have a call to a helper method.

<% body_class "users" %>

which sets a CSS class declaration in the content_for block which is then
used in the <body> tag in application.html.erb layout.

  def body_class(class_name)
    content_for(:body_class) { " class=\"#{class_name}\"" }
  end


I was trying the following in my view spec:

template.should_receive (:body_class).with("users").and_return('
class="users"')
render "/admin/users/index.html.erb", :layout => "application"
response.should have_tag('body.users')

I get a:

Expected at least 1 element matching "body.users", found 0.
<false> is not true.

when I printed the response.body to screen it does not contain he CSS class
declaration on the body tag, where as running mongrel and going to the page
everything is fine.

what am I doing wrong? I ended up doing:

render "/admin/users/index.html.erb", :layout => "application"
response[:body_class].should == ' class="users"'

I am interested to know why my first attempt did not work.
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to