Reputation: 779
How to make stub in rspecs to behave differently on each call
for example,
teststub.onCall(0).stub(:testmethod).and_raise(Exception)
teststub.onCall(1).stub(:testmethod).and_return(true)
Seems like rspecs don't have onCall
construct. how can i achieve this?
Upvotes: 0
Views: 51
Reputation: 4368
Replace the implementation of it. Then you can do whatever you want with it. Including but not limited to behaving differently on each call.
teststub.stub(:testmethod) do
if @already_raised
true
else
@already_raised = true
raise Exception
end
end
Upvotes: 1