Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions Source/OCMock/OCMStubRecorder.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,44 +51,46 @@ - (OCMInvocationStub *)stub

- (id)andReturn:(id)anObject
{
[[self stub] addInvocationAction:[[[OCMObjectReturnValueProvider alloc] initWithValue:anObject] autorelease]];
return self;
Class returnValueProviderClass;
if (anObject == mockObject)
{
returnValueProviderClass = [OCMNonRetainingObjectReturnValueProvider class];
} else
{
returnValueProviderClass = [OCMObjectReturnValueProvider class];
}
[[self stub] addInvocationAction:[[[returnValueProviderClass alloc] initWithValue:anObject] autorelease]];
return self;
}

- (id)andReturnValue:(NSValue *)aValue
{
[[self stub] addInvocationAction:[[[OCMBoxedReturnValueProvider alloc] initWithValue:aValue] autorelease]];
return self;
}

- (id)andReturnMockObject
{
[[self stub] addInvocationAction:[[[OCMNonRetainingObjectReturnValueProvider alloc] initWithValue:mockObject] autorelease]];
return self;
return self;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to merge this PR as is. In future, though, please don't make whitespace changes. I know that inconsistencies have crept in over the years, but cleaning them up like this adds noise to the real change. Thanks.

}

- (id)andThrow:(NSException *)anException
{
[[self stub] addInvocationAction:[[[OCMExceptionReturnValueProvider alloc] initWithValue:anException] autorelease]];
return self;
return self;
}

- (id)andPost:(NSNotification *)aNotification
{
[[self stub] addInvocationAction:[[[OCMNotificationPoster alloc] initWithNotification:aNotification] autorelease]];
return self;
return self;
}

- (id)andCall:(SEL)selector onObject:(id)anObject
{
[[self stub] addInvocationAction:[[[OCMIndirectReturnValueProvider alloc] initWithProvider:anObject andSelector:selector] autorelease]];
return self;
return self;
}

- (id)andDo:(void (^)(NSInvocation *))aBlock
{
[[self stub] addInvocationAction:[[[OCMBlockCaller alloc] initWithCallBlock:aBlock] autorelease]];
return self;
return self;
}

- (id)andForwardToRealObject
Expand Down Expand Up @@ -122,7 +124,7 @@ @implementation OCMStubRecorder (Properties)
{
id objValue = nil;
[aValue getValue:&objValue];
return (objValue == mockObject) ? [self andReturnMockObject] : [self andReturn:objValue];
return [self andReturn:objValue];
}
else
{
Expand Down
14 changes: 13 additions & 1 deletion Source/OCMockTests/OCMockObjectTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ - (void)setUp
mock = [OCMockObject mockForClass:[NSString class]];
}


#pragma mark accepting stubbed methods / rejecting methods not stubbed

- (void)testAcceptsStubbedMethod
Expand Down Expand Up @@ -574,6 +573,18 @@ - (void)testReturnsStubbedValueForProperty
}

- (void)testReturningMockFromMethodItStubsDoesntCreateRetainCycle
{
@autoreleasepool {
id mockWithShortLifetime = OCMClassMock([TestClassWithClassMethod class]);
[[[mockWithShortLifetime stub] andReturn:@"bar"] stringValue];
[[[mockWithShortLifetime stub] andReturn:mockWithShortLifetime] shared];
}
id singleton = [TestClassWithClassMethod shared];

XCTAssertEqualObjects(@"foo", [singleton stringValue], @"Should return value from real implementation (because shared is not stubbed anymore).");
}

- (void)testReturningMockFromMethodItStubsDoesntCreateRetainCycleUsingMacros
{
@autoreleasepool {
id mockWithShortLifetime = OCMClassMock([TestClassWithClassMethod class]);
Expand All @@ -586,6 +597,7 @@ - (void)testReturningMockFromMethodItStubsDoesntCreateRetainCycle
}



#pragma mark beyond stubbing: raising exceptions, posting notifications, etc.

- (void)testRaisesExceptionWhenAskedTo
Expand Down