ios - Capturing blocks from method parameters in Kiwi? -
i'm working firebase ios sdk, , i'm struggling figure out how fully-test of firebase method calls using kiwi.
i'm using instance of firebase "watch" path:
firebase *streamsreference = [self.firebaseref childbyappendingpath:@"streams"];
and using streamsreference observe events:
[streamsreference observeeventtype:feventtypechildadded withblock:^(fdatasnapshot *snapshot) { // stuff in block here }]; i want test effects of code in block.
this i've got far:
it(@"should handle incoming connections hook webrtc", ^{ id mockfirebaseclass = [kwmock mockforclass:[firebase class]]; // mock firebase object handle "/streams" path id mockfirebasestreamsreference = [kwmock mockforclass:[firebase class]]; // return streams reference object via mock firebase object [mockfirebaseclass stub:@selector(childbyappendingpath:) andreturn:mockfirebasestreamsreference]; // attempt capture block in second param kwcapturespy *spy = [mockfirebasestreamsreference captureargument:@selector(observeeventtype:withblock:) atindex:1]; // inject firebase mock test class classundertest.firebaseref = mockfirebaseclass; // capture block spy void(^blocktorun)() = spy.argument; // call method invoke firebase observeeventtype:withblock method [classundertest setupincomingremoteconnectionhandler]; // run captured block blocktorun(nil); ... ... expectations go here ... }); when run test, it's failing argument requested has yet captured error - suggests i'm nailing things in wrong order. can see i'm going wrong here?
you trying capture argument early, before watched method had been called. try move void(^blocktorun)() = spy.argument; line after call setupincomingremoteconnectionhandler. if doesn't work either, means need make run calls test class in order trigger observeeventtype:withblock: call.
Comments
Post a Comment