Reputation: 31630
Normally in my Rails controller tests, I'll do before { Website.any_instance.stub(:save).and_return(false) }
to test what happens when the record does not save. It looks like any_instance
went away with Rspec 3.
I tried using before { allow(Website).to receive(:save).and_return(false) }
for Rspec 3, but now I get this error:
Website(id: integer, ...) does not implement: save
Is there a replacement for the very useful any_instance
with Rspec 3?
Upvotes: 19
Views: 6716
Reputation: 29349
Try this
allow_any_instance_of(Website).to receive(:save).and_return(false)
Eg: https://github.com/rspec/rspec-mocks#settings-mocks-or-stubs-on-any-instance-of-a-class
Upvotes: 39