https://github.com/pascalw/pwfakeweb
Stub out HTTP requests for testing HTTP related Objective-C code.
https://github.com/pascalw/pwfakeweb
Last synced: 10 months ago
JSON representation
Stub out HTTP requests for testing HTTP related Objective-C code.
- Host: GitHub
- URL: https://github.com/pascalw/pwfakeweb
- Owner: pascalw
- Created: 2011-10-01T12:31:22.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2011-12-19T20:46:42.000Z (over 14 years ago)
- Last Synced: 2025-03-03T04:27:12.941Z (over 1 year ago)
- Language: Objective-C
- Homepage:
- Size: 105 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PWFakeWeb
PWFakeWeb is inspired by the ruby [fakeweb gem](http://fakeweb.rubyforge.org/). It allows you to stub out HTTP calls, for example through [ASIHTTPRequest](http://allseeing-i.com/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](http://stackoverflow.com/questions/6124523/linking-a-static-library-to-an-ios-project-in-xcode-4/6124872#6124872)).
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.