dashbitco / mox

Mocks and explicit contracts in Elixir
1.35k stars 77 forks source link

Calling `verify!` should raise a `Mox.VerificationError` if there are too many calls to a mock #141

Open metavida opened 1 year ago

metavida commented 1 year ago

Similar to comments in Issue #32, there are certain cases when we want to assert that a mocked function is never called (or is not over-called) but where the expected calls happen within code that either async or has aggressive error handling. In these cases it's desirable for verify! (and verify_on_exit!) to inform the user when an expectation has been violated by receiving too many calls.

Currently this PR does not implement a solution but does contribute 4 net-new verify! unit tests that should begin passing once this behavior is implemented.

Does this seem like a reasonable request/approach?

josevalim commented 1 year ago

Currently this PR does not implement a solution but does contribute 4 net-new verify! unit tests that should begin passing once this behavior is implemented.

Would it be possible to add new tests instead of changing the existing suite?

metavida commented 1 year ago

Would it be possible to add new tests instead of changing the existing suite?

Thanks for this comment! It inspired me to simplify this PR so that now it only introduces the 4 new (currently failing) tests. If you think these 4 new tests deserve to be in their own describe blocks or in their own test file just let me know!

I've separated the other, tangential improvements to verify tests into separate PR: #142

josevalim commented 1 year ago

Perfect, Yes, this looks good to me. Looking forward to a possible solution. :)

whatyouhide commented 9 months ago

@metavida any chance you're picking this up anytime soon? Otherwise, I can give it a try.

metavida commented 9 months ago

Go for it! I do not have any near term plans to work on this.