vcr 3.0.3 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vcr.rb +18 -1
- data/lib/vcr/cassette.rb +11 -3
- data/lib/vcr/cassette/persisters/file_system.rb +1 -1
- data/lib/vcr/configuration.rb +3 -5
- data/lib/vcr/deprecations.rb +0 -62
- data/lib/vcr/errors.rb +16 -0
- data/lib/vcr/library_hooks/typhoeus.rb +37 -8
- data/lib/vcr/middleware/faraday.rb +5 -1
- data/lib/vcr/structs.rb +1 -1
- data/lib/vcr/util/hooks.rb +1 -0
- data/lib/vcr/version.rb +1 -1
- metadata +9 -249
- data/features/CHANGELOG.md +0 -710
- data/features/CONTRIBUTING.md +0 -26
- data/features/LICENSE.md +0 -20
- data/features/README.md +0 -339
- data/features/Upgrade.md +0 -289
- data/features/about_these_examples.md +0 -18
- data/features/cassettes/allow_unused_http_interactions.feature +0 -100
- data/features/cassettes/automatic_re_recording.feature +0 -72
- data/features/cassettes/decompress.feature +0 -74
- data/features/cassettes/dynamic_erb.feature +0 -100
- data/features/cassettes/exclusive.feature +0 -126
- data/features/cassettes/format.feature +0 -411
- data/features/cassettes/freezing_time.feature +0 -68
- data/features/cassettes/naming.feature +0 -28
- data/features/cassettes/no_cassette.feature +0 -152
- data/features/cassettes/update_content_length_header.feature +0 -112
- data/features/configuration/allow_http_connections_when_no_cassette.feature +0 -55
- data/features/configuration/cassette_library_dir.feature +0 -31
- data/features/configuration/debug_logging.feature +0 -58
- data/features/configuration/default_cassette_options.feature +0 -100
- data/features/configuration/filter_sensitive_data.feature +0 -153
- data/features/configuration/hook_into.feature +0 -172
- data/features/configuration/ignore_request.feature +0 -192
- data/features/configuration/preserve_exact_body_bytes.feature +0 -108
- data/features/configuration/query_parser.feature +0 -84
- data/features/configuration/uri_parser.feature +0 -93
- data/features/getting_started.md +0 -82
- data/features/hooks/after_http_request.feature +0 -58
- data/features/hooks/around_http_request.feature +0 -57
- data/features/hooks/before_http_request.feature +0 -63
- data/features/hooks/before_playback.feature +0 -184
- data/features/hooks/before_record.feature +0 -172
- data/features/http_libraries/em_http_request.feature +0 -250
- data/features/http_libraries/net_http.feature +0 -179
- data/features/middleware/faraday.feature +0 -56
- data/features/middleware/rack.feature +0 -92
- data/features/record_modes/all.feature +0 -82
- data/features/record_modes/new_episodes.feature +0 -79
- data/features/record_modes/none.feature +0 -72
- data/features/record_modes/once.feature +0 -95
- data/features/request_matching/README.md +0 -30
- data/features/request_matching/body.feature +0 -91
- data/features/request_matching/body_as_json.feature +0 -90
- data/features/request_matching/custom_matcher.feature +0 -135
- data/features/request_matching/headers.feature +0 -85
- data/features/request_matching/host.feature +0 -95
- data/features/request_matching/identical_request_sequence.feature +0 -89
- data/features/request_matching/method.feature +0 -96
- data/features/request_matching/path.feature +0 -96
- data/features/request_matching/playback_repeats.feature +0 -98
- data/features/request_matching/query.feature +0 -97
- data/features/request_matching/uri.feature +0 -94
- data/features/request_matching/uri_without_param.feature +0 -101
- data/features/step_definitions/cli_steps.rb +0 -199
- data/features/support/env.rb +0 -46
- data/features/support/http_lib_filters.rb +0 -46
- data/features/test_frameworks/cucumber.feature +0 -211
- data/features/test_frameworks/rspec_macro.feature +0 -81
- data/features/test_frameworks/rspec_metadata.feature +0 -150
- data/features/test_frameworks/test_unit.feature +0 -49
- data/lib/vcr/extensions/net_http_response.rb +0 -36
- data/lib/vcr/library_hooks/fakeweb.rb +0 -197
- data/spec/acceptance/concurrency_spec.rb +0 -51
- data/spec/acceptance/threading_spec.rb +0 -34
- data/spec/fixtures/cassette_spec/1_x_cassette.yml +0 -110
- data/spec/fixtures/cassette_spec/empty.yml +0 -0
- data/spec/fixtures/cassette_spec/example.yml +0 -111
- data/spec/fixtures/cassette_spec/with_localhost_requests.yml +0 -111
- data/spec/fixtures/fake_example_responses.yml +0 -110
- data/spec/fixtures/match_requests_on.yml +0 -187
- data/spec/lib/vcr/cassette/erb_renderer_spec.rb +0 -53
- data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +0 -295
- data/spec/lib/vcr/cassette/migrator_spec.rb +0 -196
- data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +0 -75
- data/spec/lib/vcr/cassette/persisters_spec.rb +0 -39
- data/spec/lib/vcr/cassette/serializers_spec.rb +0 -182
- data/spec/lib/vcr/cassette_spec.rb +0 -618
- data/spec/lib/vcr/configuration_spec.rb +0 -326
- data/spec/lib/vcr/deprecations_spec.rb +0 -85
- data/spec/lib/vcr/errors_spec.rb +0 -178
- data/spec/lib/vcr/extensions/net_http_response_spec.rb +0 -86
- data/spec/lib/vcr/library_hooks/excon_spec.rb +0 -104
- data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +0 -169
- data/spec/lib/vcr/library_hooks/faraday_spec.rb +0 -68
- data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +0 -36
- data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +0 -162
- data/spec/lib/vcr/library_hooks/webmock_spec.rb +0 -117
- data/spec/lib/vcr/library_hooks_spec.rb +0 -51
- data/spec/lib/vcr/middleware/faraday_spec.rb +0 -181
- data/spec/lib/vcr/middleware/rack_spec.rb +0 -115
- data/spec/lib/vcr/request_ignorer_spec.rb +0 -70
- data/spec/lib/vcr/request_matcher_registry_spec.rb +0 -345
- data/spec/lib/vcr/structs_spec.rb +0 -732
- data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +0 -107
- data/spec/lib/vcr/test_frameworks/rspec_spec.rb +0 -94
- data/spec/lib/vcr/util/hooks_spec.rb +0 -158
- data/spec/lib/vcr/util/internet_connection_spec.rb +0 -37
- data/spec/lib/vcr/util/version_checker_spec.rb +0 -31
- data/spec/lib/vcr/version_spec.rb +0 -27
- data/spec/lib/vcr_spec.rb +0 -354
- data/spec/monkey_patches.rb +0 -186
- data/spec/spec_helper.rb +0 -63
- data/spec/support/configuration_stubbing.rb +0 -8
- data/spec/support/cucumber_helpers.rb +0 -39
- data/spec/support/fixnum_extension.rb +0 -10
- data/spec/support/http_library_adapters.rb +0 -289
- data/spec/support/limited_uri.rb +0 -21
- data/spec/support/ruby_interpreter.rb +0 -7
- data/spec/support/shared_example_groups/excon.rb +0 -63
- data/spec/support/shared_example_groups/hook_into_http_library.rb +0 -594
- data/spec/support/shared_example_groups/request_hooks.rb +0 -59
- data/spec/support/sinatra_app.rb +0 -86
- data/spec/support/vcr_localhost_server.rb +0 -76
- data/spec/support/vcr_stub_helpers.rb +0 -17
| @@ -1,59 +0,0 @@ | |
| 1 | 
            -
            shared_examples_for "request hooks" do |library_hook_name, request_type|
         | 
