Skip to content

Instantly share code, notes, and snippets.

@seanwolter
Last active December 15, 2015 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanwolter/5198852 to your computer and use it in GitHub Desktop.
Save seanwolter/5198852 to your computer and use it in GitHub Desktop.
/*
* SenTestingKit does not wait for blocks to finish by default so your test would simply complete
* as successful. You need to use a semaphore and keep the run loop going in order for the test
* to properly run.
*/
- (void)testGetSpots {
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
CLLocation location = [[CLLocation alloc] initWithLatitude:70.0 longitude:50.0];
[Spot spotsWithURLString:@"/spots" near:location parameters:[NSDictionary dictionaryWithObject:@"128" forKey:@"per_page"] block:^(NSArray *records) {
//sample assert
STAssertNotNil(records,@"Could not load spots");
dispatch_semaphore_signal(semaphore);
}];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW)
dispatch_release(semaphore);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment