0

私は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エラーが発生して失敗します。これは、間違った順序で作業していることを示唆しています。ここで私が間違っているところを誰かが見ることができますか?

4

1 に答える 1