所以我知道这是关于 OCMock 的......但我想我会把它放在那里,我用Kiwi成功地做到了这一点,它看起来像这样。
it(@"should refresh the client's temporary API key if it is stale before sending the request", ^{
ISLDataServiceAdd *addRequest = [ISLDataServiceAdd withRecord:@{ISLFieldContact_FirstName: @"Jason"} table:ISLTableContact];
[[clientMock shouldEventually] receive:@selector(apiKey) andReturn:VALID_API_KEY];
[[clientMock shouldEventually] receive:@selector(hasTemporaryAPIKey) andReturn:theValue(YES)];
[[clientMock shouldEventually] receive:@selector(isTemporaryAPIKeyStale) andReturn:theValue(YES)];
[[clientMock shouldEventually] receive:@selector(refreshTemporaryAPIKeyAndWait:)];
[addRequest sendRequestUsingClient:clientMock completion:nil failure:nil];
});
sendRequestUsingClient:completion:failure:
是一个异步调用,所以通过shouldEventually
与 Kiwi 一起使用,它知道在调用这些选择器之前需要等待一段时间(默认为 1 秒)。