Created
November 1, 2013 16:01
-
-
Save delebedev/7267579 to your computer and use it in GitHub Desktop.
OHTTPStubs+ShortBlocks
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 (^stubResponseWithHeaders)(NSString *, NSString *, NSDictionary *); | |
void (^stubResponse)(NSString *, NSString *); | |
void (^stubResponseWithStatusCode)(NSString *, int); |
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 (^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