A Crystal version of the Ruby HTTP interaction library vcr. Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.
Lots. But the main ones right now are - only recording once, then everything is a replay unless the files are deleted. TODO: I'd like to add a timer class to manage replays and replay intervals.
development_dependencies:
hi8:
github: vonkingsley/hi8.cr
HI8.configure do |config|
config.cabinet_shelf = "./test_dir/cassettes"
end
You can define a custom playback behaviour by setting the on_playback
block in the configuration. This can be necessary if you don't want to match against request headers for example. A basic definition for WebMock
could look like this:
HI8.configure do |config|
config.on_playback do |recorder, request, response|
uri = URI.parse(request.uri)
query = uri.query.to_s
uri.query = ""
req_headers = recorder.headers_from_hash(request.headers)
req_query = HTTP::Params.try(&.parse(query)).to_h
res_status = response.status.to_i
res_headers = recorder.headers_from_hash(response.headers)
::WebMock.stub(request.method, uri.to_s)
.with(query: req_query)
.to_return(status: res_status, body: response.body, headers: res_headers)
end
end
Cassette options are a Hash(Symbol, Symbol)
you can pass the options in the HI8.use_cassette
call
defaults are:
{
:record_mode => :once,
:record_with => :webmock,
:store_with => :file_system,
:format_with => :yaml
}
HI8.use_cassette("cassette_name") do
...
end
I probably take the whole Cassette emulation a little to far, but its fun. We have Cassettes which manage the playback and recording of episodes.
An Episode is an HTTP interaction.
StorageCabinets are where the cassettes are stored. Currently we only have the file system.
Formats are how the episode is stored on in the StorageCabinet
.
Currently we support YAML && JSON.
RecordingLibaries are the Mocking libraries. Currently we only support WebMock
- Fork it ( https://github.com/vonkingsley/hi8/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
- vonkingsley Kingsley Lewis - creator, maintainer
- alexanderadam Alexander Adam - likes the smell of video cassettes
Myron Marston and all the contributers of the original VCR