| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * A simple mocking/spy library. | 6 * A simple mocking/spy library. |
| 7 * | 7 * |
| 8 * ## Installing ## |
| 9 * |
| 10 * Use [pub][] to install this package. Add the following to your `pubspec.yaml` |
| 11 * file. |
| 12 * |
| 13 * dependencies: |
| 14 * mock: any |
| 15 * |
| 16 * And then run `pub install`. |
| 17 * |
| 18 * ## Using ## |
| 19 * |
| 8 * To create a mock objects for some class T, create a new class using: | 20 * To create a mock objects for some class T, create a new class using: |
| 9 * | 21 * |
| 10 * class MockT extends Mock implements T {}; | 22 * class MockT extends Mock implements T {}; |
| 11 * | 23 * |
| 12 * Then specify the [Behavior] of the Mock for different methods using | 24 * Then specify the [Behavior] of the Mock for different methods using |
| 13 * [when] (to select the method and parameters) and then the [Action]s | 25 * [when] (to select the method and parameters) and then the [Action]s |
| 14 * for the [Behavior] by calling [thenReturn], [alwaysReturn], [thenThrow], | 26 * for the [Behavior] by calling [thenReturn], [alwaysReturn], [thenThrow], |
| 15 * [alwaysThrow], [thenCall] or [alwaysCall]. | 27 * [alwaysThrow], [thenCall] or [alwaysCall]. |
| 16 * | 28 * |
| 17 * [thenReturn], [thenThrow] and [thenCall] are one-shot so you would | 29 * [thenReturn], [thenThrow] and [thenCall] are one-shot so you would |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 * } | 92 * } |
| 81 * | 93 * |
| 82 * class MockFoo extends Mock implements Foo { | 94 * class MockFoo extends Mock implements Foo { |
| 83 * Foo real; | 95 * Foo real; |
| 84 * MockFoo() { | 96 * MockFoo() { |
| 85 * real = new Foo(); | 97 * real = new Foo(); |
| 86 * this.when(callsTo('bar')).alwaysCall(real.bar); | 98 * this.when(callsTo('bar')).alwaysCall(real.bar); |
| 87 * } | 99 * } |
| 88 * } | 100 * } |
| 89 * | 101 * |
| 102 * [pub]: http://pub.dartlang.org |
| 90 */ | 103 */ |
| 91 | 104 |
| 92 library mock; | 105 library mock; |
| 93 | 106 |
| 94 import 'dart:mirrors' show MirrorSystem; | 107 import 'dart:mirrors' show MirrorSystem; |
| 95 | 108 |
| 96 import 'matcher.dart'; | 109 import 'matcher.dart'; |
| 97 | 110 |
| 98 /** | 111 /** |
| 99 * The error formatter for mocking is a bit different from the default one | 112 * The error formatter for mocking is a bit different from the default one |
| (...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1482 } | 1495 } |
| 1483 } | 1496 } |
| 1484 } | 1497 } |
| 1485 | 1498 |
| 1486 /** Clear both logs and behavior. */ | 1499 /** Clear both logs and behavior. */ |
| 1487 void reset() { | 1500 void reset() { |
| 1488 resetBehavior(); | 1501 resetBehavior(); |
| 1489 clearLogs(); | 1502 clearLogs(); |
| 1490 } | 1503 } |
| 1491 } | 1504 } |
| OLD | NEW |