Rails RR Framework: multiple calls to instance_of instance
I would like to write an RSpec for my controller using RR.
I wrote the following code:
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe RegistrationController do
it "should work" do
#deploy and approve are member functions
stub.instance_of(Registration).approve { true }
stub.instance_of(Registration).deploy { true }
post :register
end
end
However, RR only blocks deployment when it still calls the approve method .
What syntax should I use to block both method calls for all instances of the registration class?
UPDATE: I achieved the desired result with [Mocha]
Registration.any_instance.stubs(:deploy).returns(true)
Registration.any_instance.stubs(:approve).returns(true)
0
a source to share
2 answers
As far as I know RSpec mocks doesn't let you do this. Are you sure you need to mute all instances? I usually follow this pattern:
describe RegistrationController do
before(:each) do
@registration = mock_model(Registration, :approve => true, :deploy => true)
Registration.stub!(:find => @registration)
# now each call to Registration.find will return my mocked object
end
it "should work" do
post :register
reponse.should be_success
end
it "should call approve" do
@registration.should_receive(:approve).once.and_return(true)
post :register
end
# etc
end
After completing the lookup method of the registration class you control which object is returned to the BOM.
-1
a source to share