Skip to content
This repository
Browse code

Add tests for stubAndReturn with different return values.

  • Loading branch information...
commit aedbc7d5e3fa7c9e84cc6673592ab3dda94ebff7 1 parent eff7f47
authored May 02, 2012
11  Tests/KWMockTest.m
@@ -106,6 +106,17 @@ - (void)testItShouldStubWithAReturnValueAndMessage {
106 106
     STAssertEquals(ratio, 42.0f, @"expected mock to have message stubbed");
107 107
 }
108 108
 
  109
+- (void)testItShouldStubWithDifferentReturnValuesAndMessage {
  110
+    id mock = [Cruiser mock];
  111
+    STAssertNoThrow([[mock stubAndReturn:[KWValue valueWithFloat:42.0f] times:[KWValue valueWithInt:2] afterThatReturn:[KWValue valueWithFloat:43.0f]] energyLevelInWarpCore:3], @"expected mock to stub message");
  112
+    float firstRatio = [mock energyLevelInWarpCore:3];
  113
+    STAssertEquals(firstRatio, 42.0f, @"expected mock to have message stubbed");
  114
+    float secondRatio = [mock energyLevelInWarpCore:3];
  115
+    STAssertEquals(secondRatio, 42.0f, @"expected mock to have message stubbed");
  116
+    float thirdRatio = [mock energyLevelInWarpCore:3];
  117
+    STAssertEquals(thirdRatio, 43.0f, @"expected mock to have message stubbed and changed return value");
  118
+}
  119
+
109 120
 - (void)testItShouldClearStubbedMethods {
110 121
     id mock = [Cruiser mock];
111 122
     [mock stub:@selector(callsign) andReturn:@"Executor"];
10  Tests/KWRealObjectStubTest.m
@@ -91,6 +91,16 @@ - (void)testItShouldStubTheNextMessage {
91 91
     STAssertEqualObjects([cruiser callsign], callsign, @"expected method to be stubbed");
92 92
 }
93 93
 
  94
+- (void)testItShouldStubTheNextMessagesAndReturnDifferentValues {
  95
+    NSString *callsign = @"Galactica";
  96
+    NSString *secondCallsign = @"Andromeda";
  97
+    Cruiser *cruiser = [Cruiser cruiserWithCallsign:@"Avenger"];
  98
+    [[cruiser stubAndReturn: callsign times:[KWValue valueWithInt:2] afterThatReturn:secondCallsign] callsign];
  99
+    STAssertEqualObjects([cruiser callsign], callsign, @"expected method to be stubbed");
  100
+    STAssertEqualObjects([cruiser callsign], callsign, @"expected method to be stubbed");
  101
+    STAssertEqualObjects([cruiser callsign], secondCallsign, @"expected method to be stubbed and change return value");
  102
+}
  103
+
94 104
 - (void)testItShouldPreserveClassResultWhenInstanceMethodStubbed {
95 105
     id subject = [Cruiser cruiser];
96 106
     Class originalClass = [subject class];

0 notes on commit aedbc7d

Please sign in to comment.
Something went wrong with that request. Please try again.