DMocks-revived
DMocks-revived copied to clipboard
Allow for custom comparison of arguments
When a function to be mocked has an argument for which the comparison with ==
does not work, you have to switch to ignoreArgs
and to action
. In the action block you have to explicitly compare all simple arguments with ==
and the offending one with your own custom comparison.
One example of an offending argument is Nullable!T()
, where ==
throws.
It would be nice, when the comparison of arguments could be customized. Then you would provide a specialized equality predicate for a type like Nullable!JSONValue
(or even JSONValue
) and could use the mock framework as usual.
BTW:
When I accidentally inserted an action
before returns
, it was somewhat surprising that the action
is quietly discarded.
Just to note, custom comparison is possible now, the only remaining problem now is with specifying action.
The current solution is much better than the original ignoreArgs
and action
hack. It's only that I encountered some problems in my first try of the customArgsComparator
.
I have to mock functions with more than one problematic type. So the custom comparator needs to switch on the type, which is usually a bad thing. Template specializations, for example, would be nice, but I don't know how to do this kind of type switching on Dynamic
objects.
Often, I have to mock different calls of functions with a problematic type. To avoid code duplication, I factored out the comparison, but intuitively I created a comparator function. So I have to wrap this function into the required delegate.
And then I have to add customArgsComparator(&comparator)
at each corresponding call of expect
instead of somehow "registering" the comparator at the mocker.
For some reason spam bots like this issue, so I'm closing it.