Added support for spy.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ca63bc0..ce1deb1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.10.0
+
+* Added support for spy.
+
## 0.9.0
* Migrate from the unittest package to use the new test package.
diff --git a/lib/mockito.dart b/lib/mockito.dart
index c255a4e..2c69a20 100644
--- a/lib/mockito.dart
+++ b/lib/mockito.dart
@@ -59,6 +59,13 @@
mock._realCalls.clear();
}
+dynamic spy(dynamic mock, dynamic spiedObject) {
+ var mirror = reflect(spiedObject);
+ mock._defaultResponse = () => new CannedResponse(
+ null, (Invocation realInvocation) => mirror.delegate(realInvocation));
+ return mock;
+}
+
class PostExpectation {
thenReturn(expected) {
return _completeWhen((_) => expected);
diff --git a/pubspec.yaml b/pubspec.yaml
index f576845..3fbf6b1 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: mockito
-version: 0.9.0
+version: 0.10.0
author: Dmitriy Fibulwinter <fibulwinter@gmail.com>
description: A mock framework inspired by Mockito.
homepage: https://github.com/fibulwinter/dart-mockito
diff --git a/test/mockito_test.dart b/test/mockito_test.dart
index 4d61b62..30b9b72 100644
--- a/test/mockito_test.dart
+++ b/test/mockito_test.dart
@@ -48,6 +48,25 @@
mock = new MockedClass();
});
+ group("spy", () {
+ setUp(() {
+ mock = spy(new MockedClass(), new RealClass());
+ });
+
+ test("should delegate to real object by default", () {
+ expect(mock.methodWithoutArgs(), 'Real');
+ });
+ test("should record interactions delegated to real object", () {
+ mock.methodWithoutArgs();
+ verify(mock.methodWithoutArgs());
+ });
+ test("should behave as mock when expectation are set", () {
+ when(mock.methodWithoutArgs()).thenReturn('Spied');
+ expect(mock.methodWithoutArgs(), 'Spied');
+ });
+ });
+
+
group("mixin support", () {
test("should work", () {
var foo = new MockFoo();