You can mute the call and pass it to the unit that checks it:
NSObject *expected = ...; id mock = [OCMockObject mockForClass:someClass] void (^theBlock)(NSInvocation *) = ^(NSInvocation *invocation) { NSObject *actual; [invocation getArgument:&actual atIndex:2]; expect(actual).toEqual(expected); }; [[[mock stub] andDo:theBlock] foo:[OCMArg any]]; [mock foo:expected];
There is also a callback version, but the control flow is becoming more complex, as you need a state variable visible both for your test and for the validation callback:
[[[mock stub] andCall:@selector(aMethod:) onObject:anObject] someMethod:someArgument]
source share