Can OCMock run a block parameter?

前端 未结 5 1878
予麋鹿
予麋鹿 2020-12-29 22:12

Assume a method signature such as the following:

- (void)theMethod:(void(^)(BOOL completed))completionBlock;

I would like to mock this meth

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 22:28

    This is Sven's answer updated for OCMock 3.

    OCMStub([myMock myMethodWithMyBlock:[OCMArg any]]).andDo(^(NSInvocation *invocation) {
        void (^passedBlock)(BOOL myFirstArgument, NSError *mySecondArgument);
        [invocation getArgument: &passedBlock atIndex: 2];
        passedBlock(YES, nil);
    });
    

提交回复
热议问题