I have 2 methods in a class where one of them simply calls the other one with specific parameters. The methods are as below:
-(void)loadAllFollowersForUser:(NSUInteger)userID withResponseHandler:(_Nullable CompletionHandler)handler {
[self loadFollowersForUser:userID
fromOffSet:0
toLimit:100000
withResponseHandler:handler];
}
-(void)loadFollowersForUser:(NSUInteger)userID fromOffSet:(NSInteger)offset toLimit:(NSInteger)limit withResponseHandler:(_Nullable CompletionHandler)handler {
NSLog(@"Actual loadFollowersForUser method got called!");
}
I am trying my hand on TDD and have been using OCMock. I have the following test that simply tests that loadAllFollowers is internally calling the other method
- (void)testLoadAllFollowersCallsLoadFollowers {
id partialMockSUT = OCMPartialMock(self.sut);
OCMExpect([partialMockSUT loadFollowersForUser:[OCMArg any]
fromOffSet:[OCMArg any]
toLimit:[OCMArg any]
withResponseHandler:[OCMArg any]]);
[partialMockSUT loadAllFollowersForUser:123
withResponseHandler:^(BOOL success, id response, NSError *error) {
}];
OCMVerifyAll(partialMockParser);
}
I am using a partial mock because I only want to stub the loadFollowersForUser method and call the actual implementation of loadAllFollowers method. This does almost exactly this but my test always fails to meet the expectation and I see the NSLog in the console.
Things I have tried:
- I have tried adding other temporary methods to verify the behavior of parital mocks and they perform exactly as expected
- This question suggests what I am trying to do should be very much possible
- I have tried adding OCMStub for the method after the OCMExpect inline with OCMock documentation. See 10.2 on this page
I am not sure if its a problem with block being passed in or that the method return type is void and I have no action for the expectation.