How can I use OCMock to verify that a method is never called?

后端 未结 6 2159
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-06 22:32

At my day job I\'ve been spoiled with Mockito\'s never() verification, which can confirm that a mock method is never called.

Is there some way to accomplish the same thi

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-06 23:02

    You could also try something like this, a la JavaScript:

    - (void)aMethod {
       __block BOOL b = NO;
    
       id mock = [OCMockObject mockForClass:[UIView class]];
       [[[mock stub] andDo:^(NSInvocation *i) { b = YES; }] resignFirstResponder];
       [mock resignFirstResponder];
    
       NSLog(@"And b is: %i", b); // This reads "And b is: 1" on the console
    }
    

    I'm not sure if there are any leaks associated with this code. I got the idea from reading this page: http://thirdcog.eu/pwcblocks/

提交回复
热议问题