[rspec-users] RSpec 2 view example: render_template

David Chelimsky dchelimsky at gmail.com
Sun Jun 20 09:09:46 EDT 2010


On Jun 20, 2010, at 8:06 AM, David Chelimsky wrote:

> On Jun 20, 2010, at 8:03 AM, David Chelimsky wrote:
> 
>> 
>> On Jun 20, 2010, at 7:30 AM, Michael Schuerig wrote:
>> 
>>> On http://github.com/rspec/rspec-rails under "View specs" there's an 
>>> example
>>> 
>>> describe "events/index.html.erb" do
>>> it "renders _event partial for each event" do
>>>  assign(:events, [stub_model(Event), stub_model(Event)])
>>>  render
>>>  view.should render_template(:partial => "_event", :count => 2)
>>> end
>>> end
>>> 
>>> Is this indeed correct? From the outset, it looks wrong because it sets 
>>> an expectation (view.should ...) after the call to render.
> 
> Yeah - I see that this is confusing. Maybe we should change that to view.should have_rendered("..."). If so, we should also change response.should render_tempate("...") and response.should redirect_to("....") in controller specs.
> 
> WDTY?

I'm also toying with an idea that would allow you to set an expectation before and have it evaluate at the end. Kind of like message expectations from the outside, but the underlying implementation would be different. Not sure if it would work, and I'm not sure if it would help (might just make things more confusing). WDYT?


> 
>>> 
>>> Then, no matter if I leave that line where it is or put it before the 
>>> render, I get an exception
>>> 
>>> undefined method `render_template' for 
>>> #<RSpec::Core::ExampleGroup::Nested_1:0x7f6c0632fea0>
>> 
>> The README you're looking at is stored in git with git HEAD, and aligns with that code. This feature was added after the last release, and works as advertised if you're working with git HEAD, and will be part of the next release.
>> 
>> If you're using an earlier release, then you should follow the README for that release: http://github.com/rspec/rspec-rails/tree/v2.0.0.beta.12
>> 
>> HTH,
>> David
>> 
>> 
> 



More information about the rspec-users mailing list