Skip to content

Commit e9e61d1

Browse files
committed
Merge branch 'dmaclach-disallowInvocationActionsOnRejects'
2 parents 15754a3 + e9612c1 commit e9e61d1

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Source/OCMock/OCMInvocationExpectation.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@ - (BOOL)isSatisfied
3737
return isSatisfied;
3838
}
3939

40-
- (void)handleInvocation:(NSInvocation *)anInvocation
40+
- (void)addInvocationAction:(id)anAction
4141
{
42-
[super handleInvocation:anInvocation];
42+
if(matchAndReject)
43+
{
44+
[NSException raise:NSInternalInconsistencyException format:@"%@: cannot add action to a reject stub; got %@",
45+
[self description], anAction];
46+
}
47+
[super addInvocationAction:anAction];
48+
}
4349

50+
- (void)handleInvocation:(NSInvocation *)anInvocation
51+
{
4452
if(matchAndReject)
4553
{
4654
isSatisfied = NO;
@@ -49,8 +57,11 @@ - (void)handleInvocation:(NSInvocation *)anInvocation
4957
}
5058
else
5159
{
60+
[super handleInvocation:anInvocation];
5261
isSatisfied = YES;
5362
}
5463
}
5564

65+
66+
5667
@end

Source/OCMockTests/OCMockObjectMacroTests.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ - (void)testSetsUpReject
291291
XCTAssertThrows([mock verify], @"Should have complained about rejected method being invoked");
292292
}
293293

294+
- (void)testThrowsWhenTryingToAddActionToReject
295+
{
296+
id mock = OCMClassMock([TestClassForMacroTesting class]);
297+
XCTAssertThrows(OCMReject([mock stringValue]).andReturn(@"Foo"));
298+
}
294299

295300
- (void)testShouldNotReportErrorWhenMethodWasInvoked
296301
{

Source/OCMockTests/OCMockObjectTests.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,12 @@ - (void)testThrowsWhenRejectedMethodIsCalledOnNiceMock
10821082
XCTAssertThrows([mock uppercaseString], @"Should have complained about rejected method being called.");
10831083
}
10841084

1085+
- (void)testThrowsWhenTryingToAddActionToReject
1086+
{
1087+
mock = [OCMockObject niceMockForClass:[NSString class]];
1088+
XCTAssertThrows([[[mock reject] andReturn:@"Foo"] stringValue]);
1089+
}
1090+
10851091
- (void)testUncalledRejectStubDoesNotCountAsExpectation
10861092
{
10871093
mock = [OCMockObject niceMockForClass:[NSString class]];

0 commit comments

Comments
 (0)