我正在使用Firebase iOS SDK,我正在努力弄清楚如何使用 Kiwi 全面测试一些 Firebase 方法调用。
我正在使用 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
- 这表明我以错误的顺序进行操作。谁能看到我要去哪里错了?