Skip to content

Instantly share code, notes, and snippets.

@delebedev
Created November 1, 2013 16:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save delebedev/7267579 to your computer and use it in GitHub Desktop.
Save delebedev/7267579 to your computer and use it in GitHub Desktop.
OHTTPStubs+ShortBlocks
void (^stubResponseWithHeaders)(NSString *, NSString *, NSDictionary *);
void (^stubResponse)(NSString *, NSString *);
void (^stubResponseWithStatusCode)(NSString *, int);
void (^stubResponseWithHeaders)(NSString *, NSString *, NSDictionary *) = ^(NSString *path, NSString *responseFilename, NSDictionary *headers) {
[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
return [request.URL.path isEqualToString:path];
} withStubResponse:^OHHTTPStubsResponse *(NSURLRequest *request) {
NSString *path = [[NSBundle bundleForClass:[OHHTTPStubs class]] pathForResource:[responseFilename stringByDeletingPathExtension] ofType:[responseFilename pathExtension]];
return [OHHTTPStubsResponse responseWithFileAtPath:path statusCode:200 headers:headers];
}];
};
void (^stubResponse)(NSString *, NSString *) = ^(NSString *path, NSString *responseFilename) {
stubResponseWithHeaders(path, responseFilename, @{@"content-type": @"application/json"});
};
void (^stubResponseWithStatusCode)(NSString *, int) = ^(NSString *path, int statusCode) {
[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
return [request.URL.path isEqualToString:path];
} withStubResponse:^OHHTTPStubsResponse *(NSURLRequest *request) {
return [OHHTTPStubsResponse responseWithData:[NSData data] statusCode:statusCode headers:@{@"content-type": @"application/json"}];
}];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment