vcr 3.0.3 → 6.2.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 +5 -5
- data/lib/vcr/cassette/erb_renderer.rb +4 -2
- data/lib/vcr/cassette/http_interaction_list.rb +14 -9
- data/lib/vcr/cassette/migrator.rb +5 -6
- data/lib/vcr/cassette/persisters/file_system.rb +9 -1
- data/lib/vcr/cassette/serializers/compressed.rb +2 -2
- data/lib/vcr/cassette/serializers/json.rb +14 -8
- data/lib/vcr/cassette/serializers/psych.rb +10 -2
- data/lib/vcr/cassette/serializers/syck.rb +7 -1
- data/lib/vcr/cassette/serializers/yaml.rb +14 -2
- data/lib/vcr/cassette/serializers.rb +10 -0
- data/lib/vcr/cassette.rb +63 -16
- data/lib/vcr/configuration.rb +21 -8
- data/lib/vcr/deprecations.rb +0 -62
- data/lib/vcr/errors.rb +17 -12
- data/lib/vcr/library_hooks/excon.rb +8 -0
- data/lib/vcr/library_hooks/typhoeus.rb +91 -79
- data/lib/vcr/library_hooks/webmock.rb +2 -11
- data/lib/vcr/linked_cassette.rb +4 -4
- data/lib/vcr/middleware/excon.rb +1 -1
- data/lib/vcr/middleware/faraday.rb +29 -2
- data/lib/vcr/request_ignorer.rb +8 -1
- data/lib/vcr/request_matcher_registry.rb +3 -3
- data/lib/vcr/structs.rb +48 -32
- data/lib/vcr/test_frameworks/cucumber.rb +16 -5
- data/lib/vcr/test_frameworks/rspec.rb +34 -22
- data/lib/vcr/util/hooks.rb +1 -0
- data/lib/vcr/util/internet_connection.rb +15 -21
- data/lib/vcr/version.rb +2 -2
- data/lib/vcr.rb +52 -2
- metadata +45 -272
- 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/lib/vcr/library_hooks/typhoeus_0.4.rb +0 -103
- 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,51 +0,0 @@
|
|
|
1
|
-
require 'vcr/library_hooks'
|
|
2
|
-
|
|
3
|
-
module VCR
|
|
4
|
-
describe LibraryHooks do
|
|
5
|
-
describe '#disabled?' do
|
|
6
|
-
it 'returns false by default for any argument given' do
|
|
7
|
-
expect(subject.disabled?(:foo)).to be false
|
|
8
|
-
expect(subject.disabled?(:bar)).to be false
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
context 'when a library hook is exclusively enabled' do
|
|
12
|
-
it 'returns false for the exclusively enabled hook' do
|
|
13
|
-
faraday_disabled = nil
|
|
14
|
-
|
|
15
|
-
subject.exclusively_enabled :faraday do
|
|
16
|
-
faraday_disabled = subject.disabled?(:faraday)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
expect(faraday_disabled).to eq(false)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it 'returns true for every other argument given' do
|
|
23
|
-
foo_disabled = bar_disabled = nil
|
|
24
|
-
|
|
25
|
-
subject.exclusively_enabled :faraday do
|
|
26
|
-
foo_disabled = subject.disabled?(:foo)
|
|
27
|
-
bar_disabled = subject.disabled?(:bar)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
expect(foo_disabled).to be true
|
|
31
|
-
expect(bar_disabled).to be true
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
describe '#exclusively_enabled' do
|
|
37
|
-
it 'restores all hook to being enabled when the block completes' do
|
|
38
|
-
subject.exclusively_enabled(:faraday) { }
|
|
39
|
-
expect(subject.disabled?(:foo)).to be false
|
|
40
|
-
expect(subject.disabled?(:faraday)).to be false
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it 'restores all hooks to being enabled when the block completes, even if there is an error' do
|
|
44
|
-
subject.exclusively_enabled(:faraday) { raise "boom" } rescue
|
|
45
|
-
expect(subject.disabled?(:foo)).to be false
|
|
46
|
-
expect(subject.disabled?(:faraday)).to be false
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'vcr/library_hooks/faraday'
|
|
3
|
-
|
|
4
|
-
describe VCR::Middleware::Faraday do
|
|
5
|
-
http_libs = %w[ typhoeus net_http patron ]
|
|
6
|
-
http_libs.each do |lib|
|
|
7
|
-
it_behaves_like 'a hook into an HTTP library', :faraday, "faraday (w/ #{lib})",
|
|
8
|
-
:status_message_not_exposed,
|
|
9
|
-
:does_not_support_rotating_responses
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
context 'when performing a multipart upload' do
|
|
13
|
-
let(:connection) do
|
|
14
|
-
::Faraday.new("http://localhost:#{VCR::SinatraApp.port}/") do |b|
|
|
15
|
-
b.request :multipart
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def self.test_recording
|
|
20
|
-
it 'records the request body correctly' do
|
|
21
|
-
payload = { :file => Faraday::UploadIO.new(__FILE__, 'text/plain') }
|
|
22
|
-
|
|
23
|
-
expect(VCR).to receive(:record_http_interaction) do |i|
|
|
24
|
-
expect(i.request.headers['Content-Type'].first).to include("multipart")
|
|
25
|
-
expect(i.request.body).to include(File.read(__FILE__))
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
VCR.use_cassette("upload") do
|
|
29
|
-
connection.post '/files', payload
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context 'when the net_http adapter is used' do
|
|
35
|
-
before { connection.builder.adapter :net_http }
|
|
36
|
-
test_recording
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
context 'when no adapter is used' do
|
|
40
|
-
test_recording
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context 'when extending the response body with an extension module' do
|
|
45
|
-
let(:connection) { ::Faraday.new("http://localhost:#{VCR::SinatraApp.port}/") }
|
|
46
|
-
|
|
47
|
-
def process_response(response)
|
|
48
|
-
response.body.extend Module.new { attr_accessor :_response }
|
|
49
|
-
response.body._response = response
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it 'does not record the body extensions to the cassette' do
|
|
53
|
-
3.times do |i|
|
|
54
|
-
VCR.use_cassette("hack", :record => :new_episodes) do
|
|
55
|
-
response = connection.get("/foo")
|
|
56
|
-
process_response(response)
|
|
57
|
-
|
|
58
|
-
# Do something different after the first time to
|
|
59
|
-
# ensure new interactions are added to an existing
|
|
60
|
-
# cassette.
|
|
61
|
-
if i > 1
|
|
62
|
-
response = connection.get("/")
|
|
63
|
-
process_response(response)
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
contents = VCR::Cassette.new("hack").send(:raw_cassette_bytes)
|
|
69
|
-
expect(contents).not_to include("ruby/object:Faraday::Response")
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
context 'when making parallel requests' do
|
|
74
|
-
include VCRStubHelpers
|
|
75
|
-
let(:connection) { ::Faraday.new { |b| b.adapter :typhoeus } }
|
|
76
|
-
let(:request_url) { "http://localhost:#{VCR::SinatraApp.port}/" }
|
|
77
|
-
|
|
78
|
-
it 'works correctly with multiple parallel requests' do
|
|
79
|
-
recorded, played_back = [1, 2].map do
|
|
80
|
-
responses = []
|
|
81
|
-
|
|
82
|
-
VCR.use_cassette("multiple_parallel") do
|
|
83
|
-
connection.in_parallel do
|
|
84
|
-
responses << connection.get(request_url)
|
|
85
|
-
responses << connection.get(request_url)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
responses.map(&:body)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
# there should be no blanks
|
|
93
|
-
expect(recorded.select { |r| r.to_s == '' }).to eq([])
|
|
94
|
-
expect(played_back).to eq(recorded)
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
shared_examples_for "exclusive library hook" do
|
|
98
|
-
def make_request
|
|
99
|
-
connection.in_parallel { connection.get(request_url) }
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
it 'makes the faraday middleware exclusively enabled for the duration of the request' do
|
|
103
|
-
expect(VCR.library_hooks).not_to be_disabled(:fakeweb)
|
|
104
|
-
|
|
105
|
-
hook_called = false
|
|
106
|
-
VCR.configuration.after_http_request do
|
|
107
|
-
hook_called = true
|
|
108
|
-
expect(VCR.library_hooks).to be_disabled(:fakeweb)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
make_request
|
|
112
|
-
expect(VCR.library_hooks).not_to be_disabled(:fakeweb)
|
|
113
|
-
expect(hook_called).to be true
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
context 'for an ignored request' do
|
|
118
|
-
before(:each) { VCR.configuration.ignore_request { true } }
|
|
119
|
-
it_behaves_like "exclusive library hook"
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
context 'for a stubbed request' do
|
|
123
|
-
it_behaves_like "exclusive library hook" do
|
|
124
|
-
before(:each) do
|
|
125
|
-
stub_requests([http_interaction(request_url)], [:method, :uri])
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
context "when another adapter is exclusive" do
|
|
131
|
-
it 'still makes requests properly' do
|
|
132
|
-
response = VCR.library_hooks.exclusively_enabled(:typhoeus) do
|
|
133
|
-
Faraday.get("http://localhost:#{VCR::SinatraApp.port}/")
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
expect(response.body).to eq("GET to root")
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
context 'for a recorded request' do
|
|
141
|
-
let!(:inserted_cassette) { VCR.insert_cassette('new_cassette') }
|
|
142
|
-
before(:each) { expect(VCR).to receive(:record_http_interaction) }
|
|
143
|
-
it_behaves_like "exclusive library hook"
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
context 'for a disallowed request' do
|
|
147
|
-
it_behaves_like "exclusive library hook" do
|
|
148
|
-
undef make_request
|
|
149
|
-
def make_request
|
|
150
|
-
expect {
|
|
151
|
-
connection.in_parallel { connection.get(request_url) }
|
|
152
|
-
}.to raise_error(VCR::Errors::UnhandledHTTPRequestError)
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
it_behaves_like "request hooks", :faraday, :recordable do
|
|
158
|
-
let!(:inserted_cassette) { VCR.insert_cassette('new_cassette') }
|
|
159
|
-
|
|
160
|
-
undef make_request
|
|
161
|
-
def make_request(disabled = false)
|
|
162
|
-
response = nil
|
|
163
|
-
connection.in_parallel do
|
|
164
|
-
response = connection.get(request_url)
|
|
165
|
-
end
|
|
166
|
-
response
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
it 'can be used to eject a cassette after the request is recorded' do
|
|
170
|
-
VCR.configuration.after_http_request { |request| VCR.eject_cassette }
|
|
171
|
-
|
|
172
|
-
expect(VCR).to receive(:record_http_interaction) do |interaction|
|
|
173
|
-
expect(VCR.current_cassette).to be(inserted_cassette)
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
make_request
|
|
177
|
-
expect(VCR.current_cassette).to be_nil
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
end if defined?(::Typhoeus)
|
|
181
|
-
end
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'vcr/middleware/rack'
|
|
3
|
-
|
|
4
|
-
module VCR
|
|
5
|
-
module Middleware
|
|
6
|
-
describe CassetteArguments do
|
|
7
|
-
describe '#name' do
|
|
8
|
-
it 'initially returns nil' do
|
|
9
|
-
expect(subject.name).to be_nil
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it 'stores the given value, returning it when no arg is given' do
|
|
13
|
-
subject.name :value1
|
|
14
|
-
expect(subject.name).to eq(:value1)
|
|
15
|
-
|
|
16
|
-
subject.name :value2
|
|
17
|
-
expect(subject.name).to eq(:value2)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe '#options' do
|
|
22
|
-
it 'initially returns an empty hash' do
|
|
23
|
-
expect(subject.options).to eq({})
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it 'merges the given hash options, returning them when no arg is given' do
|
|
27
|
-
subject.options :record => :new_episodes
|
|
28
|
-
expect(subject.options).to eq({ :record => :new_episodes })
|
|
29
|
-
|
|
30
|
-
subject.options :erb => true
|
|
31
|
-
expect(subject.options).to eq({ :record => :new_episodes, :erb => true })
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
describe Rack do
|
|
37
|
-
describe '.new' do
|
|
38
|
-
it 'raises an error if no cassette arguments block is provided' do
|
|
39
|
-
expect {
|
|
40
|
-
described_class.new(lambda { |env| })
|
|
41
|
-
}.to raise_error(ArgumentError)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
describe '#call' do
|
|
46
|
-
let(:env_hash) { { :env => :hash } }
|
|
47
|
-
it 'calls the provided rack app and returns its response' do
|
|
48
|
-
rack_app = double
|
|
49
|
-
expect(rack_app).to receive(:call).with(env_hash).and_return(:response)
|
|
50
|
-
instance = described_class.new(rack_app) { |c| c.name 'cassette_name' }
|
|
51
|
-
expect(instance.call(env_hash)).to eq(:response)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it 'uses a cassette when the rack app is called' do
|
|
55
|
-
expect(VCR.current_cassette).to be_nil
|
|
56
|
-
rack_app = lambda { |env| expect(VCR.current_cassette).not_to be_nil }
|
|
57
|
-
instance = described_class.new(rack_app) { |c| c.name 'cassette_name' }
|
|
58
|
-
instance.call({})
|
|
59
|
-
expect(VCR.current_cassette).to be_nil
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it 'sets the cassette name based on the provided block' do
|
|
63
|
-
rack_app = lambda do |env|
|
|
64
|
-
expect(VCR.current_cassette.name).to eq('rack_cassette')
|
|
65
|
-
end
|
|
66
|
-
instance = described_class.new(rack_app) { |c| c.name 'rack_cassette' }
|
|
67
|
-
instance.call({})
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it 'sets the cassette options based on the provided block' do
|
|
71
|
-
rack_app = lambda do |env|
|
|
72
|
-
expect(VCR.current_cassette.erb).to eq({ :foo => :bar })
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
instance = described_class.new(rack_app, &lambda do |c|
|
|
76
|
-
c.name 'c'
|
|
77
|
-
c.options :erb => { :foo => :bar }
|
|
78
|
-
end)
|
|
79
|
-
|
|
80
|
-
instance.call({})
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it 'yields the rack env to the provided block when the block accepts 2 arguments' do
|
|
84
|
-
instance = described_class.new(lambda { |env| }, &lambda do |c, env|
|
|
85
|
-
expect(env).to eq(env_hash)
|
|
86
|
-
c.name 'c'
|
|
87
|
-
end)
|
|
88
|
-
|
|
89
|
-
instance.call(env_hash)
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
let(:threaded_app) do
|
|
94
|
-
lambda do |env|
|
|
95
|
-
sleep 0.15
|
|
96
|
-
expect(VCR.send(:cassettes).size).to eq(1)
|
|
97
|
-
[200, {}, ['OK']]
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
it 'is thread safe' do
|
|
102
|
-
stack = described_class.new(threaded_app) do |cassette|
|
|
103
|
-
cassette.name 'c'
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
thread = Thread.new { stack.call({}) }
|
|
107
|
-
stack.call({})
|
|
108
|
-
thread.join
|
|
109
|
-
|
|
110
|
-
expect(VCR.current_cassette).to be_nil
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
require 'vcr/structs'
|
|
2
|
-
require 'vcr/request_ignorer'
|
|
3
|
-
|
|
4
|
-
module VCR
|
|
5
|
-
describe RequestIgnorer do
|
|
6
|
-
def request(uri)
|
|
7
|
-
VCR::Request.new.tap { |r| r.uri = uri }
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
shared_examples_for "#ignore?" do |url, expected_value|
|
|
11
|
-
it "returns #{expected_value} if given a request with a url like #{url}" do
|
|
12
|
-
expect(subject.ignore?(request(url))).to eq(expected_value)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
context 'when example.com and example.net are ignored' do
|
|
17
|
-
before(:each) { subject.ignore_hosts 'example.com', 'example.net' }
|
|
18
|
-
|
|
19
|
-
it_behaves_like "#ignore?", "http://www.example.com/foo", false
|
|
20
|
-
it_behaves_like "#ignore?", "http://example.com/foo", true
|
|
21
|
-
it_behaves_like "#ignore?", "http://example.net:890/foo", true
|
|
22
|
-
it_behaves_like "#ignore?", "http://some-other-domain.com/", false
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
context 'when ignore_localhost is set to true' do
|
|
26
|
-
before(:each) { subject.ignore_localhost = true }
|
|
27
|
-
|
|
28
|
-
it_behaves_like "#ignore?", "http://some-host.com/foo", false
|
|
29
|
-
RequestIgnorer::LOCALHOST_ALIASES.each do |host|
|
|
30
|
-
it_behaves_like "#ignore?", "http://#{host}/foo", true
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context 'when ignore_localhost is not set' do
|
|
35
|
-
it_behaves_like "#ignore?", "http://some-host.com/foo", false
|
|
36
|
-
RequestIgnorer::LOCALHOST_ALIASES.each do |host|
|
|
37
|
-
it_behaves_like "#ignore?", "http://#{host}/foo", false
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
context 'when ignore_localhost is set to false after being set to true' do
|
|
42
|
-
before(:each) do
|
|
43
|
-
subject.ignore_localhost = true
|
|
44
|
-
subject.ignore_localhost = false
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it_behaves_like "#ignore?", "http://some-host.com/foo", false
|
|
48
|
-
RequestIgnorer::LOCALHOST_ALIASES.each do |host|
|
|
49
|
-
it_behaves_like "#ignore?", "http://#{host}/foo", false
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context 'when a custom ignore_request hook has been set' do
|
|
54
|
-
before(:each) do
|
|
55
|
-
subject.ignore_request do |request|
|
|
56
|
-
URI(request.uri).port == 5
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it 'ignores requests for which the block returns true' do
|
|
61
|
-
expect(subject.ignore?(request('http://foo.com:5/bar'))).to be true
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it 'does not ignore requests for which the block returns false' do
|
|
65
|
-
expect(subject.ignore?(request('http://foo.com:6/bar'))).to be false
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|