Giter VIP home page Giter VIP logo

vcr's Introduction

vcr

CI status GitHub tag (latest SemVer) Version OpenCollective OpenCollective

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").

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

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:

  • The usage 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.
  • The rubydoc.info docs contain API documentation. The API docs contain detailed info about all of VCR's public API.
  • See the CHANGELOG 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 http://railscasts.com/episodes/291-testing-with-vcr.

Release Policy

VCR follows the principles of semantic versioning. The API 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.1
  • MRI 3.0
  • MRI 2.7
  • MRI 2.6

VCR 6.0.0 is the last version supporting >= 2.4. Upcoming releases will only explicitly support >= 2.6.

Development

  • Source hosted on GitHub.
  • Direct questions and discussions on GitHub Issues.
  • Report bugs/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.
  • See the Contributing guide for instructions on running the specs and features.
  • Code quality metrics are checked by Code Climate.
  • Documentation is generated with YARD (cheat sheet). To generate while developing:
yard server --reload

Ports in Other Languages

Related Projects

  • Mr. Video (Rails engine for managing VCR cassettes and episodes)

Similar Libraries in Ruby

Credits

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

Backers

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

Sponsors

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

vcr's People

Contributors

64kramsystem avatar andrehjr avatar casperisfine avatar cgunther avatar challengee avatar ecnalyr avatar hirowatari avatar ikapelyukhin avatar knu avatar krainboltgreene avatar marshall-lee avatar mattbrictson avatar mcfiredrill avatar mislav avatar mrbrdo avatar myronmarston avatar nbibler avatar nellirx avatar nicholaides avatar olleolleolle avatar plukevdh avatar rhburrows avatar rmcastil avatar s-mage avatar sambostock avatar sbleon avatar scotterc avatar sigmavirus24 avatar tlunter avatar vzvu3k6k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vcr's Issues

:record_once record option?

This would simplify creating new cassette files.

My workflow is something like:

  1. Write code using HTTP in a TDD way
  2. Once the request (and response) are correct, record with VCR
  3. continue testing and developing code
  4. move onto other features

At the moment, I globally configure record to :none, and set record to :new_episodes in the specific test I'm working on.

The problem comes when I get the request/response correct, but forget to remove record: :new_expisodes. On the next test run, I end up with multiple request/responses in my cassette file (not good), and with the API I'm currently using, errors from the remote end as the request is non-repeatable, so the test fails (bad).

I suggest adding a :once :write_once or :record_once option, that only writes if the file is missing or empty.

Multiple requests would be fine, as long as they're within the "use_cassette" block.

getting EOFError on playback

I appear to be getting EOFError when playing back a cassette.

I'm using VCR 1.6.0 => webmock 1.6.2 => Mechanize 1.0.0

Following are:

  • configuration info
  • the backtrace
  • the RSpec file
  • the YAML cassette file that appears to be generating the EOFError

I'm less clear on how to cons up a standalone example, so if you need additional tests or info, just holler.

CONFIGURATION INFO

$ rake about
About your application's environment
Ruby version              1.9.2 (x86_64-darwin10.6.0)
RubyGems version          1.3.7
Rack version              1.2
Rails version             3.0.3
Active Record version     3.0.1
Action Pack version       3.0.3
Active Resource version   3.0.3
Action Mailer version     3.0.3
Active Support version    3.0.3
Application root          xxx
Environment               development

$ bundle show
Gems included by the bundle:
  * ZenTest (4.4.2)
  * abstract (1.0.0)
  * actionmailer (3.0.3)
  * actionpack (3.0.3)
  * activemodel (3.0.3)
  * activerecord (3.0.3)
  * activeresource (3.0.3)
  * activesupport (3.0.3)
  * addressable (2.2.4)
  * annotate-models (1.0.4)
  * arel (2.0.7)
  * autotest (4.4.6)
  * bcrypt-ruby (2.1.4)
  * builder (2.1.2)
  * bundler (1.0.9)
  * crack (0.1.8)
  * devise (1.1.5)
  * diff-lcs (1.1.2)
  * erubis (2.6.6)
  * factory_girl (1.3.3)
  * factory_girl_rails (1.0.1)
  * faker (0.9.4)
  * gravatar_image_tag (1.0.0)
  * i18n (0.5.0)
  * jquery-rails (0.2.6)
  * mail (2.2.14)
  * mechanize (1.0.0)
  * mime-types (1.16)
  * nokogiri (1.4.4)
  * polyglot (0.3.1)
  * rack (1.2.1)
  * rack-mount (0.6.13)
  * rack-test (0.5.7)
  * rails (3.0.3)
  * railties (3.0.3)
  * rake (0.8.7)
  * rspec (2.4.0)
  * rspec-core (2.4.0)
  * rspec-expectations (2.4.0)
  * rspec-mocks (2.4.0)
  * rspec-rails (2.4.1)
  * sqlite3 (1.3.3)
  * sqlite3-ruby (1.3.3)
  * thor (0.14.6)
  * treetop (1.4.9)
  * tzinfo (0.3.24)
  * vcr (1.6.0)
  * warden (1.0.3)
  * webmock (1.6.2)
  * webrat (0.7.3)
  * will_paginate (2.3.15)

