Skip to content

Commit

Permalink
fix failing test_AFHTTPRequestOperation_multiple_choices using setTas…
Browse files Browse the repository at this point in the history
…kWillPerformHTTPRedirectionBlock method from AFNetworking 3.0
  • Loading branch information
tiagomartinho committed Oct 29, 2015
1 parent 4235b01 commit 98c7ae6
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions OHHTTPStubs/UnitTests/Test Suites/AFNetworkingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,28 @@ -(void)test_AFHTTPRequestOperation_multiple_choices

XCTestExpectation* expectation = [self expectationWithDescription:@"AFHTTPRequestOperation request finished"];

// NSURLRequest* req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.iana.org/domains/example/"]];
// AFHTTPRequestOperation* op = [[AFHTTPRequestOperation alloc] initWithRequest:req];
// AFHTTPResponseSerializer* serializer = [AFHTTPResponseSerializer serializer];
// [serializer setAcceptableStatusCodes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 101)]];
// [op setResponseSerializer:serializer];
//
NSURL *URL = [NSURL URLWithString:@"http://www.iana.org/domains/example/"];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
AFHTTPResponseSerializer* serializer = [AFHTTPResponseSerializer serializer];
[serializer setAcceptableStatusCodes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 101)]];
[manager setResponseSerializer:serializer];
__block __strong id response = nil;
// [op setRedirectResponseBlock:^NSURLRequest *(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse) {
// if (redirectResponse == nil) {
// return request;
// }
// XCTFail(@"Unexpected redirect");
// return nil;
// }];
//
// [op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// response = responseObject; // keep strong reference
// [expectation fulfill];
// } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// XCTFail(@"Unexpected network failure");
// [expectation fulfill];
// }];
// [op start];
[manager setTaskWillPerformHTTPRedirectionBlock:^NSURLRequest * (NSURLSession * session, NSURLSessionTask * task, NSURLResponse * response, NSURLRequest * request) {
if (response == nil) {
return request;
}
XCTFail(@"Unexpected redirect");
return nil;
}];

[manager GET:URL.absoluteString parameters:nil success:^(NSURLSessionTask *task, id responseObject) {
response = responseObject; // keep strong reference
[expectation fulfill];
} failure:^(NSURLSessionTask *operation, NSError *error) {
XCTFail(@"Unexpected network failure");
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:kRequestTime+kResponseTime+kResponseTimeTolerence handler:nil];

Expand Down

0 comments on commit 98c7ae6

Please sign in to comment.