Я работаю с Firebase iOS SDK, и я изо всех сил пытаюсь выяснить, как полностью проверить некоторые вызовы метода Firebase с использованием Kiwi.Захват блоков из параметров метода в киви?
Я использую экземпляр Firebase, чтобы «смотреть» путь:
Firebase *streamsReference = [self.firebaseRef childByAppendingPath:@"streams"];
А потом с помощью этого streamsReference
наблюдать события:
[streamsReference observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
// do stuff in the block here
}];
Я хочу, чтобы проверить эффекты кода в блоке.
Это то, что я получил до сих пор:
it(@"should handle incoming connections as a hook for WebRTC", ^{
id mockFirebaseClass = [KWMock mockForClass:[Firebase class]];
// mock Firebase object to handle "/streams" path
id mockFirebaseStreamsReference = [KWMock mockForClass:[Firebase class]];
// return the streams reference object via the mock Firebase object
[mockFirebaseClass stub:@selector(childByAppendingPath:) andReturn:mockFirebaseStreamsReference];
// attempt to capture the block in the second param
KWCaptureSpy *spy = [mockFirebaseStreamsReference captureArgument:@selector(observeEventType:withBlock:) atIndex:1];
// inject the Firebase mock into the test class
classUnderTest.firebaseRef = mockFirebaseClass;
// capture the block from the spy
void(^blockToRun)() = spy.argument;
// call method that will invoke the Firebase observeEventType:withBlock method
[classUnderTest setupIncomingRemoteConnectionHandler];
// run the captured block
blockToRun(nil);
...
... expectations go here
...
});
Когда я запускаю тест, он терпит неудачу с ошибкой Argument requested has yet to be captured
- что говорит о том, что я пригвоздил вещи в неправильном порядке. Может ли кто-нибудь увидеть, где я здесь ошибся?