How to handle multiple calls with different returns?
linkrope opened this issue · 3 comments
linkrope commented
class Dependency
{
public int foo() { assert(0); }
}
unittest
{
auto mocker = new Mocker;
auto dependency = mocker.mock!Dependency;
mocker.ordered;
mocker.expect(dependency.foo).returns(1);
mocker.expect(dependency.foo).returns(2);
mocker.replay;
assert(dependency.foo == 1);
assert(dependency.foo == 2);
mocker.verify;
}
throws ExpectationViolationException: Dependency.foo() Expected: 1..1 Actual: 2
linkrope commented
BTW:
In the real code, "foo" has a parameter of type Nullable!JSONValue.
So I just rediscovered your Issue 10771 - std.typecons.Nullable throws an exception on comparision of null values.
With ignoreArgs as kind of workaround, I stumbled into the next problem.
QAston commented
It's a bug that your example doesn't work.
About Nullable - looks like it's emulating behavior of null for structs, classes can't be compared when references are null so it's okay. I've updated the issue.
linkrope commented
OK
With your fix, I just completed the migration of the first example to dmocks - nice.