Skip to content

Instantly share code, notes, and snippets.

@bsorrentino
Last active May 17, 2016 10:28
Show Gist options
  • Save bsorrentino/30b8335501072a42afd2 to your computer and use it in GitHub Desktop.
Save bsorrentino/30b8335501072a42afd2 to your computer and use it in GitHub Desktop.
IOS unit test: Make a REST call and wait for result
- (void)testMBRequest
{
NSURL *url = ....;
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
MBJSONRequest *jsonRequest = [[MBJSONRequest alloc] init];
__block BOOL loaded = NO;
[jsonRequest performJSONRequest:urlRequest completionHandler:^(id responseJSON, NSError *error) {
XCTAssertNil(error, @"error on request: %@", error);
NSArray *posts = responseJSON[@"posts"];
XCTAssertNotNil(posts, @"posts not found!");
loaded = YES;
}];
NSRunLoop *theRL = [NSRunLoop currentRunLoop];
while (!loaded && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment