Add test coverage around operation cancellation setting the error and invoking the failure block. refs #941
This commit is contained in:
parent
5c81d90a4c
commit
6e57c377f1
1 changed files with 26 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue