OUTDATED: This package is now maintained here
Originally forked from VCRURLConnection, this package provides VCR functionality for AFNetworking on iOS.
[VCR start];
NSString *path = @"http://example.com/example";
NSURL *url = [NSURL URLWithString:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
// use either NSURLSession or NSURLConnection
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request];
[task resume];
// NSURLSession makes a real network request and VCRURLConnection
// will record the request/response pair.
// once async request is complete or application is ready to exit:
[VCR save:@"/path/to/cassette.json"]; // copy the output file into your project
NSURL *cassetteURL = [NSURL fileURLWithPath:@"/path/to/cassette.json"];
[VCR loadCassetteWithContentsOfURL:cassetteURL];
[VCR start];
// request an HTTP interaction that was recorded to cassette.json
NSString *path = @"http://example.com/example";
NSURL *url = [NSURL URLWithString:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
// use either NSURLSession or NSURLConnection
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request];
[task resume];
// The cassette has a recording for this request, so no network request
// is made. Instead NSURLConnectionDelegate methods are called with the
// previously recorded response.
-
Download VCRURLConnection and try out the included example app
-
Include the files in the VCRURLConnection folder in your test target
-
Run your tests once to record all HTTP interactions
-
Copy the recorded json file (the file whose path is returned by
[VCR save]
) into your project -
Subsequent test runs will use the recorded HTTP interactions instead of the network
-
All recordings are stored in a single JSON file, which you can edit by hand
VCRURLConnection is released under the MIT license
Dustin Barker
- SenTestCase+SRTAdditions.h from SocketRocket by Square