嘲笑期望和Grand Central Dispatch

时间:2013-05-19 14:05:53

标签: ios grand-central-dispatch kiwi

我有一个简单的经理对象,并且在猕猴桃中使用模拟,我想在我调用[aPOIManager fetchNear:location]时检查它是否在其下载程序上调用downloadPOIsNear:completionBlock:

一切正常,直到我决定在大型中央调度中将调用发送到下载器。

调用是异步的,测试现在失败了。 Kiwi具有异步检查某些值的功能,但不检查异步调用。

以下是我测试的一部分:

it(@"should call the proximity downloader", ^{

      CLLocation *location = [[CLLocation alloc] initWithLatitude:1.0f longitude:1.0f];

      id<RMProximityDownloader> mockDownloader =
      [KWMock mockForProtocol:@protocol(RMProximityDownloader)];

      [[(NSObject*)mockDownloader should] receive:@selector(downloadPOIsNear:completionBlock:)];

      RMPOIManager *aPOIManager = [[RMPOIManager alloc] initWithDownloader:mockDownloader];

      [aPOIManager fetchNear:location];
    });

1 个答案:

答案 0 :(得分:1)

试试这个:

[[(NSObject*)mockDownloader shouldEventually] receive:@selector(downloadPOIsNear:completionBlock:)];

如果需要,您还可以使用shouldEventuallyBeforeTimingOutAfter(seconds)