GithubHelp home page GithubHelp logo

benjaminoakes / vcr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vcr/vcr

1.0 3.0 0.0 2.05 MB

Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.

Home Page: http://relishapp.com/myronmarston/vcr

License: MIT License

Ruby 100.00%

vcr's Introduction

VCR

Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.

Build Status

Synopsis

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

VCR.config do |c|
  c.cassette_library_dir = 'fixtures/vcr_cassettes'
  c.stub_with :webmock # or :fakeweb
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/example/'))
      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).

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.
  • The same request can receive different responses in different tests--just use different cassettes.
  • The recorded requests and responses are stored on disk as YAML and can easily be inspected and edited.
  • Dynamic responses are supported using ERB.
  • Automatically 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 macro.
  • Known to work well with many popular ruby libraries including RSpec 1 & 2, Cucumber, Test::Unit, Capybara, Mechanize, Rest-Client and HTTParty.
  • Extensively tested on 7 different ruby interpretters.
  • Includes Rack and Faraday middleware.

Usage

Browse the documentation for usage info.

The VCR talk given at Philly.rb also contains good usage info.

Release Policy

VCR follows the principles of semantic versioning. The cucumber features define 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 has been tested on the following ruby interpreters:

  • MRI 1.8.7
  • MRI 1.9.2
  • REE 1.8.7
  • JRuby 1.5.6
  • Rubinius 1.2.1

Known Issues

  • VCR uses YAML to serialize the HTTP interactions to disk in a human-readable, human-editable format. Unfortunately there are bugs in Syck, Ruby's default YAML engine, that cause it to modify strings when serializing them. It appears the the bug is limited to entire lines of whitespace. A string such as "1\n \n2" will get changed to "1\n\n2" (see this gist for example code). In practice, this usually isn't so bad, but it can occassionally cause problems, especially when the recorded response includes a content_length header and you are using an HTTP client that relies on this. Mechanize will raise an EOFError when the content_length header does not match the response body length. One solution is to use Psych, the new YAML engine included in Ruby 1.9. VCR attempts to use Psych if possible, but you may have to re-compile ruby 1.9 to use it. See this issue for more info. You can also use the :update_content_length_header cassette option to ensure the header has the correct value.

Development

  • Source hosted on GitHub.
  • Direct questions and discussions to the mailing list.
  • Report issues on GitHub 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.

If you find VCR useful, please recommend me on working with rails.

Thanks

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

Copyright

Copyright (c) 2010-2011 Myron Marston. See LICENSE for details.

vcr's People

Contributors

myronmarston avatar bblimke avatar jsmestad avatar geemus avatar opsb avatar

Stargazers

Ben Oakes avatar

Watchers

Ben Oakes avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.