Permalink
Browse files

Add tests for stubAndReturn with different return values.

  • Loading branch information...
1 parent eff7f47 commit aedbc7d5e3fa7c9e84cc6673592ab3dda94ebff7 @Bensk1 committed May 2, 2012
Showing with 21 additions and 0 deletions.
  1. +11 −0 Tests/KWMockTest.m
  2. +10 −0 Tests/KWRealObjectStubTest.m
View
@@ -106,6 +106,17 @@ - (void)testItShouldStubWithAReturnValueAndMessage {
STAssertEquals(ratio, 42.0f, @"expected mock to have message stubbed");
}
+- (void)testItShouldStubWithDifferentReturnValuesAndMessage {
+ id mock = [Cruiser mock];
+ STAssertNoThrow([[mock stubAndReturn:[KWValue valueWithFloat:42.0f] times:[KWValue valueWithInt:2] afterThatReturn:[KWValue valueWithFloat:43.0f]] energyLevelInWarpCore:3], @"expected mock to stub message");
+ float firstRatio = [mock energyLevelInWarpCore:3];
+ STAssertEquals(firstRatio, 42.0f, @"expected mock to have message stubbed");
+ float secondRatio = [mock energyLevelInWarpCore:3];
+ STAssertEquals(secondRatio, 42.0f, @"expected mock to have message stubbed");
+ float thirdRatio = [mock energyLevelInWarpCore:3];
+ STAssertEquals(thirdRatio, 43.0f, @"expected mock to have message stubbed and changed return value");
+}
+
- (void)testItShouldClearStubbedMethods {
id mock = [Cruiser mock];
[mock stub:@selector(callsign) andReturn:@"Executor"];
@@ -91,6 +91,16 @@ - (void)testItShouldStubTheNextMessage {
STAssertEqualObjects([cruiser callsign], callsign, @"expected method to be stubbed");
}
+- (void)testItShouldStubTheNextMessagesAndReturnDifferentValues {
+ NSString *callsign = @"Galactica";
+ NSString *secondCallsign = @"Andromeda";
+ Cruiser *cruiser = [Cruiser cruiserWithCallsign:@"Avenger"];
+ [[cruiser stubAndReturn: callsign times:[KWValue valueWithInt:2] afterThatReturn:secondCallsign] callsign];
+ STAssertEqualObjects([cruiser callsign], callsign, @"expected method to be stubbed");
+ STAssertEqualObjects([cruiser callsign], callsign, @"expected method to be stubbed");
+ STAssertEqualObjects([cruiser callsign], secondCallsign, @"expected method to be stubbed and change return value");
+}
+
- (void)testItShouldPreserveClassResultWhenInstanceMethodStubbed {
id subject = [Cruiser cruiser];
Class originalClass = [subject class];

0 comments on commit aedbc7d

Please sign in to comment.