Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

AssertExpectations re-evaluates MatchedBy() functions #504

Open
decibel opened this issue Sep 19, 2017 · 1 comment
Open

AssertExpectations re-evaluates MatchedBy() functions #504

decibel opened this issue Sep 19, 2017 · 1 comment

Comments

@decibel
Copy link

decibel commented Sep 19, 2017

It appears that AssertExpectations always re-executes every MatchedBy() function. That's a problem if the matcher isn't re-entrant. It's not hard to work around (see below), but it would be nice if the function was never evaluated a second time.

My fix:

mockAlreadyCalled := false
mock.On("bleh", mock.MatchedBy ... {
    if mockAlreadyCalled { return true }
    mockAlreadyCalled = true
...
@ernesto-jimenez
Copy link
Member

The problem is AssertExpectations re-evaluates everything, which has other problems: mock is storing the calls internally to replicate on the assertions, which in turn means that it can have a false failure if the mocked method received a pointer and the underlying object was mutated after the call succeeded.

Last time I looked into this it was quite tricky to fix that behaviour without introducing breaking changes.

Happy to receive proposals that would be backwards-compatible, though.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants