Multiple should_receive(:render).with

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?

Stub out the first one, something like

template.stub!(:render)

Then, each of your tests set the actual should_receive expectation.

-Corey

Corey H. wrote:

it comes to
rspec-users mailing list


rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Thanks.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs