erikdoe / ocmock

Mock objects for Objective-C
http://ocmock.org
Apache License 2.0
2.16k stars 606 forks source link

Ignore rejection expectations during async verification #299

Closed nikolaykasyanov closed 8 years ago

nikolaykasyanov commented 8 years ago

Without that fix, a test using both async verification & rejections would wait for the whole given delay.

Performance test to confirm the problem & verify the fix included.

I also included baselines for the mentioned performance test.

I tried to write a regression test to verify that rejections do indeed work (i.e. throw) during async verification, like that:

- (void)testRejectsInvocationDuringAsynchronousVerification
{
   OCMockObject *localMock = [OCMockObject niceMockForClass:[TestClassWithProperty class]];

   [[localMock reject] title];
   [[localMock expect] setTitle:OCMOCK_ANY];

   dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
       [(id) localMock title];
   });

   @try {
       [localMock verifyWithDelay:1];
   } @catch(NSException *exception)  {
       // Expected
   }
}

But it seems that exceptions thrown inside the NSRunLoop call will crash the app immediately.

nikolaykasyanov commented 8 years ago

I'm really sorry for bothering you (I've read the contribution guidelines), but is there any chance to get this merged?

erikdoe commented 8 years ago

Haven’t had a chance to look into it yet. I spent the time I had for OCMock on preparing #302.

nikolaykasyanov commented 8 years ago

@erikdoe thanks for the update! #302 looks great.

erikdoe commented 8 years ago

Merged this now. (I did change the test so that it fails when the new logic does't work.) Regarding your other test mentioned in the comment: this is a common misunderstanding; reject has nothing to do with verify. Interestingly, the changes proposed in #302 are hopefully going to make things clearer.

nikolaykasyanov commented 8 years ago

@erikdoe thank you!