THE BACKTRACE:

  1) Premise Zillow ETL should not raise an exception for a sucessful case
     Failure/Error: lambda do
       expected no Exception, got #<EOFError: EOFError>
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-expectations-2.4.0/lib/rspec/expectations/fail_with.rb:29:in `fail_with'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-expectations-2.4.0/lib/rspec/expectations/handler.rb:44:in `handle_matcher'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-expectations-2.4.0/lib/rspec/expectations/extensions/kernel.rb:50:in `should_not'
     # ./spec/models/zillow_etl_spec.rb:24:in `block (4 levels) in <top (required)>'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/vcr-1.6.0/lib/vcr.rb:67:in `call'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/vcr-1.6.0/lib/vcr.rb:67:in `use_cassette'
     # ./spec/models/zillow_etl_spec.rb:23:in `block (3 levels) in <top (required)>'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:49:in `instance_eval'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:49:in `block (2 levels) in run'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:98:in `with_around_hooks'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:46:in `block in run'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:91:in `block in with_pending_capture'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:90:in `catch'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:90:in `with_pending_capture'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:45:in `run'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:261:in `block in run_examples'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:257:in `map'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:257:in `run_examples'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:231:in `run'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:232:in `block in run'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:232:in `map'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:232:in `run'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/command_line.rb:27:in `block (2 levels) in run'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/command_line.rb:27:in `map'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/command_line.rb:27:in `block in run'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/reporter.rb:12:in `report'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/command_line.rb:24:in `run'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/runner.rb:55:in `run_in_process'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/runner.rb:46:in `run'
     # $RAILS_LIB/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/runner.rb:10:in `block in autorun'

Finished in 0.15279 seconds
1 example, 1 failure

THE RSPEC FILE

require 'spec_helper'
describe Premise do
  before(:each) do
    @record_mode = :none
  end
  describe "Zillow ETL" do
    it "should not raise an exception for a sucessful case" do
      VCR.use_cassette("zillow_etl_spec", :record => @record_mode) do
        lambda do
          Premise.create(:address => "1 Hilltop Cir., Morristown, NJ  07960, USA", :lat => 0.0, :lng => 0.0)
        end.should_not raise_exception
      end
    end
  end
end

THE YAML FILE

