Wednesday, 21 August 2013

stub method only on the first call with Rspec

stub method only on the first call with Rspec

How can I stub a method only on the first call, and in the second one it
should behave as expected?
I have the following method:
def method
do_stuff
rescue => MyException
sleep rand
retry
end
I want to the first call of do_stuff to raise MyException, but in the
second call, behaves normally. I need to achieve this to test my rescue
block without getting an infinite loop.
Is there a way to achieve this?

No comments:

Post a Comment