基于 Nocilla 的替换部分/全部 HTTP 响应的库。
在真实请求之前在任何地方模拟请求。
它将返回默认响应,即状态码 200 和空正文。
mockRequest(@"GET", @"http://www.google.com");
mockRequest(@"GET", @"(.*?)google.com(.*?)".regex).
withBody(@"{\"name\":\"abc\"}".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 在 MIT 许可证下发布。有关详细信息,请参阅 LICENSE。