How do I unstub in rspec 3 without enabling the old syntax?
Asked Answered
M

1

23

I am upgrading from rspec 2 to rspec 3 and would like to use the new syntax and not enable the old syntax. But I have a few stubs that I set up in my top-level before(:each) block that I selectively unstub where I want the original implementation.

Is there some equivalent way to remove a stub when I've defined it with the new allow syntax?

Michaelmas answered 23/6, 2014 at 18:31 Comment(0)
U
29

You could redifine them with

expect(Person).to receive(:find).and_call_original

which will additionaly check that the original :find method was called on person

Unblessed answered 23/6, 2014 at 19:47 Comment(2)
Ah, I didn't know I could redefine it. Seems obvious now! I also see I can redefine with allow as well. Thanks!Michaelmas
You need to specify the instance of the object you want to unstub. i.e. If my Person instance lives in company.boss, then you need to call expect(company.boss).to receive(:find).and_call_originalSunburst

© 2022 - 2024 — McMap. All rights reserved.