Skip to content

Commit

Permalink
Merge branch 'update-travis-xcode-9'
Browse files Browse the repository at this point in the history
  • Loading branch information
AliSoftware committed Nov 19, 2017
2 parents 906f3f7 + 6bf1982 commit c088cfa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
21 changes: 14 additions & 7 deletions OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m
Expand Up @@ -296,20 +296,20 @@ - (void)test_NSURLSessionDefaultConfig_notFollowingRedirects
**/
- (void)test_NSURLSessionDefaultConfig_MethodAndDataRetentionOnRedirect
{
NSURLSessionTestDelegate* delegate = [NSURLSessionTestDelegate delegateFollowingRedirects:YES fulfillOnCompletion:nil];

if ([NSURLSessionConfiguration class] && [NSURLSession class])
{
NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:delegate delegateQueue:nil];

NSDictionary* json = @{ @"query": @"Hello World" };
NSArray<NSString*>* allMethods = @[@"GET", @"HEAD", @"POST", @"PATCH", @"PUT"];

/** 301, 302, 307, 308: GET, HEAD, POST, PATCH, PUT should all maintain HTTP method and body unchanged **/
for (NSNumber* redirectStatusCode in @[@301, @302, @307, @308]) {
int statusCode = redirectStatusCode.intValue;
for (NSString* method in allMethods) {

NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSessionTestDelegate* delegate = [NSURLSessionTestDelegate delegateFollowingRedirects:YES fulfillOnCompletion:nil];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:delegate delegateQueue:nil];

[self _test_redirect_NSURLSession:session httpMethod:method jsonBody:json delays:0.0 redirectStatusCode:statusCode
completion:^(NSString *redirectedRequestMethod, id redirectedRequestJSONBody, NSHTTPURLResponse *redirectHTTPResponse, id finalJSONResponse, NSError *errorResponse)
{
Expand All @@ -323,11 +323,18 @@ - (void)test_NSURLSessionDefaultConfig_MethodAndDataRetentionOnRedirect
@"Unexpected JSON response received after %d redirect", statusCode);
XCTAssertNil(errorResponse, @"Unexpected error during %d redirect", statusCode);
}];

[session finishTasksAndInvalidate];
}
}

/** 303: GET, HEAD, POST, PATCH, PUT should use a GET HTTP method after redirection and not forward the body **/
for (NSString* method in allMethods) {

NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSessionTestDelegate* delegate = [NSURLSessionTestDelegate delegateFollowingRedirects:YES fulfillOnCompletion:nil];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:delegate delegateQueue:nil];

[self _test_redirect_NSURLSession:session httpMethod:method jsonBody:json delays:0.0 redirectStatusCode:303
completion:^(NSString *redirectedRequestMethod, id redirectedRequestJSONBody, NSHTTPURLResponse *redirectHTTPResponse, id finalJSONResponse, NSError *errorResponse)
{
Expand All @@ -337,9 +344,9 @@ - (void)test_NSURLSessionDefaultConfig_MethodAndDataRetentionOnRedirect
XCTAssertEqualObjects(finalJSONResponse, @{ @"RequestBody": json }, @"Unexpected JSON response received after 303 redirect");
XCTAssertNil(errorResponse, @"Unexpected error during 303 redirect");
}];
}

[session finishTasksAndInvalidate];
[session finishTasksAndInvalidate];
}
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Expand Up @@ -2,7 +2,7 @@

desc 'Build an iOS scheme'
task :ios, [:scheme, :ios_version, :action, :additional_args] do |_,args|
destination = "name=iPhone 5,OS=#{args.ios_version}"
destination = "name=iPhone 7,OS=#{args.ios_version}"
build("OHHTTPStubs #{args.scheme}", "iphonesimulator", destination, args.action, args.additional_args)
end

Expand All @@ -14,7 +14,7 @@ end

desc 'Build a tvOS scheme'
task :tvos, [:scheme, :tvos_version, :action, :additional_args] do |_,args|
destination = "name=Apple TV 1080p,OS=#{args.tvos_version}"
destination = "name=Apple TV,OS=#{args.tvos_version}"
build("OHHTTPStubs #{args.scheme}", "appletvsimulator", destination, args.action, args.additional_args)
end

Expand Down

0 comments on commit c088cfa

Please sign in to comment.