| 2 | 
            -
              let(:request_url) { "http://localhost:#{VCR::SinatraApp.port}/foo" }
         | 
| 3 | 
            -
             | 
| 4 | 
            -
              def make_request(disabled = false)
         | 
| 5 | 
            -
                make_http_request(:get, request_url)
         | 
| 6 | 
            -
              end
         | 
| 7 | 
            -
             | 
| 8 | 
            -
              def assert_expected_response(response)
         | 
| 9 | 
            -
                expect(response.status.code).to eq(200)
         | 
| 10 | 
            -
                expect(response.body).to eq('FOO!')
         | 
| 11 | 
            -
              end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
              [:before_http_request, :after_http_request].each do |hook|
         | 
| 14 | 
            -
                specify "the #{hook} hook is only called once per request" do
         | 
| 15 | 
            -
                  call_count = 0
         | 
| 16 | 
            -
                  VCR.configuration.send(hook) { |r| call_count += 1 }
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                  make_request
         | 
| 19 | 
            -
                  expect(call_count).to eq(1)
         | 
| 20 | 
            -
                end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                specify "the #{hook} hook yields the request" do
         | 
| 23 | 
            -
                  request = nil
         | 
| 24 | 
            -
                  VCR.configuration.send(hook) { |r| request = r }
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                  make_request
         | 
