jonreid / OCMockito

Mockito for Objective-C: creation, verification and stubbing of mock objects
MIT License
991 stars 118 forks source link

MKTArgumentCaptor to HCArgumentCaptor migration #146

Closed saiday closed 7 years ago

saiday commented 7 years ago

I have used MKTArgumentCaptor as my argument captor, on updating OCMockito seems like now there's new HCArgumentCaptor instead of old MKTArgumentCaptor.

In some use cases, I used to capture completion block and execute it to solve async testing issue.

    MKTArgumentCaptor *successCaptor = [[MKTArgumentCaptor alloc] init];
    MKTArgumentCaptor *failCaptor = [[MKTArgumentCaptor alloc] init];
    [MKTVerify(self.mockConnectionService) fetchStationSong:anything() success:[successCaptor capture] failure:[failCaptor capture]];

when I trying to migrate to new HCArgumentCaptor:

    HCArgumentCaptor *successCaptor = [[HCArgumentCaptor alloc] init];
    HCArgumentCaptor *failCaptor = [[HCArgumentCaptor alloc] init];
    [MKTVerify(self.mockConnectionService) fetchStationSong:anything() success:successCaptor failure:failCaptor];

I got this error:

Sending 'HCArgumentCaptor *__strong' to parameter of incompatible type 'A' (aka 'void (^)(B *__strong)')

My question: is HCArgumentCaptor not supporting block capture? If so, what should I do it.

Thank you for your awesome project, and great articles.

jonreid commented 7 years ago

HCArgumentCaptor is good for capturing blocks. Try adding (id) casting to make the type anonymous, like

    [MKTVerify(self.mockConnectionService) fetchStationSong:anything()
                                                    success:(id)successCaptor
                                                    failure:(id)failCaptor];
saiday commented 7 years ago

@jonreid Got it, thank you for your help