-
-
Notifications
You must be signed in to change notification settings - Fork 768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reset() does not reset a stub #806
Comments
This ticket is a bit convoluted. Are you reporting a bug or requesting a change? Stubs are intentionally cheap to create, so if you want fresh behaviour, just create another one? |
I would consider it a change request, which is
One could consider it also a design bug because a stub (being also a spy) has a While stubs are cheap to create, the objects where one needs to inject them might not be so cheap. So just creating a new stub might not be enough if need also to recreate the object where you inject the new stub. |
Did this just take away a feature? Before you could have acheived this by calling: stub.reset();
stub.resetBehvaior(); Now you can only call |
That's a good point. Perhaps it would be better if we expanded the api a bit. // resets both call history and behaviour
stub.reset();
// reset call history
stub.resetHistory();
// reset behaviour
stub.resetBehavior() |
Seems reasonable |
@mroderick That seems solid to me. |
So that the idea is not lost, I've created issue #863 for adding |
This change should be called out in the release notes as a breaking change. This is a change to the expected behavior of |
reset
resets only a spy but not a stubConsider this code:
it prints
if I change
stub.reset();
tostub.resetBehavior();
it works as expected, i.e. printsstub(1) Hello
.But
resetBehavior
is not documented (#267) and it would be more consistent and natural ifreset
works for both spies and stubs.Another option is to change
stub.reset();
tostub = sinon.stub();
.But It is not always feasible to create a new stub in each test. Consider this example:
The text was updated successfully, but these errors were encountered: