Coder Social home page Coder Social logo

Comments (3)

AliSoftware avatar AliSoftware commented on May 21, 2024

Hi

Didn't know VCRURLConnection but it seems pretty straightforward to me to make it work with OHHTTPStubs. Not sure an official branch or addition would be useful.

After reading the source, it seems to me that you simply need to create a VCRCassette object from your JSON file, then for each request to stub, use [cassette recordingForRequest:theRequest] to get a VCRRecording object and build an OHHTTPStubsResponse with its properties:

VCRCassette* cassette = [[VCRCassette alloc] initWithData:[NSData dataWithContentsOfFile:yourJSONFileURL]];

[OHHTTPStubs shouldStubRequestsPassingTest:^BOOL(NSURLRequest *request) {
    return ([cassette recordingForRequest:request] != nil);
} withStubResponse:^OHHTTPStubsResponse*(NSURLRequest *request) {
    VCRRecording* rec = [cassette recordingForRequest:request];
    return [OHHTTPStubsResponse responseWithData:rec.data
                                      statusCode:rec.statusCode
                                    responseTime:whateverYourLike
                                         headers:rec.headerFields];
}];

And that should do the trick!
I haven't tested it but it doesn't seems to be anything more needed.

from ohhttpstubs.

stanislaw avatar stanislaw commented on May 21, 2024

Ah, thanks! I overlooked this -recordingForRequest part. Seems really simple now. I did switch from acceptance testing stuff for a while, I will look at this closer later.

I am closing this issue for now.

Anyway, let me know, if you will have any insights about using OHHTTPStubs together with VCR.

from ohhttpstubs.

AliSoftware avatar AliSoftware commented on May 21, 2024

Hi

For your information latest versions 1.2.x and 2.x.y of OHHTTPStubs now include the capability of loading files generated by the output of curl -is, that is files that include the headers (with the response status code) AND body.

Simply put each of your responses (with their headers and body) in a *.response file (for example using curl -is http://example.iana.org >example1.response) and then use [OHHTTPStubsResponse responseNamed:@"example1" inBundle:nil responseTime:...] to replay them.

Not really the same format as the JSON format used by your VCR class, but still quite the same principle as you can replay real requests easily.

from ohhttpstubs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.