--- 
- !ruby/struct:VCR::HTTPInteraction 
  request: !ruby/struct:VCR::Request 
    method: :get
    uri: http://www.zillow.com:80/webservice/GetDeepSearchResults.htm?address=1%20Hilltop%20Cir.&citystatezip=Morristown,%20NJ%20%2007960&zws-id=********************
    body: 
    headers: 
      user-agent: 
      - WWW-Mechanize/1.0.0 (http://rubyforge.org/projects/mechanize/)
      connection: 
      - keep-alive
      keep-alive: 
      - "300"
      accept-encoding: 
      - gzip,identity
      accept-language: 
      - en-us,en;q=0.5
      host: 
      - www.zillow.com
      accept-charset: 
      - ISO-8859-1,utf-8;q=0.7,*;q=0.7
  response: !ruby/struct:VCR::Response 
    status: !ruby/struct:VCR::ResponseStatus 
      code: 200
      message: OK
    headers: 
      date: 
      - Mon, 07 Feb 2011 18:28:16 GMT
      server: 
      - Apache-Coyote/1.1
      x-powered-by: 
      - "Servlet 2.4; JBoss-4.0.3SP1 (build: CVSTag=JBoss_4_0_3_SP1 date=200510231054)/Tomcat-5.5"
      x-internal-host: 
      - "120"
      expires: 
      - Thu, 01 Jan 1970 00:00:00 GMT
      cache-control: 
      - no-cache
      content-type: 
      - text/xml;charset=UTF-8
      content-length: 
      - "2446"
      set-cookie: 
      - BIGipServerapache_pool_0=2567703050.0.0000; path=/
      - JSESSIONID=35363ADAB106C79E3FBD769EB658C90A; Path=/
      - JSESSIONID=35363ADAB106C79E3FBD769EB658C90A; Path=/
      - abtest=1|BotoxDefaultView%3D18%3ABotoxOnHDP%3D22%3AMortgageShoppingForm%3D40%3AMortgageShoppingContactOptions%3D36%3AMortgageShoppingQuoteViewTest%3D53%3AMortgageShoppingBestQuotesFilterTest%3D53; Domain=.zillow.com; Expires=Sun, 07-Feb-2021 06:28:16 GMT; Path=/
      - bchk=1; Domain=.zillow.com; Path=/
      - zguid=3|79b71eb9-d0fa-4756-a8ee-1c820d45837e%09false%09%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%09false; Domain=.zillow.com; Expires=Sun, 07-Feb-2021 06:28:16 GMT; Path=/
      via: 
      - 1.1 www.zillow.com
      vary: 
      - User-Agent
      keep-alive: 
      - timeout=2, max=44
    body: |-
      <?xml version="1.0" encoding="utf-8"?>
      <SearchResults:searchresults xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.zillow.com/static/xsd/SearchResults.xsd http://www.zillowstatic.com/vstatic/efc5f6d2dc09e251664253ffeeef0b32/static/xsd/SearchResults.xsd" xmlns:SearchResults="http://www.zillow.com/static/xsd/SearchResults.xsd">

          <request>
              <address>1 Hilltop Cir.</address>
              <citystatezip>Morristown, NJ  07960</citystatezip>
          </request>

          <message>
              <text>Request successfully processed</text>
              <code>0</code>

          </message>


          <response>
                <results>

                        <result>
                        <zpid>39454581</zpid>
        <links>
                <homedetails>http://www.zillow.com/homedetails/1-Hilltop-Cir-Morristown-NJ-07960/39454581_zpid/</homedetails>

                <graphsanddata>http://www.zillow.com/homedetails/1-Hilltop-Cir-Morristown-NJ-07960/39454581_zpid/#charts-and-data</graphsanddata>

                <mapthishome>http://www.zillow.com/homes/39454581_zpid/</mapthishome>

                <myestimator>http://www.zillow.com/myestimator/Edit.htm?zprop=39454581</myestimator>
                <myzestimator deprecated="true">http://www.zillow.com/myestimator/Edit.htm?zprop=39454581</myzestimator>

              <comparables>http://www.zillow.com/homes/comps/39454581_zpid/</comparables>
        </links>
        <address>
                <street>1 Hilltop Cir</street>
                <zipcode>07960</zipcode>
                <city>Morristown</city>
                <state>NJ</state>
                <latitude>40.774817</latitude>
                <longitude>-74.482526</longitude>
        </address>

                <FIPScounty>34027</FIPScounty>
            <useCode>SingleFamily</useCode>


                <taxAssessmentYear>2010</taxAssessmentYear>
                <taxAssessment>563200.0</taxAssessment>
                <yearBuilt>1950</yearBuilt>
                <lotSizeSqFt>67748</lotSizeSqFt>
                <finishedSqFt>2944</finishedSqFt>






        <zestimate>
                <amount currency="USD">716500</amount>
                <last-updated>02/01/2011</last-updated>


                        <oneWeekChange deprecated="true"></oneWeekChange>


                        <valueChange duration="30" currency="USD">-500</valueChange>


                <valuationRange>
                        <low currency="USD">609025</low>
                        <high currency="USD">816810</high>
                </valuationRange>
                <percentile>0</percentile>
        </zestimate>
        <localRealEstate>

        </localRealEstate>

                        </result>

                </results>          
          </response>

      </SearchResults:searchresults>
      <!-- H:120  T:54ms  S:1349  R:Mon Feb 07 10:28:16 PST 2011  B:3.0.103279.20110203.123920-comp_rel_b -->
    http_version: "1.1"
- !ruby/struct:VCR::HTTPInteraction 
  request: !ruby/struct:VCR::Request 
    method: :get
    uri: http://maps.googleapis.com:80/maps/api/elevation/json?locations=0.0,0.0&sensor=false
    body: 
    headers: 
      user-agent: 
      - WWW-Mechanize/1.0.0 (http://rubyforge.org/projects/mechanize/)
      connection: 
      - keep-alive
      keep-alive: 
      - "300"
      accept-encoding: 
      - gzip,identity
      accept-language: 
      - en-us,en;q=0.5
      host: 
      - maps.googleapis.com
      accept-charset: 
      - ISO-8859-1,utf-8;q=0.7,*;q=0.7
  response: !ruby/struct:VCR::Response 
    status: !ruby/struct:VCR::ResponseStatus 
      code: 200
      message: OK
    headers: 
      content-type: 
      - application/json; charset=UTF-8
      date: 
      - Mon, 07 Feb 2011 18:28:17 GMT
      expires: 
      - Tue, 08 Feb 2011 18:28:17 GMT
      cache-control: 
      - public, max-age=86400
      server: 
      - mafe
      x-xss-protection: 
      - 1; mode=block
      transfer-encoding: 
      - chunked
    body: |
      {
        "status": "OK",
        "results": [ {
          "location": {
            "lat": 0.0000000,
            "lng": 0.0000000
          },
          "elevation": -5002.7587891
        } ]
      }

    http_version: "1.1"

Cassettes not used during background steps

I haven't dug deeply into this yet, when I tag a feature or scenario to be recorded in Cucumber, any steps in a Background block still hit the FakeWeb::NetConnectNotAllowed error. Moving them into the scenario enables them to be recorded.

callbacks on associated objects

I have a before_create hook that calls out to sync with a remote server. VCR throws an error since it seems to only record local object callbacks.

Example:
If I have a Factory(:subscription) which has an associated subscription.product = Factory(:product) and the Product factory has a before_create hook then VCR will complain that its hitting an unregistered request.

To trigger this I am simply doing subject { Factory(:subscription) }

xmlrpc client: "Wrong size. Was x, should be y"

I am working with a client that uses xmlrpc/client.

I am able to save the fixture off, the fixtures content-length header appears to be correct at 2689, however the body does not appear to match, which causes the following error in xmlrpc/client.

Wrong size. Was 2680, should be 2689

Digging into ruby 1.9.2 xmlrpc/client expected is correct on line 561, however, the data.size is not correct, which looks to be come out of the fixtures body.

The saved fixture is here:

http://gist.github.com/660216

Here is a basic spec to display the error if you use the fixture listed above:

http://gist.github.com/660244

Let me know if you have any questions.

v1.3.1 breaks unless stub_with is set explicitly

I had been running v1.2.0, and things worked fine. This came up after installing 1.3.1.

When I set up VCR like this:

VCR.config do |c|
  c.cassette_library_dir = File.join(Rails.root, 'features', 'fixtures', 'vcr_cassettes')
  c.ignore_localhost = true
  c.default_cassette_options = { :record => :new_episodes }
end

I get this error:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include? (NoMethodError)
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/vcr-1.3.1/lib/vcr.rb:59:in `block in http_stubbing_adapter'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/vcr-1.3.1/lib/vcr.rb:59:in `each'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/vcr-1.3.1/lib/vcr.rb:59:in `all?'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/vcr-1.3.1/lib/vcr.rb:59:in `http_stubbing_adapter'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/vcr-1.3.1/lib/vcr/config.rb:25:in `ignore_localhost='
/home/ben/projects/dgnetwork/features/support/vcr.rb:5:in `block in <top (required)>'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/vcr-1.3.1/lib/vcr.rb:46:in `config'
/home/ben/projects/dgnetwork/features/support/vcr.rb:3:in `<top (required)>'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in `load'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in `block in load'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:227:in `load_dependency'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in `load'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/cucumber-0.9.4/lib/cucumber/rb_support/rb_language.rb:143:in `load_code_file'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/cucumber-0.9.4/lib/cucumber/runtime/support_code.rb:176:in `load_file'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/cucumber-0.9.4/lib/cucumber/runtime/support_code.rb:78:in `block in load_files!'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/cucumber-0.9.4/lib/cucumber/runtime/support_code.rb:77:in `each'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/cucumber-0.9.4/lib/cucumber/runtime/support_code.rb:77:in `load_files!'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/cucumber-0.9.4/lib/cucumber/runtime.rb:137:in `load_step_definitions'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/cucumber-0.9.4/lib/cucumber/runtime.rb:39:in `run!'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/cucumber-0.9.4/lib/cucumber/cli/main.rb:48:in `execute!'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/cucumber-0.9.4/lib/cucumber/cli/main.rb:21:in `execute'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/gems/cucumber-0.9.4/bin/cucumber:8:in `<top (required)>'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/bin/cucumber:19:in `load'
/home/ben/projects/dgnetwork/.bundle/ruby/1.9.1/bin/cucumber:19:in `<main>'

When I set stub_with explicity, it works fine:

VCR.config do |c|
  c.cassette_library_dir = File.join(Rails.root, 'features', 'fixtures', 'vcr_cassettes')
  c.stub_with :fakeweb
  c.ignore_localhost = true
  c.default_cassette_options = { :record => :new_episodes }
end

VCR doesn't seem to work in spec/requests (rspec integration tests)

I've been using VCR to great effect in my code, but it does not appear to work on specs in the spec/requests folder. I know mocking in an integration test is not necessarily what you want to do, but I need to mock out 3rd party web services that either fail intermittently (Facebook), or throttle my usage (Amazon). Any thoughts on what's going on here?
Thanks Myron.
Jeff

VCR.use_exclusive_cassette method

Per our discussion, the behavior would be:

  • Save and remove all stubs for the current cassette
  • Push the new cassette on the stack
  • At the end of the block, pop the new cassette off and restore all the saved stubs

Arrays in headers for fake Typhoeus responses

Ran into this today... Given a request where the real Typhoeus response has a header {"Content-Type" => "text/html"}, the VCR version that comes back is {"Content-Type" => ["text/html"]}.

allocator undefined for Proc

Hi,

I got this error "allocator undefined for Proc" after once VSR is recorded, I make an http request via Mechanize. Here the vcr yml header:

--- 
- !ruby/struct:VCR::RecordedResponse 
  method: :get
  uri: ...
  response: !ruby/object:Net::HTTPOK 
    body: !ruby/object:Net::ReadAdapter 
      block: !ruby/object:Proc {}
...

Thanks for this gem, even if it isn't working for me ;-)

Random hang ups when using Capybara+Webdriver

Hi guys,

I am experiencing random hangs of Capybara/Webdriver when used with VCR. It happens when filling forms, clicking links, etc. I get "Timeout error" for example when trying to fill in login form.

This happens randomly, but very often in my app. When VCR is not used -- everything works.

I have tried 1.2.0 and most recent 1.3.x versions and the results are the same.

Only replay a given transaction once by default

Per our discussion: Given a the same request is made twice, and there is a single matching response in the cassette, the first request plays back the response, and the second request triggers an exception. Make the current behavior a non-default option.

to_yaml failing in cassette.rb, write_recorded_interactions_to_disk, vcr 1.6.0, ruby 1.9.2p136

I haven't changed anything in my tests that use vcr, but all of the sudden they started generating errors.

I'm getting the following:

test_cancel_recurring_profile(ProfileTest):
ArgumentError: wrong number of arguments(1 for 0)
/usr/local/Cellar/ruby/1.9.2-p136/lib/ruby/gems/1.9.1/gems/vcr-1.6.0/lib/vcr/cassette.rb:155:in `block in write_recorded_interactions_to_disk'
/usr/local/Cellar/ruby/1.9.2-p136/lib/ruby/gems/1.9.1/gems/vcr-1.6.0/lib/vcr/cassette.rb:155:in `open'
/usr/local/Cellar/ruby/1.9.2-p136/lib/ruby/gems/1.9.1/gems/vcr-1.6.0/lib/vcr/cassette.rb:155:in `write_recorded_interactions_to_disk'
/usr/local/Cellar/ruby/1.9.2-p136/lib/ruby/gems/1.9.1/gems/vcr-1.6.0/lib/vcr/cassette.rb:38:in `eject'
/usr/local/Cellar/ruby/1.9.2-p136/lib/ruby/gems/1.9.1/gems/vcr-1.6.0/lib/vcr.rb:58:in `eject_cassette'
/usr/local/Cellar/ruby/1.9.2-p136/lib/ruby/gems/1.9.1/gems/vcr-1.6.0/lib/vcr.rb:69:in `use_cassette'
test/unit/profile_test.rb:41:in `block in <class:ProfileTest>'
/usr/local/Cellar/ruby/1.9.2-p136/lib/ruby/gems/1.9.1/gems/activesupport-3.0.4/lib/active_support/testing/setup_and_teardown.rb:35:in `block in run'
/usr/local/Cellar/ruby/1.9.2-p136/lib/ruby/gems/1.9.1/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:423:in `_run_setup_callbacks'
/usr/local/Cellar/ruby/1.9.2-p136/lib/ruby/gems/1.9.1/gems/activesupport-3.0.4/lib/active_support/testing/setup_and_teardown.rb:34:in `run'

I added some debugging to cassette.rb and everything looks fine until to_yaml is called on the interactions array, at which point it dies...

Let me know if you need any other information to fix this.

Thanks!

Yaml [BUG] Segmentation fault

Hi Myron,

Since we use VCR (1.0, with webmock) we sometimes got this scary error:

/Users/Thibaud/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/yaml.rb:133: [BUG] Segmentation fault

ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-darwin10.4.0], MBARI 0x6770, Ruby Enterprise Edition 2010.02

We have a lot of external API call inside your app (~40 yml files). Maybe you have already got this error and have an idea to how fix it.

Thanks,
Thibaud

Option to ignore some parameters in an URI?

I started using VCR here to stub calls to the Amazon Product Advertising API and have a minor issue: The parameters in each call include a unique timestamp, making it impossible to stub based on the URI.

Currently my workaround is to create a unique cassette for each request. (This is what it looks like.) It would definitely be more elegant to tell VCR to ignore certain parameters. Perhaps another option like:

:filter_parameters => ['Timestamp', 'Signature']

If you like the idea, I can have a stab at this.

Recording with AWS-S3 (YAML segfaults)

(on the latest version of VCR and Webmock)

We're using Paperclip's built-in S3 support to store files and query for file existence. We sometimes see a segfault as described in Issue #4 - (https://github.com/myronmarston/vcr/issues/closed#issue/4.

We're wondering if it's because of the many YAML references in the cassettes generated from S3 traffic?

Thanks!

- !ruby/struct:VCR::HTTPInteraction 
  request: !ruby/struct:VCR::Request 
    method: :delete
    uri: !ruby/regexp /.*amazonaws\.com.*\/str_paperclip_testing\/videos\/\d+\/thumbnails\/image.jpg/
    body: 
    headers: 
      user-agent: 
      - AWS::S3/0.6.2
      authorization: 
      - &id002 !str:AWS::S3::Authentication::Header 
          "@request": &id001 !ruby/object:Net::HTTP::Delete 
            body: 
            body_stream: 
            header: 
              - binary/octet-stream
              authorization: 
              - *id002
              date: 
        "@request": *id001
      content-length: 
      - "0"
      host: 
      - s3.amazonaws.com

Configuration option to easily filter sensitive data from cassettes

Quoting from what nbibler wrote on the hooks pull request:

In the majority of my own use cases, these filters would be to strip sensitive information from the YAML files - even though I usually use staging/test/demo accounts in test mode I still dislike having that information in a repository. So, while what's here works, it'd be even better to have a new shortcut (in addition to the current hooks) for the before_record and mirrored before_playback calls. Maybe similar to the Rails filter_parameters configuration.

    VCR.config do |c|
      c.filter_parameters({
        :account_url => Freskbooks::Base.connection.account_url,
        :auth_token => Freshbooks::Base.connection.auth_token,
      })
    end

Could be short for:

    VCR.config do |c|
      c.before_record do |interactions|
        interactions.each do |i|
          i.uri.
          sub!(FreshBooks::Base.connection.account_url, '%{ACCOUNT_URL}').
          sub!(FreshBooks::Base.connection.auth_token, '%{AUTH_TOKEN}')

          i.body.
          sub!(FreshBooks::Base.connection.account_url, '%{ACCOUNT_URL}').
          sub!(FreshBooks::Base.connection.auth_token, '%{AUTH_TOKEN}')
        end
      end
      c.before_playback(:freshbooks) do |interactions|
        interactions.each do |i|
          i.uri.
            sub!('%{ACCOUNT_URL}', FreshBooks::Base.connection.account_url).
            sub!('%{AUTH_TOKEN}', FreshBooks::Base.connection.auth_token)

          i.body.
            sub!('%{ACCOUNT_URL}', FreshBooks::Base.connection.account_url).
            sub!('%{AUTH_TOKEN}', FreshBooks::Base.connection.auth_token)
    end

And, with a helper like that, it should filter every bit of the request/response, including the URI (basic auth credentials) and body (SOAP). It seems like it's going to get REALLY annoying to constantly write the encoding/decoding hooks over and over and over, especially when they're just mirrors of each other.

Certainly, this helper doesn't work well for dynamic requests that are based on Factory-built model information and identifiers (and dynamic passwords), but for stubbing external systems that require credentials (almost every one of them).. it seems like a useful shorthand to me.

Error when using with mechanize: NoMethodError: private method `split' called for #<Array

First run with :record => :new_episodes passes.... second and all further runs give the error below.

I added the failing test and fixture data to an open source project of mine... I was running into this on a closed source project originally but this is an open example causing the same error. This commit has the fixture and the failing VCR test:
http://github.com/danmayer/ruby-fitbit/commit/d48d55653e8c7d3e1bb454203516b274ac8d3d46

Run data
dan-mayers-macbook:ruby-fitbit danmayer$ rake test
(in /Users/danmayer/projects/ruby-fitbit)
/Library/Ruby/Gems/1.8/gems/jeweler-1.4.0/lib/jeweler/commands/check_dependencies.rb:13:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement
All dependencies seem to be installed.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"lib:lib:test" "/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/test_ruby-fitbit.rb"
Loaded suite /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
...
Finished in 4.707632 seconds.

3 tests, 10 assertions, 0 failures, 0 errors
dan-mayers-macbook:ruby-fitbit danmayer$ rake test
(in /Users/danmayer/projects/ruby-fitbit)
/Library/Ruby/Gems/1.8/gems/jeweler-1.4.0/lib/jeweler/commands/check_dependencies.rb:13:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement
All dependencies seem to be installed.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"lib:lib:test" "/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/test_ruby-fitbit.rb"
Loaded suite /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
..E
Finished in 0.109018 seconds.

  1. Error:
    test: RubyFitbit should use VCR successfully. (TestRubyFitbit):
    NoMethodError: private method split' called for #<Array:0x10231dc08> /Library/Ruby/Gems/1.8/gems/mechanize-0.9.3/lib/www/mechanize/cookie.rb:9:inparse'
    /Library/Ruby/Gems/1.8/gems/mechanize-0.9.3/lib/www/mechanize/chain/response_header_handler.rb:40:in handle' /Library/Ruby/Gems/1.8/gems/mechanize-0.9.3/lib/www/mechanize/chain/response_header_handler.rb:39:ineach'
    /Library/Ruby/Gems/1.8/gems/mechanize-0.9.3/lib/www/mechanize/chain/response_header_handler.rb:39:in handle' /Library/Ruby/Gems/1.8/gems/mechanize-0.9.3/lib/www/mechanize/chain.rb:30:inpass'
    /Library/Ruby/Gems/1.8/gems/mechanize-0.9.3/lib/www/mechanize/chain/handler.rb:6:in handle' /Library/Ruby/Gems/1.8/gems/mechanize-0.9.3/lib/www/mechanize/chain/response_body_parser.rb:35:inhandle'
    /Library/Ruby/Gems/1.8/gems/mechanize-0.9.3/lib/www/mechanize/chain.rb:30:in pass' /Library/Ruby/Gems/1.8/gems/mechanize-0.9.3/lib/www/mechanize/chain/handler.rb:6:inhandle'
    /Library/Ruby/Gems/1.8/gems/mechanize-0.9.3/lib/www/mechanize/chain/pre_connect_hook.rb:14:in handle' /Library/Ruby/Gems/1.8/gems/mechanize-0.9.3/lib/www/mechanize/chain.rb:25:inhandle'
    /Library/Ruby/Gems/1.8/gems/mechanize-0.9.3/lib/www/mechanize.rb:507:in fetch_page' /Library/Ruby/Gems/1.8/gems/mechanize-0.9.3/lib/www/mechanize.rb:413:inpost_form'
    /Library/Ruby/Gems/1.8/gems/mechanize-0.9.3/lib/www/mechanize.rb:344:in submit' /Users/danmayer/projects/ruby-fitbit/test/../lib/ruby-fitbit.rb:30:inlogin'
    /Users/danmayer/projects/ruby-fitbit/test/../lib/ruby-fitbit.rb:41:in get_data' /Users/danmayer/projects/ruby-fitbit/test/../lib/ruby-fitbit.rb:18:ininitialize'
    ./test/test_ruby-fitbit.rb:88:in new' ./test/test_ruby-fitbit.rb:88:in**bind_1280715668_772158'
    /Library/Ruby/Gems/1.8/gems/vcr-1.0.2/lib/vcr.rb:37:in use_cassette' ./test/test_ruby-fitbit.rb:87:in__bind_1280715668_772158'
    /Library/Ruby/Gems/1.8/gems/shoulda-2.11.1/lib/shoulda/context.rb:382:in call' /Library/Ruby/Gems/1.8/gems/shoulda-2.11.1/lib/shoulda/context.rb:382:intest: RubyFitbit should use VCR successfully. '
    /Library/Ruby/Gems/1.8/gems/mocha-0.9.8/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:19:in __send**' /Library/Ruby/Gems/1.8/gems/mocha-0.9.8/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:19:in run'

3 tests, 9 assertions, 0 failures, 1 errors
rake aborted!
Command failed with status (1): [/System/Library/Frameworks/Ruby.framework/...]

(See full trace by running task with --trace)

Rspec Group Macros

Would be really cool if Rspec has a simple helper on the group blocks to provide an insert/eject functionality for vcr

describe "#create" do
  wrap_cassette("billing/create", opts)
end

Get recording to work when Net::HTTP#request is called with a block with a return

When a request is made with a block that has a return statement, no recording is done. The return in a block returns from the method that defines the block. It acts a bit like a magic goto, and as a result the recording gets skipped.

This is preventing me from being able to record http interactions from rack-client. See rack-client's code here.

execution expired with Selenium

I'm getting the behaviour described at the following stackoverflow question with both Webmock and Fakeweb backends:

http://stackoverflow.com/questions/4115714/timeouterror-with-selenium-capybara-cucumber

Removing VCR and its config fixes the issue. Can VCR be more thoroughly disabled for a particular scenario?

Lovely backtrace snippet:

When I try to check out                                                     # features/step_definitions/checkout_steps.rb:63
And I sign up with email: "[email protected]"                           # features/step_definitions/login_steps.rb:26
  execution expired (Timeout::Error)
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/timeout.rb:64:in `rbuf_fill'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/protocol.rb:126:in `readline'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:2028:in `read_status_line'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:2017:in `read_new'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:543:in `start'
  ./features/step_definitions/login_steps.rb:31:in `/^I sign up with email: "([^"]*)"$/'
  /Users/andrew/dev/superhug/features/checkout_designs_with_javascript.feature:17:in `And I sign up with email: "[email protected]"'

Requesting :no_tape option for record mode

Would be awesome to have a :no_tape mode which would disable any HTTP stubbing etc. This helps in debugging or when your just trying to get a test to pass, then when you know its green to add :new_episode back in there. Things like that.

Add ability to selectively ignore localhost ports

As a developer on a project using e.g. Solr and Celerity
I want to select certain ports to record and playback
So that I can use Celerity for JavaScript testing

This means extending the ignore_localhost config option to allow certain ports to be 'true' (not record / playback) and others 'false' (record / playback).

VCR Cassettes inside test/fixtures on Rails 3

Placing VCR Cassetttes inside test/fixtures on a Rails 3 beta 4 app resulted in the following exception for me:

Fixture::FormatError: Bad data for VcrCassettes::Rubygem fixture named XYZ (+ the whole YAML dump)

By default, Rails 3 is configured to load all fixtures in tests (fixtures :all) inside test helper. This can be difficuilt to track down because of the confusing error message.

The issue can be fixed by:
* Moving the vcr fixtures outside of rails fixtures (using the corresponding vcr config method)
* Comment the fixtures :all line in test_helper (when using a fixture replacement like factory_girl)

I guess a lot of people might potentially bump into this, so it might make sense to point the issue and the exception out in the README for vcr

Headers are recorded inconsistently

When using Net::HTTP, headers get recorded as a hash, with arrays for values (i.e. to handle multiple values for the same header key). For patron, httpclient, and em-http, headers get recorded as a hash, with single values.

This should be normalized so that the same thing is recorded regardless of which http library is used.

Cassettes don't port between ruby-1.8 and ruby-1.9?

I wrote a bunch of cassettes in ruby-1.8.7 and am finding that they're failing in ruby-1.9.1:

ArgumentError: wrong number of arguments(0 for 1)
/Users/dball/.rvm/gems/ruby-1.9.1-p378/gems/vcr-1.0.3/lib/vcr/http_stubbing_adapters/fakeweb.rb:26:in method' /Users/dball/.rvm/gems/ruby-1.9.1-p378/gems/vcr-1.0.3/lib/vcr/http_stubbing_adapters/fakeweb.rb:26:inblock in stub_requests'
/Users/dball/.rvm/gems/ruby-1.9.1-p378/gems/vcr-1.0.3/lib/vcr/http_stubbing_adapters/fakeweb.rb:25:in each' /Users/dball/.rvm/gems/ruby-1.9.1-p378/gems/vcr-1.0.3/lib/vcr/http_stubbing_adapters/fakeweb.rb:25:instub_requests'
/Users/dball/.rvm/gems/ruby-1.9.1-p378/gems/vcr-1.0.3/lib/vcr/cassette.rb:102:in load_recorded_interactions' /Users/dball/.rvm/gems/ruby-1.9.1-p378/gems/vcr-1.0.3/lib/vcr/cassette.rb:24:ininitialize'
/Users/dball/.rvm/gems/ruby-1.9.1-p378/gems/vcr-1.0.3/lib/vcr.rb:22:in new' /Users/dball/.rvm/gems/ruby-1.9.1-p378/gems/vcr-1.0.3/lib/vcr.rb:22:ininsert_cassette'

Has anyone else run into this?

Get VCR working with Savon?

I have created a test case that demonstrates the issue. The first test passes using raw httpclient. The 2nd test fails... no cassette is created.

https://gist.github.com/799132

Any ideas on what's wrong? Happy to contribute a fix, just not sure where the issue lies.

Use VCR selectively

I am noticing that when i require vcr, even if i do not use it in my code, it complains whenever i try to make an http request. Though i wish my entire cucumber suite already did use vcr, some of our tests unfortunately do call out to the web. Would like to eventually refactor those, but for now, would like to use vcr on new tests, without breaking some of our existing.

thx.

-karl

Empty casset file causes TypeError

Had a look at reproducing this error in a spec, but I think i need a bit of help. I noticed this happening when somehow i had an empty cassette file. Maybe due to a ctrl-c in a previous test run?

 can't convert false into Array (TypeError)
 /Users/karl/.rvm/gems/ruby-1.9.2-p0@email-sync/gems/vcr-1.4.0/lib/vcr/cassette.rb:112:in `replace'
 /Users/karl/.rvm/gems/ruby-1.9.2-p0@email-sync/gems/vcr-1.4.0/lib/vcr/cassette.rb:112:in `load_recorded_interactions'
 /Users/karl/.rvm/gems/ruby-1.9.2-p0@email-sync/gems/vcr-1.4.0/lib/vcr/cassette.rb:33:in `initialize'
 /Users/karl/.rvm/gems/ruby-1.9.2-p0@email-sync/gems/vcr-1.4.0/lib/vcr.rb:38:in `new'
 /Users/karl/.rvm/gems/ruby-1.9.2-p0@email-sync/gems/vcr-1.4.0/lib/vcr.rb:38:in `insert_cassette'
 /Users/karl/.rvm/gems/ruby-1.9.2-p0@email-sync/gems/vcr-1.4.0/lib/vcr.rb:50:in `use_cassette'
 /Users/karl/.rvm/gems/ruby-1.9.2-p0@email-sync/gems/vcr-1.4.0/lib/vcr/cucumber_tags.rb:25:in `block (2 levels) in tags'

Btw.. i cannot believe how well your library is tested. Example to everyone else!

match_requests_on doesn't work with Net::HTTP when matching on headers

There is a problem with matching on headers when using Net::HTTP.
VCR's Net::HTTP adapter is recording request headers AFTER the real request is made.
Net::HTTP adds 'host' and 'content-type' headers to the request during the real request and these
are the headers recorded and expected when matching requests on headers later.
WebMock creates request signature before the real request is made (obviously), and the signature
doesn't include these headers so the signature comparison fails.

Here is the failing spec:

http://github.com/bblimke/vcr/commit/8cce783f01bd2c4d898c735212c976e0e27d7bcd

VCR fails when matching requests with XML bodies

Hello,
I'm having problems with put requests sending XML bodies to the API. The XML serializer used by ActiveResource sometimes switches the order of the elements in the XML document, and since VCR is using a simple string comparison when matching request bodies with recorded cassettes (https://github.com/myronmarston/vcr/blob/master/lib/vcr/request_matcher.rb#L64) VCR fails to recognize this as a recorded interaction. A proper XML comparison would fix the issue.

I haven't found anyone else reporting this issue. Do you have any tips about it?

before_write and after_read hooks

When I'm recording interactions for the first time I use my real login credentials so that I get valid responses from an api. Obviously I don't want my details in my git repo so after I've recorded the interaction I then go and swap them out in the recorded files for some dummy values and update the test to match. This is a bit of a pain after a while, what I had in mind was something like this:

VCR.config do |c|
    c.before_write do |recording|
        recording.gsub(ENV['GITHUB_TOKEN'], '__github_token__')
    end
    c.after_read do |recording|
        recording.gsub('__github_token__', ENV['GITHUB_TOKEN'])
    end
end

So when recordings are stored they have the real github token swapped out and vica versa the real one swapped in when playing them back. My tests then also use the ENV value so that I can easily run queries against an api and not worry about my credentials being stored anywhere they shouldn't be.

Swapping out the values could be a feature in it's own right but it seems to make more sense to implement the hooks.

Can webmock and fakeweb play nicely together?

We have a largish test suite which relies on manual fakeweb for the most part. I want to use vcr's new request body matching capability which you kindly included in the latest release, so have configured vcr to use webmock. Unfortunately, after the test cases using vcr have run, all the subsequent test cases which want to rely on fakeweb no longer work, raising errors:

WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: POST --URL-- with body --BODY-- with headers {'Accept'=>'/', 'Content-Type'=>'text/xml;charset=UTF-8'}. You can use VCR to automatically record this request and replay it later. For more details, see the VCR README at: http://github.com/myronmarston/vcr/tree/v1.0.3
webmock (1.3.4) lib/webmock/http_lib_adapters/net_http.rb:79:in request_without_vcr' vcr (1.0.3) lib/vcr/extensions/net_http.rb:16:inrequest'

I've tried a few things in the teardown for the vcr unit tests:

def teardown
VCR.eject_cassette
VCR.config do |c|
c.http_stubbing_library = :fakeweb
end
WebMock.allow_net_connect!
end

Nothing I've tried yet corrects the problem. I'm wondering if this is a case you've encountered and for which you might have a suggestion? I've considered forcibly unaliasing the net http stubs, but that would cause problems for any other unit tests which might want to use vcr.

Migrate documentation from README to Wiki

The README is getting large and unwieldy. I think the wiki will be a better way to document VCR's features and usage.

If you're a VCR user, feel free to help out with this effort. I don't know when I'm going to have time to work on it.

Provide a way to automatically re-record requests

Both stale_fish and ephemeral_response provide a way to automatically re-record requests based on some kind of time-based expiration.

It would be nice if VCR provided this feature, too. Maybe something like this:

VCR.use_cassette('some_cassette', :re_record_after => 30.days) { }

You could set a project-wide default by setting the default_cassette_options.

I'm not sure I'm totally happy with this API for it, though--it'd be nice to combine it somehow with the :record option, but I'm not sure how. Anyone got a suggestion for how this should work?

Match failure upon playback

I've observed VCR/webmock raising an error:

WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: GET https://myaccount.sdge.com/security/signin.fcc?<LONG_STRING>

... even though the corresponding cassette file has a URI entry of

uri: https://myaccount.sdge.com:443/security/signin.fcc?<LONG_STRING>

A minimal test and companion cassette are in git://gist.github.com/908795.git (hey, why didn't GitHub flavored markdown autolink that??)

TypeError: can't convert Fixnum into String

Hey,

I am using vcr and fakeweb to test some Google Data Calendar API integration (with gem oauth), and I keep receiving a TypeError: can't convert Fixnum into String happening in vcr-1.5.1/lib/vcr/structs.rb:69 (with some put and post HTTP methods).

There is a String.new(v) there, but when v == 1, for example (as a Fixnum), the statement String.new(1) raises that TypeError.

In order to fix that, I sugest changing String(v) to v.to_s. That solved my problem -- since this is a simple modification, the patch is here:

*** lib/vcr/structs.rb  2011-01-26 18:18:00.000000000 -0200
--- lib/vcr/structs.rb  2011-01-26 18:18:01.000000000 -0200
***************
*** 66,72 ****
          # get serialized with some extra stuff which leads
          # to a seg fault. See this issue for more info:
          # https://github.com/myronmarston/vcr/issues#issue/39
!         string_vals = important_vals.map { |v| String.new(v) }
  
          new_headers[k] = string_vals
        end if headers
--- 66,72 ----
          # get serialized with some extra stuff which leads
          # to a seg fault. See this issue for more info:
          # https://github.com/myronmarston/vcr/issues#issue/39
!         string_vals = important_vals.map { |v| v.to_s }
  
          new_headers[k] = string_vals
        end if headers

Thanks a lot for vcr!

Typhoeus support is limited to Typhoeus::Hydra only

I was trying to add Typhoeus support to WebMock and I discovered that
Typhoeus internal stubbing only works only for Typhoeus::Hydra.
This means that Typhoeus::Easy and Typhoeus::Multi are not supported.

Changes in VCR 1.1.2 conflict with webmock

The following code throws : Net::HTTPOK#read_body called twice (IOError)

require 'rubygems'
require 'vcr'
require 'open-uri'

VCR.config do |c|
  c.cassette_library_dir = 'test/fakeweb'
  c.http_stubbing_library = :webmock
end

WebMock.allow_net_connect!
url = 'http://www.wp.pl'
open(url)

VCR not playing nice with Selenium (and Capybara)

When I put a cassette tag on a Cucumber featured tagged with @javascript (causing Capybara to use the Selenium driver), strange things start happening...

The first time I run it, everything happens as expected: the cassette records, the data is used, and everything passes.

The next time I run it (off the cassette), it fails with Unregistered request: GET http://localhost:9887/**identify**.

It seems that Selenium needs to talk to its server using that port (pinging it to see if it exists, in this instance). I'm not precisely just sure how VCR is messing that up, but it is.

It would probably be useful to allow localhost requests through (either configurable or by an @allow_localhost tag, or both).

Add ability to log all HTTP requests in a development environment

VCR is intended primarily for use in a test environment, but some people have mentioned that they would like to use it in a development environment to log all HTTP requests in VCR's YAML format. This is possible, but it's a bit tricky to setup. It'd be nice to have an officially supported way to do this. Maybe something like this in a rails app:

# config/initializers/vcr.rb
if Rails.environment.development?
  require 'vcr'
  VCR.log_all_http_interactions_to(file_name)
end

Have VCR warn or fail when a cassette isn't found

I ran into an issue where my tests were failing in ruby-1.9 because the method I had been using to generate the cassette names was no longer valid. It would be cool if vcr would warn users that a cassette wasn't found.

can't dup NilClass (TypeError) when creating stubs checkpoint

Any idea about this? I get it with both FakeWeb and Webmock backends.

  /Users/andrew/dev/jruby-1.5.6/lib/ruby/gems/1.8/gems/vcr-1.4.0/lib/vcr/http_stubbing_adapters/webmock.rb:40:in `create_stubs_checkpoint'
  /Users/andrew/dev/jruby-1.5.6/lib/ruby/gems/1.8/gems/vcr-1.4.0/lib/vcr/cassette.rb:100:in `load_recorded_interactions'
  /Users/andrew/dev/jruby-1.5.6/lib/ruby/gems/1.8/gems/vcr-1.4.0/lib/vcr/cassette.rb:33:in `initialize'
  /Users/andrew/dev/jruby-1.5.6/lib/ruby/gems/1.8/gems/vcr-1.4.0/lib/vcr.rb:38:in `new'
  /Users/andrew/dev/jruby-1.5.6/lib/ruby/gems/1.8/gems/vcr-1.4.0/lib/vcr.rb:38:in `insert_cassette'
  /Users/andrew/dev/jruby-1.5.6/lib/ruby/gems/1.8/gems/vcr-1.4.0/lib/vcr.rb:50:in `use_cassette'

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.