2014-12-02 64 views
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錯誤而失敗 - 這表明我釘的事情了順序錯誤。任何人都可以看到我要去哪裏嗎?

回答

0

您正試圖在觀察方法被調用之前過早地捕獲參數。嘗試在呼叫setupIncomingRemoteConnectionHandler後移動void(^blockToRun)() = spy.argument;行。如果這也不起作用,這意味着您需要運行一些額外的呼叫到您的測試類,以觸發observeEventType:withBlock:呼叫。

相關問題