Marcus Crafter
2007-Jul-16 11:02 UTC
[rspec-users] Accessing content_for html in view specs?
Hi All, Hope all is going well. I''ve got a few views that create some content using ''content_for'' blocks <% content_for :blah do %> ..... <% end %> Has anyone worked out a way to be able to access the html that''s generated inside those blocks? Since they''re not part of the view, have_tag('''') seems to miss them, and at the moment I can''t find a way to be able to access the generated content? Any thoughts, ideas appreciated. Cheers, Marcus
David Chelimsky
2007-Jul-16 11:04 UTC
[rspec-users] Accessing content_for html in view specs?
On 7/16/07, Marcus Crafter <crafterm at gmail.com> wrote:> Hi All, > > Hope all is going well. > > I''ve got a few views that create some content using ''content_for'' blocks > > <% content_for :blah do %> > ..... > <% end %> > > Has anyone worked out a way to be able to access the html that''s > generated inside those blocks? > > Since they''re not part of the view, have_tag('''') seems to miss them, > and at the moment I can''t find a way to be able to access the > generated content? > > Any thoughts, ideas appreciated.Since have_tag wraps assert_select, you may want to post this to the rails mailing lists as well.> > Cheers, > > Marcus > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On 16 Jul 2007, at 12:02, Marcus Crafter wrote:> <% content_for :blah do %> ..... <% end %> > Has anyone worked out a way to be able to access the html that''s > generated inside those blocks?It ends up in @content_for_blah, doesn''t it?
Marcus Crafter
2007-Jul-16 11:14 UTC
[rspec-users] Accessing content_for html in view specs?
On 16/07/2007, at 9:11 PM, Tom Stuart wrote:> On 16 Jul 2007, at 12:02, Marcus Crafter wrote: >> <% content_for :blah do %> ..... <% end %> >> Has anyone worked out a way to be able to access the html that''s >> generated inside those blocks? > > It ends up in @content_for_blah, doesn''t it?I thought it did too, but that''s a nil reference in the spec unfortunately. Cheers, Marcus
On 16 Jul 2007, at 12:14, Marcus Crafter wrote:> On 16/07/2007, at 9:11 PM, Tom Stuart wrote: >> On 16 Jul 2007, at 12:02, Marcus Crafter wrote: >>> <% content_for :blah do %> ..... <% end %> >>> It ends up in @content_for_blah, doesn''t it? > I thought it did too, but that''s a nil reference in the spec > unfortunately.Well, it''s an instance variable in the view, not your spec. This was discussed recently on rspec-users (starts at http://rubyforge.org/ pipermail/rspec-users/2007-June/002222.html and continues into July) with the general consensus being that you can write a helper or use instance_eval if you *really* want to access your view''s instance variables, but that you''re almost always better off specifying this sort of behaviour by expecting the output to show up in the place where it''s meant to show up, e.g. have_tag() on the view that does yield :blah in your case, rather than fiddling about with state. Cheers, -Tom