Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding VCR-like support #33

Open
mwlang opened this issue Jun 12, 2019 · 2 comments
Open

Consider adding VCR-like support #33

mwlang opened this issue Jun 12, 2019 · 2 comments

Comments

@mwlang
Copy link

mwlang commented Jun 12, 2019

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.

@straight-shoota
Copy link

IMO this should be a separate shard, building on top of webmock.

@mwlang
Copy link
Author

mwlang commented Jun 12, 2019

I discovered while reading through other issues on this shard that "hi8" exists and probably should close this issue on account. See #20 for more info. Still open to discussion about adding this kind of functionality. For me, it's hard to say whether it's worth a separate shard or not. If all Crystal shards were easier to find out in the wild, then I'd definitely agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants