Add test coverage around operation cancellation setting the error and invoking the failure block. refs #941

This commit is contained in:
Blake Watters 2013-05-13 09:21:36 -04:00
parent 5c81d90a4c
commit 6e57c377f1

View file

@ -39,4 +39,30 @@
expect(blockError).willNot.beNil();
}
- (void)testThatCancellationOfRequestOperationSetsError
{
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/delay/5" relativeToURL:AFNetworkingTestsBaseURL()]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation start];
expect([operation isExecuting]).will.beTruthy();
[operation cancel];
expect(operation.error).willNot.beNil();
expect(operation.error.code).to.equal(NSURLErrorCancelled);
}
- (void)testThatCancellationOfRequestOperationInvokesFailureCompletionBlock
{
__block NSError *blockError = nil;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/delay/5" relativeToURL:AFNetworkingTestsBaseURL()]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:nil failure:^(AFHTTPRequestOperation *operation, NSError *error) {
blockError = error;
}];
[operation start];
expect([operation isExecuting]).will.beTruthy();
[operation cancel];
expect(blockError).willNot.beNil();
expect(blockError.code).to.equal(NSURLErrorCancelled);
}
@end