Skip to content

Commit 5819bd4

Browse files
committed
Fix for erikdoe#164.
1 parent 2d77d72 commit 5819bd4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Source/OCMock/OCMIndirectReturnValueProvider.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#import "NSMethodSignature+OCMAdditions.h"
1818
#import "OCMIndirectReturnValueProvider.h"
19+
#import "NSInvocation+OCMAdditions.h"
1920

2021

2122
@implementation OCMIndirectReturnValueProvider
@@ -36,9 +37,15 @@ - (void)dealloc
3637

3738
- (void)handleInvocation:(NSInvocation *)anInvocation
3839
{
39-
[anInvocation setTarget:provider];
40+
id originalTarget = [anInvocation target];
41+
SEL originalSelector = [anInvocation selector];
42+
43+
[anInvocation setTarget:provider];
4044
[anInvocation setSelector:selector];
4145
[anInvocation invoke];
46+
47+
[anInvocation setTarget:originalTarget];
48+
[anInvocation setSelector:originalSelector];
4249
}
4350

4451
@end

Source/OCMockTests/OCMockObjectPartialMocksTests.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,18 @@ - (void)testForwardsToRealObjectWhenSetUpAndCalledOnRealObject
397397
[mock verify];
398398
}
399399

400+
- (void)testReturnValueFromRealObjectShouldBeReturnedEvenWithPrecedingAndCall
401+
{
402+
TestClassThatCallsSelf *object = [[TestClassThatCallsSelf alloc] init];
403+
OCMockObject *mock = OCMPartialMock(object);
404+
[[[[mock stub] andCall:@selector(firstReturnValueMethod) onObject:self] andForwardToRealObject] method2];
405+
XCTAssertEqualObjects([object method2], @"Foo", @"Should have returned value from real object.");
406+
}
407+
408+
- (NSString *)firstReturnValueMethod
409+
{
410+
return @"Bar";
411+
}
400412

401413
#pragma mark Tests for method swizzling with partial mocks
402414

0 commit comments

Comments
 (0)