| 27 | 
            -
                  expect(request.method).to be(:get)
         | 
| 28 | 
            -
                  expect(request.uri).to eq(request_url)
         | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                specify "the #{hook} hook is not called if the library hook is disabled" do
         | 
| 32 | 
            -
                  expect(VCR.library_hooks).to respond_to(:disabled?)
         | 
| 33 | 
            -
                  allow(VCR.library_hooks).to receive(:disabled?).and_return(true)
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                  hook_called = false
         | 
| 36 | 
            -
                  VCR.configuration.send(hook) { |r| hook_called = true }
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                  make_request(:disabled)
         | 
| 39 | 
            -
                  expect(hook_called).to be false
         | 
| 40 | 
            -
                end
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                specify "the #type of the yielded request given to the #{hook} hook is #{request_type}" do
         | 
| 43 | 
            -
                  request = nil
         | 
| 44 | 
            -
                  VCR.configuration.send(hook) { |r| request = r }
         | 
| 45 | 
            -
             | 
| 46 | 
            -
                  make_request
         | 
| 47 | 
            -
                  expect(request.type).to be(request_type)
         | 
| 48 | 
            -
                end
         | 
| 49 | 
            -
              end
         | 
| 50 | 
            -
             | 
| 51 | 
            -
              specify "the after_http_request hook yields the response if there is one and the second block arg is given" do
         | 
| 52 | 
            -
                response = nil
         | 
| 53 | 
            -
                VCR.configuration.after_http_request { |req, res| response = res }
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                make_request
         | 
| 56 | 
            -
                assert_expected_response(response)
         | 
| 57 | 
            -
              end
         | 
| 58 | 
            -
            end
         | 
| 59 | 
            -
             | 
    
        data/spec/support/sinatra_app.rb
    DELETED
    
    | @@ -1,86 +0,0 @@ | |
| 1 | 
            -
            require 'sinatra'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module VCR
         | 
| 4 | 
            -
              class SinatraApp < ::Sinatra::Base
         | 
| 5 | 
            -
                disable :protection
         | 
| 6 | 
            -
             | 
| 7 | 
            -
                get '/' do
         | 
| 8 | 
            -
                  "GET to root"
         | 
| 9 | 
            -
                end
         | 
| 10 | 
            -
             | 
| 11 | 
            -
                get '/search' do
         | 
| 12 | 
            -
                  "query: #{params[:q]}"
         | 
| 13 | 
            -
                end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                get '/localhost_test' do
         | 
| 16 | 
            -
                  "Localhost response"
         | 
| 17 | 
            -
                end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
                get '/foo' do
         | 
| 20 | 
            -
                  "FOO!"
         | 
| 21 | 
            -
                end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                get '/redirect-to-root' do
         | 
| 24 | 
            -
                  redirect to('/')
         | 
| 25 | 
            -
                end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                post '/foo' do
         | 
| 28 | 
            -
                  "FOO!"
         | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                post '/return-request-body' do
         | 
| 32 | 
            -
                  request.body
         | 
| 33 | 
            -
                end
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                get '/set-cookie-headers/1' do
         | 
| 36 | 
            -
                  headers 'Set-Cookie' => 'foo'
         | 
| 37 | 
            -
                  'header set'
         | 
| 38 | 
            -
                end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                get '/set-cookie-headers/2' do
         | 
| 41 | 
            -
                  headers 'Set-Cookie' => %w[ bar foo ]
         | 
