Skip to content

Stub out HTTP requests for testing HTTP related Objective-C code.

Notifications You must be signed in to change notification settings

pascalw/PWFakeWeb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PWFakeWeb

PWFakeWeb is inspired by the ruby fakeweb gem. It allows you to stub out HTTP calls, for example through ASIHTTPRequest. Ideal for testing HTTP related code.

PWFakeWeb comes with a fakeweb implementation for ASIHTTPRequest. PWFakeWeb however is only loosely coupled to ASIHTTPRequest, allowing you to use PWFakeWeb to override calls in any HTTP library. For an example how to do this, checkout the ASIHTTPRequest+fakeweb.m source code.

Getting started

To get started link the PWFakeWeb static library into your testing target (for a walkthrough, see here).

Now all you need to do is #import ASIHTTPRequest+fakeweb.m into your test and off you go!

Examples

Registring fakes:

[PWFakeWeb registerURI: @"http://pwiddershoven.nl" method: @"GET" body: @"Hello, world!"];

NSURL *url = [NSURL URLWithString: @"http://pwiddershoven.nl"];

ASIHTTPRequest *request =  [ASIHTTPRequest requestWithURL: url];
[request startSynchronous];

[request responseString]; => @"Hello, world!"

You can also match URIs with regular expressions, like so:

[PWFakeWeb registerURI: @"http://google\.(com|nl|co\.uk)/(.*)" method: @"GET" body: @"Hello, world!"];

And set status codes:

[PWFakeWeb registerURI: @"http://google.com" method: @"POST" body: @"" status: 500];

See the specs in src/PWFakeWebSpecs/PWFakeWebSpec.m for a full usage example.

About

Stub out HTTP requests for testing HTTP related Objective-C code.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published