How can I test asynchronous delegate methods using Expecta/OCMockito?

361 Views Asked by At

I'm currently using Kiwi to write tests, but I'm interested in trying out Specta/Expecta/OCMockito (or another mocking library, if necessary).

One thing I use Kiwi for is testing that delegate methods are called after some asynchronous work. For example, this Kiwi spec stubs an HTTP request response (which is performed in a background queue), and tests that eventually the delegate is informed of a response from the request:

it(@"Sends a callback", ^{
    [OHHTTPStubs stubRequestContainingString:@"start" withJSON:@{}];

    id starterMock = [KWMock mockForProtocol:@protocol(HZMediationStarting)];
    HZMediationStarter *starter = [[HZMediationStarter alloc] initWithStartingDelegate:starterMock];

    [starter start];
    [[starterMock shouldEventually] receive:@selector(startWithDictionary:fromCache:)];
});

Is there a way to achieve this with Expecta/OCMockito (or potentially another mocking library?). I can see that Expecta supports asynchronous expectations, but I'm not sure how to combine that with a mocking library like OCMockito.

0

There are 0 best solutions below