Improve verify failure message; more tests (#131)
Improve verify failure message; more tests
diff --git a/lib/src/mock.dart b/lib/src/mock.dart
index 99d1d64..7bb81a5 100644
--- a/lib/src/mock.dart
+++ b/lib/src/mock.dart
@@ -464,7 +464,8 @@
.map((key) =>
"${_symbolToString(key)}: ${invocation.namedArguments[key]}")
.join(", ");
- args += ", {$namedArgs}";
+ if (args.isNotEmpty) args += ", ";
+ args += "{$namedArgs}";
}
var method = _symbolToString(invocation.memberName);
diff --git a/test/verify_test.dart b/test/verify_test.dart
index 27d77ed..eab950a 100644
--- a/test/verify_test.dart
+++ b/test/verify_test.dart
@@ -23,6 +23,7 @@
String methodWithListArgs(List<int> x) => 'Real';
String methodWithPositionalArgs(int x, [int y]) => 'Real';
String methodWithNamedArgs(int x, {int y}) => 'Real';
+ String methodWithOnlyNamedArgs({int y, int z}) => 'Real';
String methodWithObjArgs(RealClass x) => 'Real';
String get getter => 'Real';
set setter(String arg) {
@@ -71,11 +72,6 @@
test('should verify method with normal args', () {
mock.methodWithNormalArgs(42);
- expectFail(
- 'No matching calls. All calls: MockedClass.methodWithNormalArgs(42)\n'
- '$noMatchingCallsFooter', () {
- verify(mock.methodWithNormalArgs(43));
- });
verify(mock.methodWithNormalArgs(42));
});
@@ -183,6 +179,51 @@
verify(mock.setter = 'A');
});
+ test(
+ 'should fail when no matching call is found, '
+ 'and there are no unmatched calls', () {
+ expectFail(
+ 'No matching calls (actually, no calls at all).\n'
+ '$noMatchingCallsFooter', () {
+ verify(mock.methodWithNormalArgs(43));
+ });
+ });
+
+ test(
+ 'should fail when no matching call is found, '
+ 'and there is one unmatched call', () {
+ mock.methodWithNormalArgs(42);
+ expectFail(
+ 'No matching calls. All calls: MockedClass.methodWithNormalArgs(42)\n'
+ '$noMatchingCallsFooter', () {
+ verify(mock.methodWithNormalArgs(43));
+ });
+ });
+
+ test(
+ 'should fail when no matching call is found, '
+ 'and there are multiple unmatched calls', () {
+ mock.methodWithNormalArgs(41);
+ mock.methodWithNormalArgs(42);
+ expectFail(
+ 'No matching calls. All calls: '
+ 'MockedClass.methodWithNormalArgs(41), MockedClass.methodWithNormalArgs(42)\n'
+ '$noMatchingCallsFooter', () {
+ verify(mock.methodWithNormalArgs(43));
+ });
+ });
+
+ test(
+ 'should fail when no matching call is found, '
+ 'and unmatched calls have only named args', () {
+ mock.methodWithOnlyNamedArgs(y: 1);
+ expectFail(
+ 'No matching calls. All calls: MockedClass.methodWithOnlyNamedArgs({y: 1})\n'
+ '$noMatchingCallsFooter', () {
+ verify(mock.methodWithOnlyNamedArgs());
+ });
+ });
+
test('should throw meaningful errors when verification is interrupted', () {
var badHelper = () => throw 'boo';
try {