vcr 1.11.3 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +6 -2
- data/CHANGELOG.md +49 -1
- data/Gemfile +1 -5
- data/Guardfile +0 -5
- data/README.md +3 -2
- data/Rakefile +11 -16
- data/cucumber.yml +0 -4
- data/features/.nav +14 -2
- data/features/cassettes/automatic_re_recording.feature +4 -6
- data/features/cassettes/dynamic_erb.feature +6 -8
- data/features/cassettes/exclusive.feature +111 -0
- data/features/cassettes/format.feature +16 -14
- data/features/cassettes/naming.feature +4 -6
- data/features/cassettes/no_cassette.feature +25 -28
- data/features/cassettes/update_content_length_header.feature +9 -9
- data/features/configuration/allow_http_connections_when_no_cassette.feature +6 -8
- data/features/configuration/cassette_library_dir.feature +4 -6
- data/features/configuration/default_cassette_options.feature +12 -10
- data/features/configuration/filter_sensitive_data.feature +12 -17
- data/features/configuration/{stub_with.feature → hook_into.feature} +63 -62
- data/features/configuration/hooks.feature +23 -33
- data/features/configuration/ignore_hosts.feature +16 -17
- data/features/configuration/ignore_localhost.feature +33 -42
- data/features/http_libraries/em_http_request.feature +7 -8
- data/features/http_libraries/net_http.feature +26 -28
- data/features/middleware/faraday.feature +17 -56
- data/features/middleware/rack.feature +8 -11
- data/features/record_modes/all.feature +5 -7
- data/features/record_modes/new_episodes.feature +5 -7
- data/features/record_modes/none.feature +6 -6
- data/features/record_modes/once.feature +6 -8
- data/features/request_matching/README.md +28 -0
- data/features/request_matching/body.feature +81 -0
- data/features/request_matching/custom_matcher.feature +125 -0
- data/features/request_matching/headers.feature +85 -0
- data/features/request_matching/host.feature +85 -0
- data/features/request_matching/identical_request_sequence.feature +79 -0
- data/features/request_matching/method.feature +86 -0
- data/features/request_matching/path.feature +86 -0
- data/features/request_matching/playback_repeats.feature +87 -0
- data/features/request_matching/uri.feature +84 -0
- data/features/request_matching/uri_without_param.feature +85 -0
- data/features/step_definitions/cli_steps.rb +4 -28
- data/features/support/env.rb +11 -9
- data/features/support/http_lib_filters.rb +2 -11
- data/features/support/vcr_cucumber_helpers.rb +4 -5
- data/features/test_frameworks/cucumber.feature +17 -18
- data/features/test_frameworks/rspec.feature +8 -12
- data/features/test_frameworks/shoulda.feature +5 -8
- data/features/test_frameworks/test_unit.feature +5 -8
- data/lib/vcr.rb +38 -58
- data/lib/vcr/cassette.rb +41 -60
- data/lib/vcr/cassette/http_interaction_list.rb +56 -0
- data/lib/vcr/cassette/reader.rb +29 -31
- data/lib/vcr/configuration.rb +76 -0
- data/lib/vcr/deprecations.rb +39 -0
- data/lib/vcr/errors.rb +22 -0
- data/lib/vcr/library_hooks.rb +19 -0
- data/lib/vcr/library_hooks/excon.rb +136 -0
- data/lib/vcr/library_hooks/fakeweb.rb +110 -0
- data/lib/vcr/library_hooks/faraday.rb +3 -0
- data/lib/vcr/library_hooks/typhoeus.rb +98 -0
- data/lib/vcr/library_hooks/webmock.rb +100 -0
- data/lib/vcr/middleware/faraday.rb +43 -36
- data/lib/vcr/middleware/rack.rb +28 -4
- data/lib/vcr/request_handler.rb +43 -0
- data/lib/vcr/request_ignorer.rb +31 -0
- data/lib/vcr/request_matcher_registry.rb +86 -0
- data/lib/vcr/structs/http_interaction.rb +24 -18
- data/lib/vcr/structs/normalizers/body.rb +1 -1
- data/lib/vcr/structs/normalizers/header.rb +1 -1
- data/lib/vcr/structs/normalizers/status_message.rb +1 -1
- data/lib/vcr/structs/normalizers/uri.rb +1 -1
- data/lib/vcr/structs/request.rb +0 -13
- data/lib/vcr/structs/response.rb +2 -9
- data/lib/vcr/structs/response_status.rb +0 -4
- data/lib/vcr/test_frameworks/cucumber.rb +1 -1
- data/lib/vcr/test_frameworks/rspec.rb +1 -1
- data/lib/vcr/util/hooks.rb +28 -19
- data/lib/vcr/util/internet_connection.rb +29 -2
- data/lib/vcr/util/version_checker.rb +60 -0
- data/lib/vcr/version.rb +1 -1
- data/script/FullBuildRakeFile +0 -7
- data/script/full_build +1 -1
- data/spec/capture_warnings.rb +36 -31
- data/spec/fixtures/{1.9.1/cassette_spec → cassette_spec}/empty.yml +0 -0
- data/spec/fixtures/{not_1.9.1/cassette_spec → cassette_spec}/example.yml +0 -0
- data/spec/fixtures/{not_1.9.1/cassette_spec → cassette_spec}/with_localhost_requests.yml +0 -0
- data/spec/fixtures/{not_1.9.1/fake_example.com_responses.yml → fake_example.com_responses.yml} +0 -0
- data/spec/fixtures/{not_1.9.1/match_requests_on.yml → match_requests_on.yml} +0 -0
- data/spec/monkey_patches.rb +40 -11
- data/spec/spec_helper.rb +7 -43
- data/spec/support/http_library_adapters.rb +3 -13
- data/spec/support/shared_example_groups/{http_library.rb → hook_into_http_library.rb} +39 -111
- data/spec/support/shared_example_groups/version_checking.rb +9 -9
- data/spec/vcr/cassette/http_interaction_list_spec.rb +178 -0
- data/spec/vcr/cassette/reader_spec.rb +2 -2
- data/spec/vcr/cassette_spec.rb +121 -156
- data/spec/vcr/configuration_spec.rb +143 -0
- data/spec/vcr/deprecations_spec.rb +91 -0
- data/spec/vcr/{http_stubbing_adapters → library_hooks}/excon_spec.rb +6 -9
- data/spec/vcr/library_hooks/fakeweb_spec.rb +83 -0
- data/spec/vcr/{http_stubbing_adapters → library_hooks}/typhoeus_spec.rb +7 -11
- data/spec/vcr/library_hooks/webmock_spec.rb +17 -0
- data/spec/vcr/library_hooks_spec.rb +51 -0
- data/spec/vcr/middleware/faraday_spec.rb +17 -44
- data/spec/vcr/middleware/rack_spec.rb +94 -58
- data/spec/vcr/request_ignorer_spec.rb +54 -0
- data/spec/vcr/request_matcher_registry_spec.rb +223 -0
- data/spec/vcr/structs/request_spec.rb +0 -33
- data/spec/vcr/structs/response_spec.rb +0 -24
- data/spec/vcr/structs/response_status_spec.rb +0 -9
- data/spec/vcr/util/hooks_spec.rb +3 -5
- data/spec/vcr/version_spec.rb +1 -1
- data/spec/vcr_spec.rb +79 -91
- data/vcr.gemspec +1 -1
- metadata +83 -103
- data/features/cassettes/request_matching.feature +0 -383
- data/lib/vcr/config.rb +0 -84
- data/lib/vcr/deprecations/cassette.rb +0 -29
- data/lib/vcr/deprecations/config.rb +0 -18
- data/lib/vcr/deprecations/http_stubbing_adapters/common.rb +0 -9
- data/lib/vcr/deprecations/http_stubbing_adapters/fakeweb.rb +0 -11
- data/lib/vcr/extensions/net_http.rb +0 -32
- data/lib/vcr/http_stubbing_adapters/common.rb +0 -202
- data/lib/vcr/http_stubbing_adapters/excon.rb +0 -178
- data/lib/vcr/http_stubbing_adapters/fakeweb.rb +0 -107
- data/lib/vcr/http_stubbing_adapters/faraday.rb +0 -26
- data/lib/vcr/http_stubbing_adapters/multi_object_proxy.rb +0 -43
- data/lib/vcr/http_stubbing_adapters/typhoeus.rb +0 -115
- data/lib/vcr/http_stubbing_adapters/webmock.rb +0 -120
- data/lib/vcr/middleware/cassette_arguments.rb +0 -19
- data/lib/vcr/middleware/common.rb +0 -20
- data/lib/vcr/request_matcher.rb +0 -94
- data/lib/vcr/rspec.rb +0 -2
- data/lib/vcr/util/basic_object.rb +0 -43
- data/lib/vcr/util/ping.rb +0 -30
- data/lib/vcr/util/regexes.rb +0 -37
- data/spec/fixtures/1.9.1/0_3_1_cassette.yml +0 -29
- data/spec/fixtures/1.9.1/cassette_spec/example.yml +0 -110
- data/spec/fixtures/1.9.1/cassette_spec/with_localhost_requests.yml +0 -109
- data/spec/fixtures/1.9.1/example_net_http.yml +0 -14
- data/spec/fixtures/1.9.1/example_net_http_request.yml +0 -12
- data/spec/fixtures/1.9.1/example_net_http_response.yml +0 -25
- data/spec/fixtures/1.9.1/fake_example.com_responses.yml +0 -108
- data/spec/fixtures/1.9.1/match_requests_on.yml +0 -185
- data/spec/fixtures/not_1.9.1/0_3_1_cassette.yml +0 -29
- data/spec/fixtures/not_1.9.1/cassette_spec/empty.yml +0 -0
- data/spec/fixtures/not_1.9.1/example_net_http.yml +0 -14
- data/spec/fixtures/not_1.9.1/example_net_http_request.yml +0 -12
- data/spec/fixtures/not_1.9.1/example_net_http_response.yml +0 -25
- data/spec/support/shared_example_groups/http_stubbing_adapter.rb +0 -133
- data/spec/support/shared_example_groups/ignore_localhost_deprecation.rb +0 -28
- data/spec/vcr/config_spec.rb +0 -181
- data/spec/vcr/deprecations/cassette_spec.rb +0 -57
- data/spec/vcr/deprecations/config_spec.rb +0 -30
- data/spec/vcr/deprecations/http_stubbing_adapters/common_spec.rb +0 -7
- data/spec/vcr/deprecations/http_stubbing_adapters/fakeweb_spec.rb +0 -16
- data/spec/vcr/extensions/net_http_spec.rb +0 -80
- data/spec/vcr/http_stubbing_adapters/fakeweb_spec.rb +0 -19
- data/spec/vcr/http_stubbing_adapters/faraday_spec.rb +0 -76
- data/spec/vcr/http_stubbing_adapters/multi_object_proxy_spec.rb +0 -101
- data/spec/vcr/http_stubbing_adapters/webmock_spec.rb +0 -17
- data/spec/vcr/middleware/cassette_arguments_spec.rb +0 -32
- data/spec/vcr/request_matcher_spec.rb +0 -230
@@ -14,28 +14,25 @@ Feature: Usage with Shoulda
|
|
14
14
|
|
15
15
|
Scenario: Use `VCR.insert_cassette` and `VCR.eject_cassette`
|
16
16
|
Given a file named "test/test_server.rb" with:
|
17
|
-
"""
|
18
|
-
require 'vcr_cucumber_helpers'
|
19
|
-
|
17
|
+
"""ruby
|
20
18
|
start_sinatra_app(:port => 7777) do
|
21
19
|
get('/') { "Hello" }
|
22
20
|
end
|
23
21
|
"""
|
24
22
|
Given a file named "test/test_helper.rb" with:
|
25
|
-
"""
|
23
|
+
"""ruby
|
26
24
|
require 'test/test_server' if ENV['SERVER'] == 'true'
|
27
25
|
require 'test/unit'
|
28
26
|
require 'shoulda'
|
29
27
|
require 'vcr'
|
30
28
|
|
31
|
-
VCR.
|
32
|
-
c.
|
29
|
+
VCR.configure do |c|
|
30
|
+
c.hook_into :webmock
|
33
31
|
c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
|
34
|
-
c.default_cassette_options = { :record => :new_episodes }
|
35
32
|
end
|
36
33
|
"""
|
37
34
|
And a file named "test/vcr_example_test.rb" with:
|
38
|
-
"""
|
35
|
+
"""ruby
|
39
36
|
require 'test_helper'
|
40
37
|
|
41
38
|
class VCRExampleTest < Test::Unit::TestCase
|
@@ -5,27 +5,24 @@ Feature: Usage with Test::Unit
|
|
5
5
|
|
6
6
|
Scenario: Use `VCR.use_cassette` in a test
|
7
7
|
Given a file named "test/test_server.rb" with:
|
8
|
-
"""
|
9
|
-
require 'vcr_cucumber_helpers'
|
10
|
-
|
8
|
+
"""ruby
|
11
9
|
start_sinatra_app(:port => 7777) do
|
12
10
|
get('/') { "Hello" }
|
13
11
|
end
|
14
12
|
"""
|
15
13
|
Given a file named "test/test_helper.rb" with:
|
16
|
-
"""
|
14
|
+
"""ruby
|
17
15
|
require 'test/test_server' if ENV['SERVER'] == 'true'
|
18
16
|
require 'test/unit'
|
19
17
|
require 'vcr'
|
20
18
|
|
21
|
-
VCR.
|
22
|
-
c.
|
19
|
+
VCR.configure do |c|
|
20
|
+
c.hook_into :webmock
|
23
21
|
c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
|
24
|
-
c.default_cassette_options = { :record => :new_episodes }
|
25
22
|
end
|
26
23
|
"""
|
27
24
|
And a file named "test/vcr_example_test.rb" with:
|
28
|
-
"""
|
25
|
+
"""ruby
|
29
26
|
require 'test_helper'
|
30
27
|
|
31
28
|
class VCRExampleTest < Test::Unit::TestCase
|
data/lib/vcr.rb
CHANGED
@@ -1,44 +1,28 @@
|
|
1
|
-
require 'vcr/util/regexes'
|
2
1
|
require 'vcr/util/variable_args_block_caller'
|
3
2
|
require 'vcr/util/yaml'
|
4
3
|
|
5
4
|
require 'vcr/cassette'
|
6
|
-
require 'vcr/
|
7
|
-
require 'vcr/
|
5
|
+
require 'vcr/configuration'
|
6
|
+
require 'vcr/deprecations'
|
7
|
+
require 'vcr/errors'
|
8
|
+
require 'vcr/library_hooks'
|
9
|
+
require 'vcr/request_ignorer'
|
10
|
+
require 'vcr/request_matcher_registry'
|
8
11
|
require 'vcr/version'
|
9
12
|
|
10
|
-
require 'vcr/http_stubbing_adapters/common'
|
11
|
-
|
12
|
-
require 'vcr/deprecations/cassette'
|
13
|
-
require 'vcr/deprecations/config'
|
14
|
-
require 'vcr/deprecations/http_stubbing_adapters/common'
|
15
|
-
|
16
|
-
require 'vcr/structs/normalizers/body'
|
17
|
-
require 'vcr/structs/normalizers/header'
|
18
|
-
require 'vcr/structs/normalizers/status_message'
|
19
|
-
require 'vcr/structs/normalizers/uri'
|
20
13
|
require 'vcr/structs/http_interaction'
|
21
|
-
require 'vcr/structs/request'
|
22
|
-
require 'vcr/structs/response'
|
23
|
-
require 'vcr/structs/response_status'
|
24
14
|
|
25
15
|
module VCR
|
26
16
|
include VariableArgsBlockCaller
|
17
|
+
include Errors
|
18
|
+
|
27
19
|
extend self
|
28
20
|
|
29
|
-
autoload :BasicObject, 'vcr/util/basic_object'
|
30
21
|
autoload :CucumberTags, 'vcr/test_frameworks/cucumber'
|
31
22
|
autoload :InternetConnection, 'vcr/util/internet_connection'
|
32
23
|
autoload :RSpec, 'vcr/test_frameworks/rspec'
|
33
24
|
|
34
|
-
LOCALHOST_ALIASES = %w( localhost 127.0.0.1 0.0.0.0 )
|
35
|
-
|
36
|
-
class CassetteInUseError < StandardError; end
|
37
|
-
class TurnedOffError < StandardError; end
|
38
|
-
|
39
25
|
module Middleware
|
40
|
-
autoload :CassetteArguments, 'vcr/middleware/cassette_arguments'
|
41
|
-
autoload :Common, 'vcr/middleware/common'
|
42
26
|
autoload :Faraday, 'vcr/middleware/faraday'
|
43
27
|
autoload :Rack, 'vcr/middleware/rack'
|
44
28
|
end
|
@@ -79,35 +63,44 @@ module VCR
|
|
79
63
|
end
|
80
64
|
end
|
81
65
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
http_stubbing_adapter.set_http_connections_allowed_to_default
|
86
|
-
http_stubbing_adapter.ignored_hosts = VCR::Config.ignored_hosts
|
66
|
+
def http_interactions
|
67
|
+
return current_cassette.http_interactions if current_cassette
|
68
|
+
VCR::Cassette::HTTPInteractionList::NullList.new
|
87
69
|
end
|
88
70
|
|
89
|
-
def
|
90
|
-
|
91
|
-
|
71
|
+
def real_http_connections_allowed?
|
72
|
+
return current_cassette.recording? if current_cassette
|
73
|
+
configuration.allow_http_connections_when_no_cassette? || @turned_off
|
92
74
|
end
|
93
75
|
|
94
|
-
def
|
95
|
-
@
|
96
|
-
|
97
|
-
raise ArgumentError.new("You have configured VCR to use both :fakeweb and :webmock. You cannot use both.")
|
98
|
-
end
|
76
|
+
def request_matchers
|
77
|
+
@request_matchers ||= RequestMatcherRegistry.new
|
78
|
+
end
|
99
79
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
80
|
+
def request_ignorer
|
81
|
+
@request_ignorer ||= RequestIgnorer.new
|
82
|
+
end
|
83
|
+
|
84
|
+
def library_hooks
|
85
|
+
@library_hooks ||= LibraryHooks.new
|
86
|
+
end
|
87
|
+
|
88
|
+
def configuration
|
89
|
+
@configuration ||= Configuration.new
|
90
|
+
end
|
91
|
+
|
92
|
+
def configure
|
93
|
+
yield configuration
|
94
|
+
end
|
95
|
+
|
96
|
+
def cucumber_tags(&block)
|
97
|
+
main_object = eval('self', block.binding)
|
98
|
+
yield VCR::CucumberTags.new(main_object)
|
106
99
|
end
|
107
100
|
|
108
101
|
def record_http_interaction(interaction)
|
109
102
|
return unless cassette = current_cassette
|
110
|
-
return if VCR
|
103
|
+
return if VCR.request_ignorer.ignore?(interaction.request)
|
111
104
|
|
112
105
|
cassette.record_http_interaction(interaction)
|
113
106
|
end
|
@@ -133,12 +126,10 @@ module VCR
|
|
133
126
|
raise ArgumentError.new("You passed some invalid options: #{invalid_options.inspect}")
|
134
127
|
end
|
135
128
|
|
136
|
-
VCR.http_stubbing_adapter.http_connections_allowed = true
|
137
129
|
@turned_off = true
|
138
130
|
end
|
139
131
|
|
140
132
|
def turn_on!
|
141
|
-
VCR.http_stubbing_adapter.set_http_connections_allowed_to_default
|
142
133
|
@turned_off = false
|
143
134
|
end
|
144
135
|
|
@@ -150,18 +141,7 @@ module VCR
|
|
150
141
|
@ignore_cassettes
|
151
142
|
end
|
152
143
|
|
153
|
-
|
154
|
-
|
155
|
-
def adapter_for(lib)
|
156
|
-
case lib
|
157
|
-
when :excon; HttpStubbingAdapters::Excon
|
158
|
-
when :fakeweb; HttpStubbingAdapters::FakeWeb
|
159
|
-
when :faraday; HttpStubbingAdapters::Faraday
|
160
|
-
when :typhoeus; HttpStubbingAdapters::Typhoeus
|
161
|
-
when :webmock; HttpStubbingAdapters::WebMock
|
162
|
-
else raise ArgumentError.new("#{lib.inspect} is not a supported HTTP stubbing library.")
|
163
|
-
end
|
164
|
-
end
|
144
|
+
private
|
165
145
|
|
166
146
|
def cassettes
|
167
147
|
@cassettes ||= []
|
data/lib/vcr/cassette.rb
CHANGED
@@ -3,50 +3,43 @@ require 'erb'
|
|
3
3
|
require 'set'
|
4
4
|
|
5
5
|
require 'vcr/cassette/reader'
|
6
|
+
require 'vcr/cassette/http_interaction_list'
|
6
7
|
|
7
8
|
module VCR
|
8
9
|
class Cassette
|
9
10
|
VALID_RECORD_MODES = [:all, :none, :new_episodes, :once]
|
10
11
|
|
11
|
-
attr_reader :name, :record_mode, :match_requests_on, :erb, :re_record_interval, :tag
|
12
|
+
attr_reader :name, :record_mode, :match_requests_on, :erb, :re_record_interval, :tag, :http_interactions
|
12
13
|
|
13
14
|
def initialize(name, options = {})
|
14
|
-
options = VCR
|
15
|
+
options = VCR.configuration.default_cassette_options.merge(options)
|
15
16
|
invalid_options = options.keys - [
|
16
|
-
:record,
|
17
|
-
:
|
18
|
-
:allow_real_http,
|
19
|
-
:match_requests_on,
|
20
|
-
:re_record_interval,
|
21
|
-
:tag,
|
22
|
-
:update_content_length_header
|
17
|
+
:record, :erb, :match_requests_on, :re_record_interval, :tag,
|
18
|
+
:update_content_length_header, :allow_playback_repeats, :exclusive
|
23
19
|
]
|
24
20
|
|
25
21
|
if invalid_options.size > 0
|
26
22
|
raise ArgumentError.new("You passed the following invalid options to VCR::Cassette.new: #{invalid_options.inspect}.")
|
27
23
|
end
|
28
24
|
|
29
|
-
@name
|
30
|
-
@record_mode
|
31
|
-
@erb
|
32
|
-
@match_requests_on
|
33
|
-
@re_record_interval
|
34
|
-
@tag
|
35
|
-
@record_mode
|
25
|
+
@name = name
|
26
|
+
@record_mode = options[:record]
|
27
|
+
@erb = options[:erb]
|
28
|
+
@match_requests_on = options[:match_requests_on]
|
29
|
+
@re_record_interval = options[:re_record_interval]
|
30
|
+
@tag = options[:tag]
|
31
|
+
@record_mode = :all if should_re_record?
|
36
32
|
@update_content_length_header = options[:update_content_length_header]
|
33
|
+
@allow_playback_repeats = options[:allow_playback_repeats]
|
34
|
+
@exclusive = options[:exclusive]
|
37
35
|
|
38
|
-
deprecate_old_cassette_options(options)
|
39
36
|
raise_error_unless_valid_record_mode
|
40
37
|
|
41
|
-
set_http_connections_allowed
|
42
38
|
load_recorded_interactions
|
43
39
|
end
|
44
40
|
|
45
41
|
def eject
|
46
42
|
write_recorded_interactions_to_disk
|
47
|
-
VCR.http_stubbing_adapter.restore_stubs_checkpoint(self)
|
48
|
-
restore_http_connections_allowed
|
49
|
-
restore_ignore_localhost_for_deprecation
|
50
43
|
end
|
51
44
|
|
52
45
|
def recorded_interactions
|
@@ -62,14 +55,22 @@ module VCR
|
|
62
55
|
end
|
63
56
|
|
64
57
|
def file
|
65
|
-
File.join(VCR
|
58
|
+
File.join(VCR.configuration.cassette_library_dir, "#{sanitized_name}.yml") if VCR.configuration.cassette_library_dir
|
66
59
|
end
|
67
60
|
|
68
61
|
def update_content_length_header?
|
69
62
|
@update_content_length_header
|
70
63
|
end
|
71
64
|
|
72
|
-
|
65
|
+
def recording?
|
66
|
+
case record_mode
|
67
|
+
when :none; false
|
68
|
+
when :once; file.nil? || !File.size?(file)
|
69
|
+
else true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
73
74
|
|
74
75
|
def sanitized_name
|
75
76
|
name.to_s.gsub(/[^\w\-\/]+/, '_')
|
@@ -88,14 +89,6 @@ module VCR
|
|
88
89
|
InternetConnection.available?
|
89
90
|
end
|
90
91
|
|
91
|
-
def should_allow_http_connections?
|
92
|
-
case record_mode
|
93
|
-
when :none; false
|
94
|
-
when :once; !File.size?(file)
|
95
|
-
else true
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
92
|
def should_stub_requests?
|
100
93
|
record_mode != :all
|
101
94
|
end
|
@@ -104,29 +97,14 @@ module VCR
|
|
104
97
|
record_mode == :all
|
105
98
|
end
|
106
99
|
|
107
|
-
def set_http_connections_allowed
|
108
|
-
@orig_http_connections_allowed = VCR.http_stubbing_adapter.http_connections_allowed?
|
109
|
-
VCR.http_stubbing_adapter.http_connections_allowed = should_allow_http_connections?
|
110
|
-
end
|
111
|
-
|
112
|
-
def restore_http_connections_allowed
|
113
|
-
VCR.http_stubbing_adapter.http_connections_allowed = @orig_http_connections_allowed
|
114
|
-
end
|
115
|
-
|
116
100
|
def load_recorded_interactions
|
117
|
-
VCR.http_stubbing_adapter.create_stubs_checkpoint(self)
|
118
101
|
if file && File.size?(file)
|
119
|
-
|
120
|
-
interactions = VCR::YAML.load(raw_yaml_content)
|
121
|
-
rescue TypeError, ArgumentError # Syck raises TypeError, Psych raises ArgumentError
|
122
|
-
raise unless raw_yaml_content =~ /VCR::RecordedResponse/
|
123
|
-
raise "The VCR cassette #{sanitized_name}.yml uses an old format that is now deprecated. VCR provides a rake task to migrate your old cassettes to the new format. See http://github.com/myronmarston/vcr/blob/master/CHANGELOG.md for more info."
|
124
|
-
end
|
102
|
+
interactions = VCR::YAML.load(raw_yaml_content)
|
125
103
|
|
126
104
|
invoke_hook(:before_playback, interactions)
|
127
105
|
|
128
106
|
interactions.reject! do |i|
|
129
|
-
i.request.uri.is_a?(String) && VCR
|
107
|
+
i.request.uri.is_a?(String) && VCR.request_ignorer.ignore?(i.request)
|
130
108
|
end
|
131
109
|
|
132
110
|
if update_content_length_header?
|
@@ -136,9 +114,17 @@ module VCR
|
|
136
114
|
recorded_interactions.replace(interactions)
|
137
115
|
end
|
138
116
|
|
139
|
-
|
140
|
-
|
141
|
-
|
117
|
+
interactions = should_stub_requests? ? recorded_interactions : []
|
118
|
+
|
119
|
+
@http_interactions = HTTPInteractionList.new(
|
120
|
+
interactions,
|
121
|
+
match_requests_on,
|
122
|
+
@allow_playback_repeats,
|
123
|
+
parent_list)
|
124
|
+
end
|
125
|
+
|
126
|
+
def parent_list
|
127
|
+
@exclusive ? HTTPInteractionList::NullList.new : VCR.http_interactions
|
142
128
|
end
|
143
129
|
|
144
130
|
def raw_yaml_content
|
@@ -149,14 +135,9 @@ module VCR
|
|
149
135
|
old_interactions = recorded_interactions
|
150
136
|
|
151
137
|
if should_remove_matching_existing_interactions?
|
152
|
-
|
153
|
-
|
154
|
-
new_request_matchers = Set.new new_recorded_interactions.map do |i|
|
155
|
-
i.request.matcher(match_attributes)
|
156
|
-
end
|
157
|
-
|
138
|
+
new_interaction_list = HTTPInteractionList.new(new_recorded_interactions, match_requests_on)
|
158
139
|
old_interactions = old_interactions.reject do |i|
|
159
|
-
|
140
|
+
new_interaction_list.has_interaction_matching?(i.request)
|
160
141
|
end
|
161
142
|
end
|
162
143
|
|
@@ -164,7 +145,7 @@ module VCR
|
|
164
145
|
end
|
165
146
|
|
166
147
|
def write_recorded_interactions_to_disk
|
167
|
-
return unless VCR
|
148
|
+
return unless VCR.configuration.cassette_library_dir
|
168
149
|
return if new_recorded_interactions.empty?
|
169
150
|
|
170
151
|
interactions = merged_interactions
|
@@ -178,7 +159,7 @@ module VCR
|
|
178
159
|
|
179
160
|
def invoke_hook(type, interactions)
|
180
161
|
interactions.delete_if do |i|
|
181
|
-
VCR
|
162
|
+
VCR.configuration.invoke_hook(type, tag, i, self)
|
182
163
|
i.ignored?
|
183
164
|
end
|
184
165
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module VCR
|
2
|
+
class Cassette
|
3
|
+
class HTTPInteractionList
|
4
|
+
class NullList
|
5
|
+
def response_for(*a); nil; end
|
6
|
+
def has_interaction_matching?(*a); false; end
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :interactions, :request_matchers, :allow_playback_repeats, :parent_list
|
10
|
+
|
11
|
+
def initialize(interactions, request_matchers, allow_playback_repeats = false, parent_list = NullList.new)
|
12
|
+
@interactions = interactions.dup
|
13
|
+
@request_matchers = request_matchers
|
14
|
+
@allow_playback_repeats = allow_playback_repeats
|
15
|
+
@parent_list = parent_list
|
16
|
+
@used_interactions = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def response_for(request)
|
20
|
+
if index = matching_interaction_index_for(request)
|
21
|
+
interaction = @interactions.delete_at(index)
|
22
|
+
@used_interactions.unshift interaction
|
23
|
+
interaction.response
|
24
|
+
elsif interaction = matching_used_interaction_for(request)
|
25
|
+
interaction.response
|
26
|
+
else
|
27
|
+
@parent_list.response_for(request)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def has_interaction_matching?(request)
|
32
|
+
!!matching_interaction_index_for(request) ||
|
33
|
+
!!matching_used_interaction_for(request) ||
|
34
|
+
@parent_list.has_interaction_matching?(request)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def matching_interaction_index_for(request)
|
40
|
+
@interactions.index { |i| interaction_matches_request?(request, i) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def matching_used_interaction_for(request)
|
44
|
+
return nil unless @allow_playback_repeats
|
45
|
+
@used_interactions.find { |i| interaction_matches_request?(request, i) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def interaction_matches_request?(request, interaction)
|
49
|
+
@request_matchers.all? do |matcher|
|
50
|
+
VCR.request_matchers[matcher].matches?(request, interaction.request)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|