Is there a way to unstub in RSpec?

rspec, ruby

Solution

With new `expect` syntax, `unstub` is deprecated. You can do:

# stub
allow(SomeClass).to receive(:a_method)

# do something...

# unstub
allow(SomeClass).to receive(:a_method).and_call_original

If the first `allow` contains `.with` or a block, I believe it'll still carry to the next call, so the next `allow` doesn't clear those things.

Problem

Searched the Relish docs, but did not find a way to unstub in RSpec. Is this possible?

Original source