As others have said, blocks are compared by comparing their addresses. Two different blocks - even though they do the exact same thing - are not equal. You can still make your test more specific by actually invoking the success and failure block, and check if they behave as expected.
As far as I understand you want to test that
- the method calls another method with two blocks, that when invoked, invoke the original block with
- some response object as the first and
nil
as the second argument in case of success nil
as the first, anNSError*
as the second argument in case of failure
Here is the test for the success case:
id responseMock = @"responseObject";
__block BOOL blockCalled = NO;
void (^block)(id, NSError *) = ^(id responseObject, NSError *error) {
XCTAssertNil(error, @"");
XCTAssertEqualObjects(responseObject, responseMock, @"");
blockCalled = YES;
};
[[[sessionManagerPartialMock expect] andDo:^(NSInvocation *invocation) {
void (^successBlock)(NSURLSessionDataTask *, id);
[invocation getArgument:&successBlock atIndex:4];
successBlock((id)@"task", responseMock);
}] GET:URLstring parameters:parameters success:[OCMArg isNotNil] failure:[OCMArg isNotNil]];
[sessionManagerPartialMock GET:URLstring parameters:parameters block:block];
[sessionManagerPartialMock verify];
XCTAssert(blockCalled, @"");