Last active
May 17, 2016 10:28
-
-
Save bsorrentino/30b8335501072a42afd2 to your computer and use it in GitHub Desktop.
IOS unit test: Make a REST call and wait for result
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)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