[rspec-users] Accessing content_for html in view specs?

Tom Stuart tom at experthuman.com
Mon Jul 16 07:41:34 EDT 2007


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


More information about the rspec-users mailing list