Skip to content

Commit 53dee4d

Browse files
committed
Acceptance test: Extract boilerplate networking
1 parent 257f6ed commit 53dee4d

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

MarvelBrowser/QCOMarvelAuthenticationAcceptanceTests.m

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,24 @@ - (void)testValidCallToMarvel_ShouldGetHTTPStatusCode200
2121
NSURL *validQueryURL = [NSURL URLWithString:
2222
[validQueryMissingAuthentication stringByAppendingString:[authentication URLParameters]]];
2323

24+
__block NSHTTPURLResponse *httpResponse;
25+
[self startGETRequestToURL:validQueryURL
26+
withCompletionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
27+
httpResponse = (NSHTTPURLResponse *)response;
28+
}];
29+
30+
assertThatAfter(5, futureValueOf(@(httpResponse.statusCode)), is(@200));
31+
}
32+
33+
- (void)startGETRequestToURL:(NSURL *)url
34+
withCompletionHandler:(void (^)(NSData *, NSURLResponse *, NSError *))completionHandler
35+
{
2436
NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
2537
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig
2638
delegate:nil
2739
delegateQueue:nil];
28-
__block NSHTTPURLResponse *httpResponse;
29-
NSURLSessionDataTask *dataTask = [session dataTaskWithURL:validQueryURL
30-
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
31-
httpResponse = (NSHTTPURLResponse *)response;
32-
}];
40+
NSURLSessionDataTask *dataTask = [session dataTaskWithURL:url completionHandler:completionHandler];
3341
[dataTask resume];
34-
35-
assertThatAfter(5, futureValueOf(@(httpResponse.statusCode)), is(@200));
3642
}
3743

3844
@end

0 commit comments

Comments
 (0)