From 6e57c377f17705cc4b09165f04a808c5acbc233a Mon Sep 17 00:00:00 2001 From: Blake Watters Date: Mon, 13 May 2013 09:21:36 -0400 Subject: [PATCH] Add test coverage around operation cancellation setting the error and invoking the failure block. refs #941 --- Tests/AFHTTPRequestOperationTests.m | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Tests/AFHTTPRequestOperationTests.m b/Tests/AFHTTPRequestOperationTests.m index afdeb28..ff5a80c 100644 --- a/Tests/AFHTTPRequestOperationTests.m +++ b/Tests/AFHTTPRequestOperationTests.m @@ -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