为什么我不能通过考试?未调用任何 AFHTTPRequestOperation 块。似乎 expectFutureValue 不等待结果并立即返回。我尝试使用 XCode 6.1 和 Kiwi 2.3.1
谢谢!
context(@"AFNetworking", ^{
it(@"stubs a request with an error", ^{
NSError *error = [NSError errorWithDomain:@"com.luisobo.nocilla" code:123 userInfo:@{NSLocalizedDescriptionKey:@"Failing, failing... 1, 2, 3..."}];
stubRequest(@"POST", @"https://example.com/say-hello").
withHeaders(@{ @"X-MY-AWESOME-HEADER": @"sisisi", @"Content-Type": @"text/plain" }).
withBody(@"Adios!").
andFailWithError(error);
NSURL *url = [NSURL URLWithString:@"https://example.com/say-hello"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"text/plain" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"sisisi" forHTTPHeaderField:@"X-MY-AWESOME-HEADER"];
[request setHTTPBody:[@"Adios!" dataUsingEncoding:NSASCIIStringEncoding]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
__block BOOL succeed = NO;
__block BOOL failed = NO;
__block NSError *capturedError = nil;
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
succeed = YES;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
capturedError = error;
failed = YES;
}];
[operation start];
[[expectFutureValue(theValue(failed)) shouldEventually] beYes];
});
});