VCR
v-6.0.0
v-6.0.0
  • Introduction
  • Upgrade
  • Changelog
  • About These Examples
  • License
  • Contributing
  • Cassettes
    • Cassette Format
    • Naming
    • Error for HTTP Request Made When No Cassette Is in Use
    • Dynamic ERB Cassettes
    • Automatic Re-Recording
    • Exclusive Cassette
    • Update Content Length Header
    • Decode Compressed Response
    • Allow Unused HTTP Interactions
    • Freezing Time
  • Record modes
    • Once
    • New Episodes
    • None
    • All
    • Record on Error
  • Configuration
    • Cassette Library Dir
    • Hook Into
    • Default Cassette Options
    • Ignore Request
    • Filter Sensitive Data
    • Allow HTTP Connections When No Cassette
    • Debug Logging
    • Preserve Exact Body Bytes
    • URI Parser
    • Query Parser
  • Hooks
    • Before Record Hook
    • Before Playback Hook
    • Before HTTP Request Hook
    • After HTTP Request Hook
    • Around HTTP Request Hook
  • Request matching
    • Introduction
    • Matching on Method
    • Matching on URI
    • Matching on Host
    • Matching on Path
    • Matching on Query String
    • Matching on Body
    • Matching on Headers
    • Identical Requests Are Replayed in Sequence
    • Register and Use a Custom Matcher
    • URI Without Param(s)
    • Playback Repeats
    • Matching on Body as JSON
  • Test frameworks
    • Usage With Test::Unit
    • Usage With RSpec Metadata
    • Usage With Cucumber
  • Middleware
    • Rack
    • Faraday Middleware
  • HTTP Libraries
    • Net::HTTP
    • EM HTTP Request
Powered by GitBook
On this page
  • vcr
  • Usage
  • Credits
  • Backers
  • Sponsors

Was this helpful?

Introduction

NextUpgrade

Last updated 5 years ago

Was this helpful?

vcr

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.

Usage

require 'rubygems'
require 'test/unit'
require 'vcr'

VCR.configure do |config|
  config.cassette_library_dir = "fixtures/vcr_cassettes"
  config.hook_into :webmock
end

class VCRTest < Test::Unit::TestCase
  def test_example_dot_com
    VCR.use_cassette("synopsis") do
      response = Net::HTTP.get_response(URI('http://www.iana.org/domains/reserved'))
      assert_match /Example domains/, response.body
    end
  end
end

Run this test once, and VCR will record the HTTP request to fixtures/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").

Rails and Minitest: Do not 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:

  • 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:

Release Policy

Ruby Interpreter Compatibility

VCR versions 6.x are tested on the following ruby interpreters:

  • MRI 2.4

  • MRI 2.5

  • MRI 2.6

Note that as of VCR 6, only 2.3+ is explicitly supported.

Development

  • 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.

  • guide for instructions on running the specs and features.

  • To generate while developing:

yard server --reload

Ports in Other Languages

Related Projects

Similar Libraries in Ruby

Credits

  • the inspiration for VCR.

  • support.

  • maintenance.

  • for improvements to thread-safety.

Thanks also to the following people who have contributed patches or helpful suggestions:

Backers

Sponsors

NOTE: To avoid storing any sensitive information in cassettes, check out in the documentation.

(when using WebMock)

(when using WebMock -- only supports Curl::Easy at the moment)

(when using WebMock)

(when using WebMock)

(when using WebMock)

(Typhoeus::Hydra, but not Typhoeus::Easy or Typhoeus::Multi)

And of course any library built on Net::HTTP, such as , or .

The 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.

The contain API documentation. The API docs contain detailed info about all of VCR's public API.

See the 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-time .

VCR follows the principles of . The 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.

Source hosted on .

Direct questions and discussions on .

Report bugs/issues on .

See the

Code quality metrics are checked by .

Documentation is generated with ().

(Python)

(Python)

(Go)

(Go)

(Go)

(Clojure)

(Clojure)

(C#/.NET)

(C#/.NET)

(Elixir)

(Haskell)

(PHP/Kohana)

(PHP)

(JavaScript/Node)

(JavaScript/Node)

(JavaScript)

(JavaScript/Node)

(Objective-C)

(Objective-C)

(Swift)

(Erlang)

(Java)

(Rust)

(Java/Android)

(R)

(Rails engine for managing VCR cassettes and episodes)

for .

for .

for .

for ,

and

for help with support.

for help with

for help with ongoing VCR

and

Support us with a monthly donation and help us continue our activities. []

Become a sponsor and get your logo on our README on Github with a link to your site. []

Filter Sensitive Data
WebMock
Typhoeus
Faraday
Excon
Patron
Curb
HTTPClient
em-http-request
Net::HTTP
Typhoeus
Excon
Faraday
Mechanize
HTTParty
Rest Client
relish docs
rubydoc.info docs
CHANGELOG
http://railscasts.com/episodes/291-testing-with-vcr
semantic versioning
API documentation
GitHub
GitHub Issues
GitHub Issues
Contributing
Code Climate
YARD
cheat sheet
Betamax
VCR.py
Betamax
DVR
Go VCR
Betamax
vcr-clj
scotch
Betamax.NET
ExVCR
HAVCR
Mimic
PHP-VCR
Nock-VCR
Sepia
VCR.js
yakbak
NSURLConnectionVCR
VCRURLConnection
DVR
VHS
Betamax
http_replayer
OkReplay
vcr
Mr. Video
Ephemeral Response
Net::HTTP Spy
NetRecorder
Puffing Billy
REST-assured
Stale Fish
WebFixtures
Aslak Hellesøy
Cucumber
Bartosz Blimke
WebMock
Chris Kampmeier
FakeWeb
Chris Young
NetRecorder
David Balatero
Hans Hasselberg
Typhoeus
Wesley Beary
Excon
Jacob Green
Jan Berdajs
Daniel Berger
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
Become a backer
Become a sponsor
Build
GitHub tag (latest SemVer)
Version
OpenCollective
OpenCollective