Argument matching doesn't work when the object is never equal to anything

Create issue
Issue #9 resolved
Michael Williamson created an issue

When using argument matchers, the match will fail if the argument is not equal to anything. For instance, the following will fail:

{{{ #!python class NeverEqual(object): def eq(self, other): return False obj = NeverEqual() fake = fudge.Fake().expects('save').with_args(arg.any_value()) }}}

whereas I would expect the above to pass.

I've fixed this by changing the order that arguments are tested for equality (essentially changed from actual == expected to expected == actual). Patch (including tests) attached.

Personally, I'm not sure that overloading equality to do argument matching is the best approach, but there again I haven't exactly had much experience in writing mocking frameworks!

Comments (2)

  1. Michael Williamson reporter

    I should just point out that this happens in plenty of cases, not just the example I used - that was the simplest example I could think of. Specifically, this bit me when using Django models.

  2. Log in to comment