Assume a method signature such as the following:
- (void)theMethod:(void(^)(BOOL completed))completionBlock;
I would like to mock this meth
EDIT 2: Use https://stackoverflow.com/a/32945785/637641 instead.
Using andDo:
is perfectly fine, but personally I prefer [OCMArg checkWithBlock:]
.
[[mock expect] theMethod:[OCMArg checkWithBlock:^BOOL(id param)
{
void (^passedBlock)( BOOL ) = param;
// Normally I set some expectations here and then call the block.
return YES;
}]];
// Code to test
[mock verify];
You can use also [mock stub] but I prefer to verify that theMethod is called.
EDIT 1
OCMock 3 version:
OCMExpect([mock theMethod:[OCMArg checkWithBlock:^BOOL(void (^passedBlock)(BOOL))
{
// call the block...
return YES;
}]]);
// Code to test
OCMVerify(mock);