In RSpec, is there a method equivalent to "unstub" but for "should_receive"?

p.matsinopoulos picture p.matsinopoulos · Jun 1, 2012 · Viewed 24.9k times · Source

Is there any method to remove any stubbing and mocking while using RSpec?

Example:

RestClient.should_receive(:delete).with("http://www.example.com")
...
... 

# this will remove the mocking of "should_receive" and 
# restore the proper "delete" method on "RestClient".
RestClient.mocking_reset

(mocking_reset is my ficticious name for the required functionality).

I know that there is the method "unstub" which resets "stubs" but not "should_receive"s.

So, is there any method equivalent to "unstub" but for "should_receive"?

Panayotis

Answer

Waiting for Dev... picture Waiting for Dev... · Jan 27, 2015

You can overwrite some previous mocking by:

expect(RestClient).to receive(:delete).and_call_original

Or if it is wasn't any kind of expectation, just a simple stub:

allow(RestClient).to receive(:delete).and_call_original

Remember there exists also expect_any_instance_of and allow_any_instance_of.