[rspec-users] Multiple should_receive(:render).with

Alan Larkin
Fri, 14 Mar 2008 12:44:47 -0000

I''m trying to specify that a particular view must render two different
partials.
My spec looks like:

describe AClass do
   it do
     template.should_receive(:render).with(:partial =>
''foo'', :locals => { ... })
     ...
   end

   describe ''some conditional case'' do
     it do
       template.should_receive(:render).with(:partial =>
''bar'', :locals => { ... })
       ...
     end
   end
end

Rendering the foo partial passes off fine, but the spec fails when it comes to
rendering the bar partial:

Mock ''ActionView::Base'' expected :render with
({:partial=>"bar",
:locals=>{...}}) but received it with ({:partial=>"foo",
:locals=>{...}})

In the view the foo partial is rendered first, and presumably that is being
intercepted in the second example and thus failing. How do I avoid this?