vcr
vcr
VCR for Crystal!
Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.
Installation
Add this to your application's shard.yml
:
dependencies:
vcr:
github: spoved/vcr.cr
Usage
require "vcr"
require "http/client"
load_cassette("cassette-one") do
response = HTTP::Client.get("https://jsonplaceholder.typicode.com/todos/1")
end
You can also record multiple requests within a single block:
load_cassette("cassette-two") do
r1 = HTTP::Client.get("https://jsonplaceholder.typicode.com/todos/1")
r2 = HTTP::Client.get("https://jsonplaceholder.typicode.com/todos/2")
end
To easily reset the cassette and record, simply add the :record
argument:
load_cassette("cassette-two", :record) do
r1 = HTTP::Client.get("https://jsonplaceholder.typicode.com/todos/1")
r2 = HTTP::Client.get("https://jsonplaceholder.typicode.com/todos/2")
end
Customize the location of where the cassettes are stored. The default is spec/fixtures/vcr
.
VCR.configure do
settings.cassette_library_dir = "/some/path/cassettes"
end
Contributing
- Fork it (https://github.com/spoved/vcr.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- your-github-user Holden Omans - creator, maintainer