'[OCMock]A question about the andDo function

1.code show as below:

[[OCMExpect([[self.mockDelegate ignoringNonObjectArgs] adLoaded:OCMOCK_ANY statusChanged:statusStarted]) ignoringNonObjectArgs] andDo:^(NSInvocation *invocation) {
        ...
        ...
    }];

I broke the point and found that andDo is only executed works once(when status==statusStarted).The function is not triggered when status==statusEnded. But when I copied the above code and found that the andDo function was triggered when status==statusEnded. code show as below:

[[OCMExpect([[self.mockDelegate ignoringNonObjectArgs] adLoaded:OCMOCK_ANY statusChanged:statusStarted]) ignoringNonObjectArgs] andDo:^(NSInvocation *invocation) {
        ...
        ...
    }];
[[OCMExpect([[self.mockDelegate ignoringNonObjectArgs] adLoaded:OCMOCK_ANY statusChanged:statusStarted]) ignoringNonObjectArgs] andDo:^(NSInvocation *invocation) {
        ...
        ...
    }];

what's the reason?

2.an additional question

After experimenting I found that OCMVerifyAllWithDelay(self.adMockDelegate, 10) is not equivalent to:

 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{    
 OCMVerifyAll(self.adMockDelegate);
    });

OCMVerifyAllWithDelay blocks the thread for 10 seconds,instead of extending the verification time of the mock by 10 seconds.why?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source