我需要以下帮助:我正在为具有以下结构的客户端API编写一些BDD测试:
@protocol MyAPIClientDelegate <NSObject>
-(void)myCallbackMethod:(id)response;
@end
// BEGIN: MyAPIClientSpec.h
SPEC_BEGIN(MyAPIClientSpec)
describe(@"MyAPIClientAPI ", ^{
__block MyAPI *api = nil;
__block id delegateMock = nil;
beforeEach(^{
delegateMock = [KWMock mockForProtocol:@protocol(MyAPIClientDelegate)];
api = [MyAPI APIClientWithDelegate:delegateMock];
});
afterEach(^{
delegateMock = nil;
api = nil;
});
it(@"should return a JSON { result: 'ok', token: <SOME_TOKEN> }", ^{
[[api should] receive:@selector(myMethodCall:)];
[[[delegateMock shouldEventually] receive] myCallbackMethod:any()];
[api myMethodCall];
});
});
SPEC_END
正如您在上面的代码中所看到的,我正在使用any()来检查是否至少有一个参数发送给了委托。
是否有定义函数(或objective-c块)来检查参数?
谢谢!
答案 0 :(得分:2)
尝试使用capture spy:
it(@"should return a JSON { result: 'ok', token: <SOME_TOKEN> }", ^{
[[api should] receive:@selector(myMethodCall:)];
KWCaptureSpy *spy = [delegateMock captureArgument:@selector(myCallbackMethod:) atIndex:0];
[api myMethodCall];
[[spy.argument should] equal:/* ... */];
});