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?

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
Kevin Bullaughey
  • 2,556
  • 25
  • 37

1 Answers1

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

dre-hh
  • 7,840
  • 2
  • 33
  • 44
  • 1
    Ah, I didn't know I could redefine it. Seems obvious now! I also see I can redefine with `allow` as well. Thanks! – Kevin Bullaughey Jun 23 '14 at 19:51
  • 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_original` – lu1s Nov 16 '17 at 20:53