Library for replacing part/all HTTP response based on Nocilla.
- Support NSURLConnection, NSURLSession.
- Support replacing totally or partly HTTP response
- Match requests with regular expressions.
- Support json file for response
To integrate GYHttpMock into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'GYHttpMock'
Then, run the following command:
$ pod install
mocking a request before the real request anywhere.
It will return the default response, which is a 200 and an empty body.
mockRequest(@"GET", @"http://www.google.com");
mockRequest(@"GET", @"(.*?)google.com(.*?)".regex);
mockRequest(@"POST", @"http://www.google.com").
isUpdatePartResponseBody(YES).
withBody(@"{\"name\":\"abc\"}".regex);
andReturn(200).
withBody(@"{\"key\":\"value\"}");
mockRequest(@"POST", @"http://www.google.com").
isUpdatePartResponseBody(YES).
withBody(@"{\"name\":\"abc\"}".regex);
andReturn(200).
withBody(@"google.json");
orginal response:
{"data":{"id":"abc","location":"GZ"}}
updatedBody: google.json
{"data":{"time":"today"}}
final resoponse:
{"data":{"id":"abc","location":"GZ","time":"today"}}
mockRequest(@"POST", @"http://www.google.com").
withHeaders(@{@"Accept": @"application/json"}).
withBody(@"\"name\":\"foo\"".regex).
isUpdatePartResponseBody(YES).
andReturn(200).
withHeaders(@{@"Content-Type": @"application/json"}).
withBody(@"google.json");
[GYHttpMock sharedInstance].logBlock = ^(NSString *logStr) {
NSLOG(@"%@", logStr);
};
GYHttpMock is released under the MIT license. See LICENSE for details.