DMocks-revived icon indicating copy to clipboard operation
DMocks-revived copied to clipboard

Allow for custom comparison of arguments

Open linkrope opened this issue 11 years ago • 3 comments

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.

linkrope avatar Jan 27 '14 16:01 linkrope

BTW: When I accidentally inserted an action before returns, it was somewhat surprising that the action is quietly discarded.

linkrope avatar Jan 27 '14 17:01 linkrope

Just to note, custom comparison is possible now, the only remaining problem now is with specifying action.

QAston avatar Mar 19 '14 16:03 QAston

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.

linkrope avatar Apr 29 '14 10:04 linkrope

For some reason spam bots like this issue, so I'm closing it.

QAston avatar Mar 04 '24 12:03 QAston