Skip to content

Consider adding VCR-like support #33

@mwlang

Description

@mwlang

I'd be happy to submit a PR that implements VCR-like support as implemented here:

https://github.com/mwlang/binance/blob/master/spec/support/vcr.cr

Basic idea taken from the Ruby VCR gem

With this, it makes writing a spec like this possible:

  context "success response" do
    it "#ping" do
      with_vcr_cassette "public/ping_success" do
        client.ping.pong.should be_truthy
      end
  end

  end
  context "error response" do
    it "#ping" do
      with_vcr_cassette("public/ping_error") do
        response = client.ping
        response.body.should eq "{\"code\": -3121, \"msg\": \"Strange Error.\"}"
        response.error_code.should eq -3121
        response.success.should be_falsey
      end
    end
  end

The first time a cassette is called and it's file does not exist, then the spec is implemented with a live call to the API server, capturing the response and writing both the request and response data to a *.yml file. The subsequent calls plays back the information captured.

Is there interest in adding this to the webmock shard? If so and approved, I'll implement in a PR and submit for consideration. If not interested, I will perhaps consider extracting this to a public shard, but would not have the time to take on a full-fledged re-implementation of the original Ruby vcr gem, hence the thought to contribute into the webmock framework where it's likely to be better maintained and grow with the community support.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions