-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Bug: Unexpected method calls are "forgotten" #608
Comments
Oops. Looks like I'm on an older one, this might be resolved now. |
Nope. It's much-improved by the addition of the testing.T injection (thank you @posener !), but non-test-injected ones still behave like this. I mean, I'm going to upgrade and put testing.T in there immediately in my code, that's excellent. But there's quite a lot of older code that could still benefit from fixing this. |
@Groxx You could do
Feel free to raise a PR for changes/refactoring. |
…expected method call panic. Fixes stretchr#608
…expected method call panic. Fixes stretchr#608.
Why did you, library creators, decided to panic on "Unexpected Method Call" rather than fail a test in |
In a nutshell: this test passes, despite the expectations being incorrect:
Granted, this isn't great code. But panic-capturing code is somewhat common in frameworks, and this can lead to tests passing despite clearly having incorrect mocks. The fact that
AssertExpectations
doesn't match behavior seems like a bug in testify.So far as I can tell, this is caused by this code below, in
mock/mock.go
.Because the panic occurs before the
call.totalCalls++
op (and possibly others!), no record of apanic
-ing call exists except for the panic.I don't know what all would be involved in correcting this though. Ideally this should both panic (which generally aborts the test prematurely) and record the error for reporting in
AssertExpectations
in case it's suppressed.The text was updated successfully, but these errors were encountered: