diff --git a/OHHTTPStubs/Sources/OHHTTPStubs.m b/OHHTTPStubs/Sources/OHHTTPStubs.m index ec91f3a9..47c94eee 100644 --- a/OHHTTPStubs/Sources/OHHTTPStubs.m +++ b/OHHTTPStubs/Sources/OHHTTPStubs.m @@ -327,15 +327,7 @@ - (void)startLoading return; } - OHHTTPStubsResponse* responseStub; - @try { - responseStub = self.stub.responseBlock(request); - } - @catch (NSException *exception) { - NSError* err = [NSError errorWithDomain:@"OHHTTPStubs" code:500 userInfo:@{@"NSException": exception}]; - [client URLProtocol:self didFailWithError:err]; - @throw exception; - } + OHHTTPStubsResponse* responseStub = self.stub.responseBlock(request); if (OHHTTPStubs.sharedInstance.onStubActivationBlock) { diff --git a/OHHTTPStubs/Sources/OHHTTPStubsResponse.m b/OHHTTPStubs/Sources/OHHTTPStubsResponse.m index 65d66b00..69d846a7 100644 --- a/OHHTTPStubs/Sources/OHHTTPStubsResponse.m +++ b/OHHTTPStubs/Sources/OHHTTPStubsResponse.m @@ -128,8 +128,16 @@ -(instancetype)initWithFileAtPath:(NSString*)filePath statusCode:(int)statusCode headers:(NSDictionary*)httpHeaders { - NSParameterAssert(filePath != nil); - NSInputStream* inputStream = [NSInputStream inputStreamWithFileAtPath:filePath]; + NSInputStream* inputStream; + if (filePath) + { + inputStream = [NSInputStream inputStreamWithFileAtPath:filePath]; + } + else + { + NSLog(@"%s: nil file path. Returning empty data", __PRETTY_FUNCTION__); + inputStream = [NSInputStream inputStreamWithData:[NSData data]]; + } NSDictionary* attributes = [NSFileManager.defaultManager attributesOfItemAtPath:filePath error:nil]; unsigned long long fileSize = [[attributes valueForKey:NSFileSize] unsignedLongLongValue]; diff --git a/OHHTTPStubs/UnitTests/AFNetworking b/OHHTTPStubs/UnitTests/AFNetworking index c66282b0..58ca2e9b 160000 --- a/OHHTTPStubs/UnitTests/AFNetworking +++ b/OHHTTPStubs/UnitTests/AFNetworking @@ -1 +1 @@ -Subproject commit c66282b09855bbf8f83cb0b49df69349a07134d9 +Subproject commit 58ca2e9ba0dd03fd158695a426df3e2b475d1c8d diff --git a/OHHTTPStubs/UnitTests/Test Suites/NSURLConnectionTests.m b/OHHTTPStubs/UnitTests/Test Suites/NSURLConnectionTests.m index 258587f1..88101347 100644 --- a/OHHTTPStubs/UnitTests/Test Suites/NSURLConnectionTests.m +++ b/OHHTTPStubs/UnitTests/Test Suites/NSURLConnectionTests.m @@ -128,7 +128,7 @@ -(void)test_NSURLConnection_sendAsyncronousRequest_parallelQueue -(void)_test_NSURLConnection_sendMultipleAsyncronousRequestsOnOperationQueue:(NSOperationQueue*)queue { - + BOOL testFinished = NO; NSData* (^dataForRequest)(NSURLRequest*) = ^(NSURLRequest* req) { return [[NSString stringWithFormat:@"",req.URL.absoluteString] dataUsingEncoding:NSUTF8StringEncoding]; }; @@ -160,7 +160,7 @@ -(void)_test_NSURLConnection_sendMultipleAsyncronousRequestsOnOperationQueue:(NS XCTAssertEqualObjects(data, dataForRequest(req), @"Invalid data response"); XCTAssertEqualWithAccuracy(-[startDate timeIntervalSinceNow], (responseTime*.1)+responseTime, kResponseTimeTolerence, @"Invalid response time"); - [expectation fulfill]; + if (!testFinished) [expectation fulfill]; }]; }; @@ -170,6 +170,7 @@ -(void)_test_NSURLConnection_sendMultipleAsyncronousRequestsOnOperationQueue:(NS sendAsyncRequest(time1); // send this one last, should receive first [self waitForExpectationsWithTimeout:MAX(time1,MAX(time2,time3))+kResponseTimeTolerence handler:nil]; + testFinished = YES; } -(void)test_NSURLConnection_sendMultipleAsyncronousRequests_mainQueue diff --git a/OHHTTPStubs/UnitTests/Test Suites/NilValuesTests.m b/OHHTTPStubs/UnitTests/Test Suites/NilValuesTests.m index 37480b07..1e50e417 100644 --- a/OHHTTPStubs/UnitTests/Test Suites/NilValuesTests.m +++ b/OHHTTPStubs/UnitTests/Test Suites/NilValuesTests.m @@ -78,10 +78,6 @@ - (void)test_NilPath completionHandler:^(NSURLResponse* resp, NSData* data, NSError* error) { XCTAssertEqual(data.length, (NSUInteger)0, @"Data should be empty"); - XCTAssertEqualObjects(error.domain, @"OHHTTPStubs"); - XCTAssertEqual(error.code, 500); - NSException* ex = error.userInfo[ @"NSException"]; - XCTAssertEqualObjects([ex description], @"Invalid parameter not satisfying: filePath != nil"); [expectation fulfill]; }];