我正在尝试运行猕猴桃测试,它不评估内部块上的猕猴桃语句。 但它将评估块外的任何测试语句。 我该怎么办?:
- (void) jsonTest:(void (^)(NSDictionary *model))jsonData{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://api.somesite.com" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
if(jsonData){
jsonData((NSDictionary *)responseObject);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
jsonData(nil);
}];
}
describe(@"Networking", ^{
it(@"Get Sample JSON", ^{
[[NetworkingUtil alloc] jsonTest:^(NSDictionary *model){
NSString * result = [model objectForKey:@"Host"];
NSLog(@"result :: %@", result);
[[result should] equal: @"host.value.name"];
}];
//kiwi evaluates this test statement though...
[[theValue(41) should] equal:theValue(42)];
}];
你需要使用 KWCaptureSpy。
NetworkingUtil *jsonT = [NetworkingUtil alloc];
// We tell the spy what argument to capture.
KWCaptureSpy *spy = [jsonT captureArgument:@selector(jsonTest:) atIndex:0];
[jsonT jsonTest:^(NSDictionary *model){
NSString * result = [model objectForKey:@"Host"];
NSLog(@"result :: %@", result);
[[result should] equal: @"host.value.name"];
}];
void (^myTestBlock)(NSDictionary *model) = spy.argument;
myTestBlock(dictionary);
您必须创建一个将通过测试的字典。对于任何块都是一样的,即使是 jsonTest: 方法中的块。
当谈到猕猴桃和在块中测试块时,它变得有点疯狂,但概念是相同的。捕获具有完成块的方法,捕获要测试的块的参数,并向其传递所需的对象。