Permalink
Browse files

Enable custom httpbin URL with HTTPBIN_BASE_URL environment variable

Editing the scheme and checking the `HTTPBIN_BASE_URL` box enables running the test suites on a default local installation of httpbin.
1 parent 0e947a7 commit 5d6867c3b6995374b374ab0783400de6a108b060 @0xced 0xced committed Oct 7, 2016
@@ -26,7 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
- shouldUseLaunchSchemeArgsEnv = "YES"
+ shouldUseLaunchSchemeArgsEnv = "NO"
codeCoverageEnabled = "YES">
<Testables>
<TestableReference
@@ -54,6 +54,13 @@
ReferencedContainer = "container:AFNetworking.xcodeproj">
</BuildableReference>
</MacroExpansion>
+ <EnvironmentVariables>
+ <EnvironmentVariable
+ key = "HTTPBIN_BASE_URL"
+ value = "http://127.0.0.1:5000"
+ isEnabled = "NO">
+ </EnvironmentVariable>
+ </EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
@@ -40,7 +40,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
- shouldUseLaunchSchemeArgsEnv = "YES"
+ shouldUseLaunchSchemeArgsEnv = "NO"
codeCoverageEnabled = "YES"
enableAddressSanitizer = "YES">
<Testables>
@@ -69,6 +69,18 @@
ReferencedContainer = "container:AFNetworking.xcodeproj">
</BuildableReference>
</MacroExpansion>
+ <EnvironmentVariables>
+ <EnvironmentVariable
+ key = "OS_ACTIVITY_MODE"
+ value = "disable"
+ isEnabled = "YES">
+ </EnvironmentVariable>
+ <EnvironmentVariable
+ key = "HTTPBIN_BASE_URL"
+ value = "http://127.0.0.1:5000"
+ isEnabled = "NO">
+ </EnvironmentVariable>
+ </EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
@@ -26,7 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
- shouldUseLaunchSchemeArgsEnv = "YES"
+ shouldUseLaunchSchemeArgsEnv = "NO"
enableAddressSanitizer = "YES">
<Testables>
<TestableReference
@@ -54,6 +54,18 @@
ReferencedContainer = "container:AFNetworking.xcodeproj">
</BuildableReference>
</MacroExpansion>
+ <EnvironmentVariables>
+ <EnvironmentVariable
+ key = "OS_ACTIVITY_MODE"
+ value = "disable"
+ isEnabled = "YES">
+ </EnvironmentVariable>
+ <EnvironmentVariable
+ key = "HTTPBIN_BASE_URL"
+ value = "http://127.0.0.1:5000"
+ isEnabled = "NO">
+ </EnvironmentVariable>
+ </EnvironmentVariables>
<AdditionalOptions>
<AdditionalOption
key = "NSZombieEnabled"
@@ -45,7 +45,7 @@ - (void)setUp {
- (void)testThatJSONRequestSerializationHandlesParametersDictionary {
NSDictionary *parameters = @{@"key":@"value"};
NSError *error = nil;
- NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:AFNetworkingTestsBaseURLString parameters:parameters error:&error];
+ NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:self.baseURL.absoluteString parameters:parameters error:&error];
XCTAssertNil(error, @"Serialization error should be nil");
@@ -57,7 +57,7 @@ - (void)testThatJSONRequestSerializationHandlesParametersDictionary {
- (void)testThatJSONRequestSerializationHandlesParametersArray {
NSArray *parameters = @[@{@"key":@"value"}];
NSError *error = nil;
- NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:AFNetworkingTestsBaseURLString parameters:parameters error:&error];
+ NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:self.baseURL.absoluteString parameters:parameters error:&error];
XCTAssertNil(error, @"Serialization error should be nil");
@@ -71,7 +71,7 @@ - (void)testThatJSONRequestSerializationHandlesInvalidParameters {
NSDictionary *parameters = @{@"key":string};
NSError *error = nil;
- NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:AFNetworkingTestsBaseURLString parameters:parameters error:&error];
+ NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:self.baseURL.absoluteString parameters:parameters error:&error];
XCTAssertNil(request, @"Expected nil request.");
XCTAssertNotNil(error, @"Expected non-nil error.");
@@ -80,7 +80,7 @@ - (void)testThatJSONRequestSerializationHandlesInvalidParameters {
- (void)testThatJSONRequestSerializationErrorsWithInvalidJSON {
NSDictionary *parameters = @{@"key":[NSSet setWithObject:@"value"]};
NSError *error = nil;
- NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:AFNetworkingTestsBaseURLString parameters:parameters error:&error];
+ NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:self.baseURL.absoluteString parameters:parameters error:&error];
XCTAssertNil(request, @"Request should be nil");
XCTAssertNotNil(error, @"Serialization error should be not nil");
@@ -39,15 +39,15 @@ - (void)setUp {
- (void)testThatPropertyListRequestSerializerAcceptsPlist {
NSDictionary *parameters = @{@"key":@"value"};
NSError *error = nil;
- NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:AFNetworkingTestsBaseURLString parameters:parameters error:&error];
+ NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:self.baseURL.absoluteString parameters:parameters error:&error];
XCTAssertNotNil(request, @"Expected non-nil request.");
}
- (void)testThatPropertyListRequestSerializerHandlesInvalidPlist {
NSDictionary *parameters = @{@42:@"value"};
NSError *error = nil;
- NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:AFNetworkingTestsBaseURLString parameters:parameters error:&error];
+ NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:self.baseURL.absoluteString parameters:parameters error:&error];
XCTAssertNil(request, @"Expected nil request.");
XCTAssertNotNil(error, @"Expected non-nil error.");
@@ -21,8 +21,6 @@
#import <XCTest/XCTest.h>
-extern NSString * const AFNetworkingTestsBaseURLString;
-
@interface AFTestCase : XCTestCase
@property (nonatomic, strong, readonly) NSURL *baseURL;
@@ -21,8 +21,6 @@
#import "AFTestCase.h"
-NSString * const AFNetworkingTestsBaseURLString = @"https://httpbin.org/";
-
@implementation AFTestCase
- (void)setUp {
@@ -37,7 +35,8 @@ - (void)tearDown {
#pragma mark -
- (NSURL *)baseURL {
- return [NSURL URLWithString:AFNetworkingTestsBaseURLString];
+ NSDictionary *environment = [[NSProcessInfo processInfo] environment];
+ return [NSURL URLWithString:environment[@"HTTPBIN_BASE_URL"] ?: @"https://httpbin.org"];
}
- (NSURL *)pngURL {

0 comments on commit 5d6867c

Please sign in to comment.