Open lawrencepit opened 15 years ago
It looks like there are multiple calls to render.
Try: stub(template).render.verbose mock(template).render(:partial => "layouts/resources")
The output I get is then:
render({:layout=>nil, :file=>"holidays/index.html.haml", :locals=>{}})
should render the resources layout partial
render({:partial=>"layouts/resources"})
Called 0 times.
Expected 1 times.
I can confirm this behavior in rr 0.10.11, rails 2.3.5, rspec 1.3
There is def, as you suggested, a double call to render. This is expected - first the parent view starts rendering, then the child (or partial) view renders. 2 calls to template.render
Rspec mocks can handle this scenario just fine (as noted by OP). Even more confusing is the fact that most examples in the readme deal with the 'doubling' of render(:partial) yet I can't get this to work in view specs at all. Thoughts on how we can set rr up to do this? Any work around? I've tried numerous combinations/setups with no luck.
Regardless thanks for the cool framework. I'm really hoping to switch to this syntax. It's so nice.
I dove into the source and found a solution to this. You can write the test as follows:
mock.proxy(template).render(anything).any_number_of_times
render
template.should have_received({:partial => "layouts/resources"})
I was hoping to be able to use spies (since they seem more appropriate here) but there is a catch the following passes ok but when it's intentionally broken rspec hangs.
spy(template)
render
template.should have_received.render({:partial => 'layouts/resources'})
I'll open a new issue to get to the bottom of that one.
I'll go ahead and mark this as a feature. If you mock a method exactly then it should not prevent the method from being called with other arguments.
Using rails 2.3.3 and rspec 1.2.6, my view is simply this:
My rspec test looks like this:
Which results in:
Any advice?