Assume a method signature such as the following:
- (void)theMethod:(void(^)(BOOL completed))completionBlock;
I would like to mock this meth
Using andDo:
blocks is sometimes required but for most cases you can use [OCMArg invokeBlock]
or [OCMArg invokeBlockWithArgs:]
.
In your example you can do the following
If you don't care about the arguments:
// Call block with default arguments.
OCMStub([mock theMethod:[OCMArg invokeBlock]];
If you want to send specific arguments:
// Call block with YES.
OCMStub([mock theMethod:([OCMArg invokeBlockWithArgs:@YES, nil])];
Note the nil
termination since you can pass multiple arguments to this method.
In addition the entire expression must be wrapped in parentheses.
You can read more about it in the OCMock documentation.