| 42 | 
            -
                  'header set'
         | 
| 43 | 
            -
                end
         | 
| 44 | 
            -
             | 
| 45 | 
            -
                get '/204' do
         | 
| 46 | 
            -
                  status 204
         | 
| 47 | 
            -
                end
         | 
| 48 | 
            -
             | 
| 49 | 
            -
                get '/404_not_200' do
         | 
| 50 | 
            -
                  status 404
         | 
| 51 | 
            -
                  '404 not 200'
         | 
| 52 | 
            -
                end
         | 
| 53 | 
            -
             | 
| 54 | 
            -
                # we use a global counter so that every response is different;
         | 
| 55 | 
            -
                # this ensures that the test demonstrates that the response
         | 
| 56 | 
            -
                # is being played back (and not running a 2nd real request)
         | 
| 57 | 
            -
                $record_and_playback_response_count ||= 0
         | 
| 58 | 
            -
                get '/record-and-playback' do
         | 
| 59 | 
            -
                  "Response #{$record_and_playback_response_count += 1}"
         | 
| 60 | 
            -
                end
         | 
| 61 | 
            -
             | 
| 62 | 
            -
                post '/record-and-playback' do
         | 
| 63 | 
            -
                  "Response #{$record_and_playback_response_count += 1}"
         | 
| 64 | 
            -
                end
         | 
| 65 | 
            -
             | 
| 66 | 
            -
                @_boot_failed = false
         | 
| 67 | 
            -
             | 
| 68 | 
            -
                class << self
         | 
| 69 | 
            -
                  def port
         | 
| 70 | 
            -
                    server.port
         | 
| 71 | 
            -
                  end
         | 
| 72 | 
            -
             | 
| 73 | 
            -
                  def server
         | 
| 74 | 
            -
                    raise "Sinatra app failed to boot." if @_boot_failed
         | 
| 75 | 
            -
                    @server ||= begin
         | 
| 76 | 
            -
                      VCR::LocalhostServer.new(new)
         | 
| 77 | 
            -
                    rescue
         | 
| 78 | 
            -
                      @_boot_failed = true
         | 
| 79 | 
            -
                      raise
         | 
| 80 | 
            -
                    end
         | 
| 81 | 
            -
                  end
         | 
| 82 | 
            -
             | 
| 83 | 
            -
                  alias boot server
         | 
| 84 | 
            -
                end
         | 
| 85 | 
            -
              end
         | 
| 86 | 
            -
            end
         | 
| @@ -1,76 +0,0 @@ | |
| 1 | 
            -
            require 'rack'
         | 
| 2 | 
            -
            require 'rack/handler/webrick'
         | 
| 3 | 
            -
            require 'net/http'
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            # The code for this is inspired by Capybara's server:
         | 
| 6 | 
            -
            #   http://github.com/jnicklas/capybara/blob/0.3.9/lib/capybara/server.rb
         | 
| 7 | 
            -
            module VCR
         | 
| 8 | 
            -
              class LocalhostServer
         | 
| 9 | 
            -
                READY_MESSAGE = "VCR server ready"
         | 
| 10 | 
            -
             | 
| 11 | 
            -
                class Identify
         | 
| 12 | 
            -
                  def initialize(app)
         | 
| 13 | 
            -
                    @app = app
         | 
| 14 | 
            -
                  end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
                  def call(env)
         | 
| 17 | 
            -
                    if env["PATH_INFO"] == "/__identify__"
         | 
| 18 | 
            -
                      [200, {}, [VCR::LocalhostServer::READY_MESSAGE]]
         | 
| 19 | 
            -
                    else
         | 
| 20 | 
            -
                      @app.call(env)
         | 
| 21 | 
            -
                    end
         | 
| 22 | 
            -
                  end
         | 
| 23 | 
            -
                end
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                attr_reader :port
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                def initialize(rack_app, port = nil)
         | 
| 28 | 
            -
                  @port = port || find_available_port
         | 
| 29 | 
            -
                  @rack_app = rack_app
         | 
| 30 | 
            -
                  concurrently { boot }
         | 
| 31 | 
            -
                  wait_until(30, "Boot failed.") { booted? }
         | 
| 32 | 
            -
                end
         | 
| 33 | 
            -
             | 
