0
我正在使用Firebase iOS SDK,我正在努力弄清楚如何使用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
錯誤而失敗 - 這表明我釘的事情了順序錯誤。任何人都可以看到我要去哪裏嗎?