jonreid / OCMockito

Mockito for Objective-C: creation, verification and stubbing of mock objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

given() willDo: for block stubbing only works if the method is non-void

cakl opened this issue · comments

I'd like to mock an object(that conforms a protocol) that has a void method with a block parameter:

@protocol DALRepoProtocol <NSObject>
-(void)getGameSessionsByName:(NSString*)name block:(void(^)(NSNumber* count, NSError* error))gameSessionResultBlock;
@end

If I'd try to stub this method and capture the block parameter the error occurs: "Argument type void is incomplete"

-(void)testCapturingBlock{

    id <DALRepoProtocol> protocol = mockProtocol(@protocol(DALRepoProtocol));

    [[given([protocol getGameSessionsByName:anything() block:anything()]) willDo:^id (NSInvocation *invocation){
        NSArray *args = [invocation mkt_arguments];
        //I'd like to get the block parameter here and call the block parameter with the needed values
    }];


}

I rarely use a method with block parameter that is non-void because often these methods are called asynchronous. So willDo is absolutely useless here.

Sorry, I didn't found this.