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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -