Chris Olsen
2008-Apr-19 22:57 UTC
[rspec-users] 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 %ul.links %li= edit_link edit_admin_contact_url(@contact), "Contact" # view test it "should have the correct side bar links" do do_render response.should have_tag("ul.links") do with_tag("a[href=?]", edit_admin_account_url(accounts(:test))) end end 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. -- Posted via http://www.ruby-forum.com/.
Ben Mabey
2008-Apr-20 02:55 UTC
[rspec-users] Is testing output within content_for possible?
Chris Olsen wrote:> I wanted to test that the links below were being rendered in the views. > > - content_for :sidebar do > %ul.links > %li= edit_link edit_admin_contact_url(@contact), "Contact" > > > # view test > it "should have the correct side bar links" do > do_render > response.should have_tag("ul.links") do > with_tag("a[href=?]", edit_admin_account_url(accounts(:test))) > end > end > > 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. >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. -Ben
Bryan Ray
2008-Apr-20 16:18 UTC
[rspec-users] Is testing output within content_for possible?
This might be of some use: http://rubyforge.org/pipermail/rspec-users/2007-June/001954.html On Sat, Apr 19, 2008 at 9:55 PM, Ben Mabey <ben at benmabey.com> wrote:> Chris Olsen wrote: > > I wanted to test that the links below were being rendered in the views. > > > > - content_for :sidebar do > > %ul.links > > %li= edit_link edit_admin_contact_url(@contact), "Contact" > > > > > > # view test > > it "should have the correct side bar links" do > > do_render > > response.should have_tag("ul.links") do > > with_tag("a[href=?]", edit_admin_account_url(accounts(:test))) > > end > > end > > > > 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. > > > > 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. > > -Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Bryan Ray http://www.bryanray.net "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080420/8c253b2e/attachment-0001.html
Chris Olsen
2008-Apr-20 17:00 UTC
[rspec-users] Is testing output within content_for possible?
Bryan Ray wrote:> This might be of some use: > > http://rubyforge.org/pipermail/rspec-users/2007-June/001954.html >That should do it! Thanks Bryan -- Posted via http://www.ruby-forum.com/.
Zach Dennis
2008-Apr-20 20:09 UTC
[rspec-users] Is testing output within content_for possible?
You can also render a testing layout which yields the content. IE: render "foo", :layout => "testing" In layouts/testing.html.erb: <%= yield :sidebar %> Zach On Sun, Apr 20, 2008 at 1:00 PM, Chris Olsen <lists at ruby-forum.com> wrote:> Bryan Ray wrote: > > This might be of some use: > > > > http://rubyforge.org/pipermail/rspec-users/2007-June/001954.html > > > > That should do it! > > Thanks Bryan > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080420/c0b89ee6/attachment.html