| 34 | 
            -
                private
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                def find_available_port
         | 
| 37 | 
            -
                  server = TCPServer.new('127.0.0.1', 0)
         | 
| 38 | 
            -
                  server.addr[1]
         | 
| 39 | 
            -
                ensure
         | 
| 40 | 
            -
                  server.close if server
         | 
| 41 | 
            -
                end
         | 
| 42 | 
            -
             | 
| 43 | 
            -
                def boot
         | 
| 44 | 
            -
                  # Use WEBrick since it's part of the ruby standard library and is available on all ruby interpreters.
         | 
| 45 | 
            -
                  options = { :Port => port, :ShutdownSocketWithoutClose => true }
         | 
| 46 | 
            -
                  options.merge!(:AccessLog => [], :Logger => WEBrick::BasicLog.new(StringIO.new)) unless ENV['VERBOSE_SERVER']
         | 
| 47 | 
            -
                  Rack::Handler::WEBrick.run(Identify.new(@rack_app), options)
         | 
| 48 | 
            -
                end
         | 
| 49 | 
            -
             | 
| 50 | 
            -
                def booted?
         | 
| 51 | 
            -
                  res = ::Net::HTTP.get_response("localhost", '/__identify__', port)
         | 
| 52 | 
            -
                  if res.is_a?(::Net::HTTPSuccess) or res.is_a?(::Net::HTTPRedirection)
         | 
| 53 | 
            -
                    return res.body == READY_MESSAGE
         | 
| 54 | 
            -
                  end
         | 
| 55 | 
            -
                rescue Errno::ECONNREFUSED, Errno::EBADF
         | 
| 56 | 
            -
                  return false
         | 
| 57 | 
            -
                end
         | 
| 58 | 
            -
             | 
| 59 | 
            -
                def concurrently
         | 
| 60 | 
            -
                  # JRuby doesn't support forking.
         | 
| 61 | 
            -
                  # Rubinius does, but there's a weird issue with the booted? check not working,
         | 
| 62 | 
            -
                  # so we're just using a thread for now.
         | 
| 63 | 
            -
                  Thread.new { yield }
         | 
| 64 | 
            -
                end
         | 
| 65 | 
            -
             | 
| 66 | 
            -
                def wait_until(timeout, error_message, &block)
         | 
| 67 | 
            -
                  start_time = Time.now
         | 
| 68 | 
            -
             | 
| 69 | 
            -
                  while true
         | 
| 70 | 
            -
                    return if yield
         | 
| 71 | 
            -
                    raise TimeoutError.new(error_message) if (Time.now - start_time) > timeout
         | 
| 72 | 
            -
                    sleep(0.01)
         | 
| 73 | 
            -
                  end
         | 
| 74 | 
            -
                end
         | 
| 75 | 
            -
              end
         | 
| 76 | 
            -
            end
         | 
| @@ -1,17 +0,0 @@ | |
| 1 | 
            -
            module VCRStubHelpers
         | 
| 2 | 
            -
              def interactions_from(file)
         | 
| 3 | 
            -
                hashes = YAML.load_file(File.join(VCR::SPEC_ROOT, 'fixtures', file))['http_interactions']
         | 
| 4 | 
            -
                hashes.map { |h| VCR::HTTPInteraction.from_hash(h) }
         | 
| 5 | 
            -
              end
         | 
| 6 | 
            -
             | 
| 7 | 
            -
              def stub_requests(*args)
         | 
| 8 | 
            -
                allow(VCR).to receive(:http_interactions).and_return(VCR::Cassette::HTTPInteractionList.new(*args))
         | 
| 9 | 
            -
              end
         | 
| 10 | 
            -
             | 
| 11 | 
            -
              def http_interaction(url, response_body = "FOO!", status_code = 200)
         | 
| 12 | 
            -
                request = VCR::Request.new(:get, request_url)
         | 
| 13 | 
            -
                response_status = VCR::ResponseStatus.new(status_code)
         | 
| 14 | 
            -
                response = VCR::Response.new(response_status, nil, response_body, '1.1')
         | 
| 15 | 
            -
                VCR::HTTPInteraction.new(request, response)
         | 
| 16 | 
            -
              end
         | 
| 17 | 
            -
            end
         |