ios - Can OCMock run a block parameter? -
assume method signature such following:
- (void)themethod:(void(^)(bool completed))completionblock;
i mock method signature ensure method called, , call completion block. see other posts this one can mock method call , accept block, not run block. know there anddo method might able use, can't figure out how pass block in , run it.
any ideas?
thanks.
you can use [[mock stub] anddo:]
pass block gets called when mocked method called:
void (^proxyblock)(nsinvocation *) = ^(nsinvocation *invocation) { void (^passedblock)( bool ); [invocation getargument: &passedblock atindex: 2]; }; [[[mock stub] anddo: proxyblock] themethod:[ocmarg any]];
the block gets nsinvocation
instance can query used arguments. note first argument @ index 2 since have self , _cmd @ indices 0 , 1.
Comments
Post a Comment