URLRaider

Created: 2012-03-22 15:24
Updated: 2016-12-01 13:35

README.md

Recommended that use other alternative libraries.

iOS/OS Xテスト向けのURL読み込みに偽のレスポンスを返すモジュールいろいろ - laiso - iPhoneアプリ開発グループ

URLRaider

A test helper for rewriting responses at Cocoa URL request API.

NSURL* url = [NSURL URLWithString:@"http://example.com/api/hi.json"];
NSString* fakeResponse = @"{\"title\": \"Hello, 世界!\"}";
[URLRaider order:url body:fakeResponse];

NSURLRequest* request = [NSURLRequest requestWithURL:url];
NSData* responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

NSString* responseText = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
STAssertEqualObjects(responseText, fakeResponse, nil);
STAssertEqualObjects(responseData, [fakeResponse dataUsingEncoding:NSUTF8StringEncoding], nil);

[URLRaider purge];
Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more