Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork511
Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.
License
vcr/vcr
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.
Help Wanted
We're looking for more maintainers. If you'd like to help maintain a well-used gem please spend some time reviewing pull requests, issues, or participating in discussions.
require'rubygems'require'test/unit'require'vcr'VCR.configuredo |config|config.cassette_library_dir="fixtures/vcr_cassettes"config.hook_into:webmockendclassVCRTest <Test::Unit::TestCasedeftest_example_dot_comVCR.use_cassette("synopsis")doresponse=Net::HTTP.get_response(URI('http://www.iana.org/domains/reserved'))assert_match/Example domains/,response.bodyendendend
Run this test once, and VCR will record the HTTP request tofixtures/vcr_cassettes/synopsis.yml. Run it again, and VCR will replay the response from iana.org when the HTTP request is made. This test is now fast (no real HTTP requests are made anymore), deterministic (the test will continue to pass, even if you are offline, or iana.org goes down for maintenance) and accurate (the response will contain the same headers and body you get from a real request). You can use a different cassette library directory (e.g., "test/vcr_cassettes").
NOTE: To avoid storing any sensitive information in cassettes, check outFilter Sensitive Data in the documentation.
Rails and Minitest:Donot use 'test/fixtures' as the directory if you're using Rails and Minitest (Rails will instead transitively load any files in that directory as models).
Features
- Automatically records and replays your HTTP interactions with minimal setup/configuration code.
- Supports and works with the HTTP stubbing facilities of multiple libraries. Currently, the following are supported:
- Supports multiple HTTP libraries:
- Patron (when using WebMock)
- Curb (when using WebMock -- only supports Curl::Easy at the moment)
- HTTPClient (when using WebMock)
- em-http-request (when using WebMock)
- Net::HTTP (when using WebMock)
- Typhoeus (Typhoeus::Hydra, but not Typhoeus::Easy or Typhoeus::Multi)
- Excon
- Faraday
- And of course any library built on Net::HTTP, such asMechanize,HTTParty orRest Client.
- Request matching is configurable based on HTTP method, URI, host, path, body and headers, or you can easily implement a custom request matcher to handle any need.
- The same request can receive different responses in different tests--just use different cassettes.
- The recorded requests and responses are stored on disk in a serialization format of your choice (currently YAML and JSON are built in, and you can easily implement your own custom serializer) and can easily be inspected and edited.
- Dynamic responses are supported using ERB.
- Optionally re-records cassettes on a configurable regular interval to keep them fresh and current.
- Disables all HTTP requests that you don't explicitly allow.
- Simple Cucumber integration is provided using tags.
- Includes convenient RSpec macros and integration with RSpec 2 metadata.
- Known to work well with many popular Ruby libraries including RSpec 1 & 2, Cucumber, Test::Unit, Capybara, Mechanize, Rest Client and HTTParty.
- Includes Rack and Faraday middleware.
- Supports filtering sensitive data from the response body
The docs come in two flavors:
- Theusage docs contain example-based documentation (VCR's Cucumber suite, in fact). It's a good place to look when you are first getting started with VCR, or if you want to see an example of how to use a feature.
- Therubydoc.info docs contain API documentation. The API docs contain detailed info about all of VCR's public API.
- See theCHANGELOG doc for info about what's new and changed.
There is also a Railscast (from 2011), which will get you up and running in no-timehttp://railscasts.com/episodes/291-testing-with-vcr.
Release Policy
VCR follows the principles ofsemantic versioning. TheAPI documentation defines VCR's public API. Patch level releases contain only bug fixes. Minor releases contain backward-compatible new features. Major new releases contain backwards-incompatible changes to the public API.
Ruby Interpreter Compatibility
VCR versions 6.x are tested on the following ruby interpreters:
- MRI 3.3
- MRI 3.2
- MRI 3.1
- MRI 3.0
- MRI 2.7
- MRI 2.6
VCR 6.0.0 is the last version supporting >= 2.3.VCR 6.1.0 is the last version supporting >= 2.6.Upcoming releases will only explicitly support >= 2.7.
Development
- Source hosted onGitHub.
- Direct questions and discussions onGitHub Issues.
- Report bugs/issues onGitHub Issues.
- Pull requests are very welcome! Please include spec and/or feature coverage for every patch,and create a topic branch for every separate change you make.
- See theContributingguide for instructions on running the specs and features.
- Code quality metrics are checked byCode Climate.
- Documentation is generated withYARD (cheat sheet).To generate while developing:
yard server --reloadPorts in Other Languages
- Betamax (Python)
- VCR.py (Python)
- Betamax (Go)
- DVR (Go)
- Go VCR (Go)
- vcr-clj (Clojure)
- scotch (C#/.NET)
- Betamax.NET (C#/.NET)
- Vcr.HttpRecorder (C#/.NET)
- ExVCR (Elixir)
- VCR (Haskell)
- Mimic (PHP/Kohana)
- PHP-VCR (PHP)
- Talkback (JavaScript/Node)
- NSURLConnectionVCR (Objective-C)
- VCRURLConnection (Objective-C)
- DVR (Swift)
- VHS (Erlang)
- Betamax (Java)
- http_replayer (Rust)
- OkReplay (Java/Android)
- vcr (R)
- hi8.cr (Crystal)
- eighttrack (Crystal)
- VCR (Crystal fork)
Related Projects
- Mr. Video (Rails engine for managing VCR cassettes and episodes)
Similar Libraries in Ruby
- Aslak Hellesøy forCucumber.
- Bartosz Blimke forWebMock.
- Chris Kampmeier forFakeWeb.
- Chris Young forNetRecorder,the inspiration for VCR.
- David Balatero andHans Hasselbergfor help withTyphoeus support.
- Wesley Beary for help withExconsupport.
- Jacob Green for help with ongoing VCRmaintenance.
- Jan Berdajs andDaniel Bergerfor improvements to thread-safety.
Thanks also to the following people who have contributed patches or helpful suggestions:
- Aaron Brethorst
- Alexander Wenzowski
- Austen Ito
- Avdi Grimm
- Bartosz Blimke
- Benjamin Oakes
- Ben Hutton
- Bradley Isotope
- Carlos Kirkconnell
- Chad Jolly
- Chris Le
- Chris Gunther
- Eduardo Maia
- Eric Allam
- Ezekiel Templin
- Flaviu Simihaian
- Gordon Wilson
- Hans Hasselberg
- Herman Verschooten
- Ian Cordasco
- Ingemar
- Ilya Scharrenbroich
- Jacob Green
- James Bence
- Jay Shepherd
- Jeff Pollard
- Joe Nelson
- Jonathan Tron
- Justin Smestad
- Karl Baum
- Kris Luminar
- Kurt Funai
- Luke van der Hoeven
- Mark Burns
- Max Riveiro
- Michael Lavrisha
- Michiel de Mare
- Mike Dalton
- Mislav Marohnić
- Nathaniel Bibler
- Noah Davis
- Oliver Searle-Barnes
- Omer Rauchwerger
- Paco Guzmán
- Paul Morgan
- playupchris
- Ron Smith
- Ryan Bates
- Ryan Burrows
- Ryan Castillo
- Sathya Sekaran
- Scott Carleton
- Shay Frendt
- Steve Faulkner
- Stephen Anderson
- Todd Lunter
- Tyler Hunt
- Uģis Ozols
- vzvu3k6k
- Wesley Beary
Support us with a monthly donation and help us continue our activities. [Become a backer]
Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]
About
Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.