diff --git a/.travis.yml b/.travis.yml index 752671d5..d50b1b86 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,17 +10,17 @@ before_install: matrix: include: - osx_image: xcode8.3 - env: RAKETASK="ios[iOS Framework,latest,build test,-DOHHTTPSTUBS_SKIP_TIMING_TESTS=1]" + env: RAKETASK="ios[iOS Framework,latest,build test,OHHTTPSTUBS_SKIP_TIMING_TESTS=1 OHHTTPSTUBS_SKIP_REDIRECT_TESTS=1]" - osx_image: xcode8.3 - env: RAKETASK="osx[Mac Framework,x86_64,build test,-DOHHTTPSTUBS_SKIP_TIMING_TESTS=1]" + env: RAKETASK="osx[Mac Framework,x86_64,build test,OHHTTPSTUBS_SKIP_TIMING_TESTS=1 OHHTTPSTUBS_SKIP_REDIRECT_TESTS=1]" - osx_image: xcode9.1 - env: RAKETASK="ios[iOS StaticLib,latest,build-for-testing test-without-building,-DOHHTTPSTUBS_SKIP_TIMING_TESTS=1]" + env: RAKETASK="ios[iOS StaticLib,latest,build-for-testing test-without-building,OHHTTPSTUBS_SKIP_TIMING_TESTS=1 OHHTTPSTUBS_SKIP_REDIRECT_TESTS=1]" - osx_image: xcode9.1 - env: RAKETASK="ios[iOS Framework,latest,build-for-testing test-without-building]" + env: RAKETASK="ios[iOS Framework,latest,build-for-testing test-without-building,OHHTTPSTUBS_SKIP_REDIRECT_TESTS=1]" - osx_image: xcode9.1 - env: RAKETASK="osx[Mac Framework,x86_64,build-for-testing test-without-building,-DOHHTTPSTUBS_SKIP_TIMING_TESTS=1]" + env: RAKETASK="osx[Mac Framework,x86_64,build-for-testing test-without-building,OHHTTPSTUBS_SKIP_TIMING_TESTS=1 OHHTTPSTUBS_SKIP_REDIRECT_TESTS=1]" - osx_image: xcode9.1 - env: RAKETASK="tvos[tvOS Framework,latest,build-for-testing test-without-building,-DOHHTTPSTUBS_SKIP_TIMING_TESTS=1]" + env: RAKETASK="tvos[tvOS Framework,latest,build-for-testing test-without-building,OHHTTPSTUBS_SKIP_TIMING_TESTS=1 OHHTTPSTUBS_SKIP_REDIRECT_TESTS=1]" script: - rake "$RAKETASK" diff --git a/CHANGELOG.md b/CHANGELOG.md index 4525e763..3af1fe70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,12 @@ # OHHTTPStubs — CHANGELOG ## [Future release] -* Enabled application extension API only. +* Enabled application extension API only. [@lightsprint09](https://github.com/lightsprint09) -* Disabled a flaky redirect test and adding the known issue with redirects to the README. - [@jeffctown](https://github.com/jeffctown) - [#301](https://github.com/AliSoftware/OHHTTPStubs/pull/301) - +* Disabled a flaky redirect test and adding the known issue with redirects to the README. + [@jeffctown](https://github.com/jeffctown) [#301](https://github.com/AliSoftware/OHHTTPStubs/pull/301) +* Updating Conditional Unit Test Compilation. + [@jeffctown](https://github.com/jeffctown) [#302](https://github.com/AliSoftware/OHHTTPStubs/pull/302) ## [6.1.0](https://github.com/AliSoftware/OHHTTPStubs/releases/tag/6.1.0) diff --git a/OHHTTPStubs/OHHTTPStubs.xcodeproj/project.pbxproj b/OHHTTPStubs/OHHTTPStubs.xcodeproj/project.pbxproj index a3c426bd..1822d068 100644 --- a/OHHTTPStubs/OHHTTPStubs.xcodeproj/project.pbxproj +++ b/OHHTTPStubs/OHHTTPStubs.xcodeproj/project.pbxproj @@ -266,6 +266,7 @@ 1D0F8E811B6E31B00049A7D2 /* MocktailFolder */ = {isa = PBXFileReference; lastKnownFileType = folder; path = MocktailFolder; sourceTree = ""; }; 1D6DB84E1B763B7A00FCF855 /* OHHTTPStubs+Mocktail.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "OHHTTPStubs+Mocktail.h"; sourceTree = ""; }; 1D6DB84F1B763B7A00FCF855 /* OHHTTPStubs+Mocktail.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "OHHTTPStubs+Mocktail.m"; sourceTree = ""; }; + 1FE7BADB223157DB00FFF120 /* OHHTTPStubsProject.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = OHHTTPStubsProject.xcconfig; sourceTree = ""; }; 221C34A41B0CCF0600FCA8FF /* OHPathHelpersTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OHPathHelpersTests.m; sourceTree = ""; }; 221C34A61B0CCF9D00FCA8FF /* empty.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = empty.bundle; sourceTree = ""; }; 451243C1FC2A423646391951 /* Pods-TestingPods-OHHTTPStubs iOS Fmk Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TestingPods-OHHTTPStubs iOS Fmk Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-TestingPods-OHHTTPStubs iOS Fmk Tests/Pods-TestingPods-OHHTTPStubs iOS Fmk Tests.debug.xcconfig"; sourceTree = ""; }; @@ -368,6 +369,7 @@ 09110A3819805F4800D175E4 = { isa = PBXGroup; children = ( + 1FE7BADB223157DB00FFF120 /* OHHTTPStubsProject.xcconfig */, 09110A4619805F4800D175E4 /* OHHTTPStubs */, 095981C519806A7900807DBE /* Supporting Files */, 09110A5A19805F4800D175E4 /* UnitTests */, @@ -1280,6 +1282,7 @@ /* Begin XCBuildConfiguration section */ 09110A6219805F4800D175E4 /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 1FE7BADB223157DB00FFF120 /* OHHTTPStubsProject.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; @@ -1336,6 +1339,7 @@ }; 09110A6319805F4800D175E4 /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 1FE7BADB223157DB00FFF120 /* OHHTTPStubsProject.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; @@ -1463,10 +1467,6 @@ ); GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "UnitTests/UnitTests-Prefix.pch"; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); INFOPLIST_FILE = "UnitTests/UnitTests-Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; OTHER_LDFLAGS = ( @@ -1519,10 +1519,6 @@ ); FRAMEWORK_VERSION = A; GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); INFOPLIST_FILE = "Supporting Files/OHHTTPStubs Mac-Info.plist"; INSTALL_PATH = "@rpath"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -1572,10 +1568,6 @@ GCC_ENABLE_OBJC_EXCEPTIONS = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "UnitTests/UnitTests-Prefix.pch"; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); LD_RUNPATH_SEARCH_PATHS = "$inherited @executable_path/../Frameworks @loader_path/../Frameworks"; OTHER_LDFLAGS = ( "$(inherited)", @@ -1623,10 +1615,6 @@ DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)"; DYLIB_INSTALL_NAME_BASE = "@rpath"; ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); INFOPLIST_FILE = "Supporting Files/OHHTTPStubs iOS-Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -1707,10 +1695,6 @@ DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)"; DYLIB_INSTALL_NAME_BASE = "@rpath"; ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); INFOPLIST_FILE = "Supporting Files/OHHTTPStubs iOS-Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; diff --git a/OHHTTPStubs/OHHTTPStubsProject.xcconfig b/OHHTTPStubs/OHHTTPStubsProject.xcconfig new file mode 100644 index 00000000..5209339a --- /dev/null +++ b/OHHTTPStubs/OHHTTPStubsProject.xcconfig @@ -0,0 +1,30 @@ +// +// OHHTTPStubsProject.xcconfig +// OHHTTPStubs +// +// Created by Jeff Lett on 3/7/19. +// Copyright © 2019 AliSoftware. All rights reserved. +// + +// Configuration settings file format documentation can be found at: +// https://help.apple.com/xcode/#/dev745c5c974 + +// These build settings are used to disable specific unit tests. +// They can and should be overridden when running tests in CI using an xcodebuild argument. + + +// xcodebuild Example: +// xcodebuild -workspace OHHTTPStubs/OHHTTPStubs.xcworkspace -scheme "OHHTTPStubs iOS StaticLib" -sdk iphonesimulator -configuration Debug ONLY_ACTIVE_ARCH=NO OHHTTPSTUBS_SKIP_TIMING_TESTS=1 -destination 'name=iPhone 7,OS=latest' clean build test +// +// rake Example: +// rake ios['iOS StaticLib','latest','build-for-testing test-without-building',"OHHTTPSTUBS_SKIP_TIMING_TESTS=1"] +OHHTTPSTUBS_SKIP_TIMING_TESTS=0 + +// xcodebuild Example: +// xcodebuild -workspace OHHTTPStubs/OHHTTPStubs.xcworkspace -scheme "OHHTTPStubs iOS StaticLib" -sdk iphonesimulator -configuration Debug ONLY_ACTIVE_ARCH=NO OHHTTPSTUBS_SKIP_REDIRECT_TESTS=1 -destination 'name=iPhone 7,OS=latest' clean build test +// +// rake Example: +// rake ios['iOS StaticLib','latest','build-for-testing test-without-building',"OHHTTPSTUBS_SKIP_REDIRECT_TESTS=1"] +OHHTTPSTUBS_SKIP_REDIRECT_TESTS=0 + +GCC_PREPROCESSOR_DEFINITIONS=$(inherited) OHHTTPSTUBS_SKIP_TIMING_TESTS=$(OHHTTPSTUBS_SKIP_TIMING_TESTS) OHHTTPSTUBS_SKIP_REDIRECT_TESTS=$(OHHTTPSTUBS_SKIP_REDIRECT_TESTS) diff --git a/OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m b/OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m index 4a927608..cc84b104 100644 --- a/OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m +++ b/OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m @@ -294,65 +294,70 @@ - (void)test_NSURLSessionDefaultConfig_notFollowingRedirects Verify that redirects of different methods and status codes are handled properly and that we retain the HTTP Method for specific HTTP status codes as well as the data payload. **/ -//- (void)test_NSURLSessionDefaultConfig_MethodAndDataRetentionOnRedirect -//{ -// if ([NSURLSessionConfiguration class] && [NSURLSession class]) -// { -// NSDictionary* json = @{ @"query": @"Hello World" }; -// NSArray* 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) -// { -// XCTAssertEqualObjects(redirectedRequestMethod, method, -// @"Expected the HTTP method to be unchanged after %d redirect", statusCode); -// XCTAssertEqualObjects(redirectedRequestJSONBody, json, -// @"Expected %d-redirected request to have the same body as the original request", statusCode); -// XCTAssertNil(redirectHTTPResponse, -// @"%d Redirect response should not have been captured by the task completion block", statusCode); -// XCTAssertEqualObjects(finalJSONResponse, @{ @"RequestBody": json }, -// @"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) -// { -// XCTAssertEqualObjects(redirectedRequestMethod, @"GET", @"Expected 303 redirected request HTTP method to be reset to GET"); -// XCTAssertNil(redirectedRequestJSONBody, @"Expected 303-redirected request to have empty body"); -// XCTAssertNil(redirectHTTPResponse, @"303 Redirect response should not have been captured by the task completion block"); -// XCTAssertEqualObjects(finalJSONResponse, @{ @"RequestBody": json }, @"Unexpected JSON response received after 303 redirect"); -// XCTAssertNil(errorResponse, @"Unexpected error during 303 redirect"); -// }]; -// -// [session finishTasksAndInvalidate]; -// } -// } -// else -// { -// NSLog(@"/!\\ Test skipped because the NSURLSession class is not available on this OS version. Run the tests a target with a more recent OS.\n"); -// } -//} +#if OHHTTPSTUBS_SKIP_REDIRECT_TESTS +#warning Redirect Tests will be skipped for this run. +#else +- (void)test_NSURLSessionDefaultConfig_MethodAndDataRetentionOnRedirect +{ + if ([NSURLSessionConfiguration class] && [NSURLSession class]) + { + NSDictionary* json = @{ @"query": @"Hello World" }; + NSArray* 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) + { + XCTAssertEqualObjects(redirectedRequestMethod, method, + @"Expected the HTTP method to be unchanged after %d redirect", statusCode); + XCTAssertEqualObjects(redirectedRequestJSONBody, json, + @"Expected %d-redirected request to have the same body as the original request", statusCode); + XCTAssertNil(redirectHTTPResponse, + @"%d Redirect response should not have been captured by the task completion block", statusCode); + XCTAssertEqualObjects(finalJSONResponse, @{ @"RequestBody": json }, + @"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) + { + XCTAssertEqualObjects(redirectedRequestMethod, @"GET", @"Expected 303 redirected request HTTP method to be reset to GET"); + XCTAssertNil(redirectedRequestJSONBody, @"Expected 303-redirected request to have empty body"); + XCTAssertNil(redirectHTTPResponse, @"303 Redirect response should not have been captured by the task completion block"); + XCTAssertEqualObjects(finalJSONResponse, @{ @"RequestBody": json }, @"Unexpected JSON response received after 303 redirect"); + XCTAssertNil(errorResponse, @"Unexpected error during 303 redirect"); + }]; + + [session finishTasksAndInvalidate]; + } + } + else + { + NSLog(@"/!\\ Test skipped because the NSURLSession class is not available on this OS version. Run the tests a target with a more recent OS.\n"); + } +} +#endif + - (void)test_NSURLSessionEphemeralConfig { if ([NSURLSessionConfiguration class] && [NSURLSession class])