Is testing output within content_for possible?

I wanted to test that the links below were being rendered in the views.

  • content_for :sidebar do
    %li= edit_link edit_admin_contact_url(@contact), “Contact”

view test

it "should have the correct side bar links" do
  response.should have_tag("ul.links") do
    with_tag("a[href=?]", edit_admin_account_url(accounts(:test)))

The above doesn’t work. Just to make sure my tests weren’t the issue I
removed the content_for block and the tests then passed.

Is there something extra that has to be done to get the content_for
contents to be rendered?

Thanks for the help.

Chris O. wrote:

  response.should have_tag("ul.links") do

Thanks for the help.

Hey Chris,
AFAIK you can’t test content_for’s in the view specs. Someone may want
to correct me on that.

I usually test content_for stuff in my stories. If your not using
stories then you could try integrating the views on certain controller
specs and testing it there.

Not the answer you were probably looking for, but I hope that helps.


This might be of some use:

On Sat, Apr 19, 2008 at 9:55 PM, Ben M. [email protected] wrote:


Not the answer you were probably looking for, but I hope that helps.


rspec-users mailing list
[email protected]

Bryan R.

“Programming today is a race between software engineers striving to
bigger and better idiot-proof programs, and the Universe trying to
bigger and better idiots. So far, the Universe is winning.”

You can also render a testing layout which yields the content.
IE: render “foo”, :layout => “testing”

In layouts/testing.html.erb:

<%= yield :sidebar %>


Bryan R. wrote:

This might be of some use:

That should do it!

Thanks Bryan

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs