Created
March 8, 2013 16:32
-
-
Save daveshah/5117747 to your computer and use it in GitHub Desktop.
Okay... so this is a REALLY ugly test but it gets the point of what I'm looking for across... (hopefully)
I wanted to (as a sanity check) test the response of a web service. I'm using AFNetworking and the responses are by default asynchronous. To get around this in my tests I do a little something like this: I'm curious to know what others have …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)testThatICanMakeAWebRequest | |
{ | |
__block BOOL complete = NO; | |
__block NSString *response; | |
NSRunLoop *loop = [NSRunLoop currentRunLoop]; | |
NSURL *url = [NSURL URLWithString:@"http://some.nifty.url.com"]; | |
AFHTTPClient *httpClient = [[AFHTTPClient alloc]initWithBaseURL:url]; | |
[httpClient getPath:@"/myservice" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject){ | |
response = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; | |
complete = YES; | |
}failure:^(AFHTTPRequestOperation *operation, NSError *error){ | |
STFail(@"The Request Failed!"); | |
complete = YES; | |
}]; | |
while(!complete && [loop runMode:NSDefaultRunLoopMode beforeDate: [NSDate distantFuture]]); | |
//Assert what I'm looking for in response | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment