ccnyou ccnyou - 16 days ago 6
iOS Question

OCMockito how to capture block and match any other primitive arguments?

method signature:

- (void)updateFeaturesButtons:(NSInteger)gameId
category:(FeatruesCategory)category
parentId:(NSInteger)parentId
success:(void (^)(NSDictionary* featuresJson))success
failure:(void (^)(NSError* error))failure


I try to capture the success block argument and ignore other arguments like that:

HCArgumentCaptor* captor = [[HCArgumentCaptor alloc] init];
[verify(mockManager) updateFeaturesButtons:0 category:0 parentId:0 success:(id)captor failure:anything()];


I just want to call success block with my json:

SuccessBlock block = captor.value;
block(json);


But what I get is only
argument(s) are different!
error.
What can I do for other arguments?

Answer

In the OCMockito documentation, see How do you specify matchers for non-object arguments?

So you'll need to specify

[[[[verify(mockManager)
    withMatcher:anything() forArgument:0]
    withMatcher:anything() forArgument:1]
    withMatcher:anything() forArgument:2]
    updateFeaturesButtons:0 category:0 parentId:0 success:(id)captor failure:anything()];
Comments