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
@@ -1,28 +0,0 @@
|
|
1
|
-
shared_examples_for '.ignore_localhost? deprecation' do
|
2
|
-
it 'returns false when no hosts are ignored' do
|
3
|
-
VCR::Config.ignored_hosts.should be_empty
|
4
|
-
described_class.ignore_localhost?.should be_false
|
5
|
-
end
|
6
|
-
|
7
|
-
it 'returns false when only non-local hosts are ignored' do
|
8
|
-
VCR::Config.ignore_hosts 'example.com'
|
9
|
-
described_class.ignore_localhost?.should be_false
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'returns false when only some localhost aliases are ignored' do
|
13
|
-
aliases = VCR::LOCALHOST_ALIASES.dup
|
14
|
-
aliases.pop
|
15
|
-
VCR::Config.ignore_hosts(*aliases)
|
16
|
-
described_class.ignore_localhost?.should be_false
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'returns true when all localhost aliases are ignored, even if some other hosts are ignored, too' do
|
20
|
-
VCR::Config.ignore_hosts 'example.com', *VCR::LOCALHOST_ALIASES
|
21
|
-
described_class.ignore_localhost?.should be_true
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'prints a warning: WARNING: `VCR::Config.ignore_localhost?` is deprecated. Check the list of ignored hosts using `VCR::Config.ignored_hosts` instead.' do
|
25
|
-
VCR::Config.should_receive(:warn).with(/Check the list of ignored hosts using `VCR::Config.ignored_hosts` instead/)
|
26
|
-
described_class.ignore_localhost?
|
27
|
-
end
|
28
|
-
end
|
data/spec/vcr/config_spec.rb
DELETED
@@ -1,181 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe VCR::Config do
|
4
|
-
def stub_no_http_stubbing_adapter
|
5
|
-
VCR.stub(:http_stubbing_adapter).and_raise(ArgumentError)
|
6
|
-
VCR::Config.stub(:http_stubbing_libraries).and_return([])
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '.cassette_library_dir=' do
|
10
|
-
let(:tmp_dir) { VCR::SPEC_ROOT + '/../tmp/cassette_library_dir/new_dir' }
|
11
|
-
after(:each) { FileUtils.rm_rf tmp_dir }
|
12
|
-
|
13
|
-
it 'creates the directory if it does not exist' do
|
14
|
-
expect { VCR::Config.cassette_library_dir = tmp_dir }.to change { File.exist?(tmp_dir) }.from(false).to(true)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'does not raise an error if given nil' do
|
18
|
-
expect { VCR::Config.cassette_library_dir = nil }.to_not raise_error
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '.default_cassette_options' do
|
23
|
-
it 'has a hash with some defaults even if it is set to nil' do
|
24
|
-
VCR::Config.default_cassette_options = nil
|
25
|
-
VCR::Config.default_cassette_options.should eq({
|
26
|
-
:match_requests_on => VCR::RequestMatcher::DEFAULT_MATCH_ATTRIBUTES,
|
27
|
-
:record => :once
|
28
|
-
})
|
29
|
-
end
|
30
|
-
|
31
|
-
it "returns #{VCR::RequestMatcher::DEFAULT_MATCH_ATTRIBUTES.inspect} for :match_requests_on when other defaults have been set" do
|
32
|
-
VCR::Config.default_cassette_options = { :record => :none }
|
33
|
-
VCR::Config.default_cassette_options.should include(:match_requests_on => VCR::RequestMatcher::DEFAULT_MATCH_ATTRIBUTES)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "returns :once for :record when other defaults have been set" do
|
37
|
-
VCR::Config.default_cassette_options = { :erb => :true }
|
38
|
-
VCR::Config.default_cassette_options.should include(:record => :once)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '.stub_with' do
|
43
|
-
it 'stores the given symbols in http_stubbing_libraries' do
|
44
|
-
VCR::Config.stub_with :fakeweb, :typhoeus
|
45
|
-
VCR::Config.http_stubbing_libraries.should eq([:fakeweb, :typhoeus])
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '.http_stubbing_libraries' do
|
50
|
-
it 'returns an empty array even when the variable is nil' do
|
51
|
-
VCR::Config.send(:remove_instance_variable, :@http_stubbing_libraries)
|
52
|
-
VCR::Config.http_stubbing_libraries.should eq([])
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '.ignore_hosts' do
|
57
|
-
let(:stubbing_adapter) { VCR::HttpStubbingAdapters::FakeWeb }
|
58
|
-
before(:each) do
|
59
|
-
stubbing_adapter.send(:ignored_hosts).should be_empty
|
60
|
-
VCR.stub(:http_stubbing_adapter => stubbing_adapter)
|
61
|
-
VCR::Config.ignored_hosts.should be_empty
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'adds the given hosts to the ignored_hosts list' do
|
65
|
-
VCR::Config.ignore_hosts 'example.com', 'example.net'
|
66
|
-
VCR::Config.ignored_hosts.should eq(%w[ example.com example.net ])
|
67
|
-
VCR::Config.ignore_host 'example.org'
|
68
|
-
VCR::Config.ignored_hosts.should eq(%w[ example.com example.net example.org ])
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'removes duplicate hosts' do
|
72
|
-
VCR::Config.ignore_host 'example.com'
|
73
|
-
VCR::Config.ignore_host 'example.com'
|
74
|
-
VCR::Config.ignored_hosts.should eq(['example.com'])
|
75
|
-
end
|
76
|
-
|
77
|
-
it "updates the http_stubbing_adapter's ignored_hosts list" do
|
78
|
-
VCR::Config.ignore_hosts 'example.com', 'example.org'
|
79
|
-
stubbing_adapter.send(:ignored_hosts).should eq(%w[ example.com example.org ])
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe '.ignore_localhost=' do
|
84
|
-
before(:each) do
|
85
|
-
VCR::Config.ignored_hosts.should be_empty
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'adds the localhost aliases to the ignored_hosts list when set to true' do
|
89
|
-
VCR::Config.ignore_host 'example.com'
|
90
|
-
VCR::Config.ignore_localhost = true
|
91
|
-
VCR::Config.ignored_hosts.should eq(['example.com', *VCR::LOCALHOST_ALIASES])
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'removes the localhost aliases from the ignored_hosts list when set to false' do
|
95
|
-
VCR::Config.ignore_host 'example.com', *VCR::LOCALHOST_ALIASES
|
96
|
-
VCR::Config.ignore_localhost = false
|
97
|
-
VCR::Config.ignored_hosts.should eq(['example.com'])
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe '.allow_http_connections_when_no_cassette=' do
|
102
|
-
[true, false].each do |val|
|
103
|
-
it "sets the allow_http_connections_when_no_cassette to #{val} when set to #{val}" do
|
104
|
-
VCR::Config.allow_http_connections_when_no_cassette = val
|
105
|
-
VCR::Config.allow_http_connections_when_no_cassette?.should eq(val)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'sets http_connnections_allowed to the default' do
|
110
|
-
VCR.http_stubbing_adapter.should respond_to(:set_http_connections_allowed_to_default)
|
111
|
-
VCR.http_stubbing_adapter.should_receive(:set_http_connections_allowed_to_default)
|
112
|
-
VCR::Config.allow_http_connections_when_no_cassette = true
|
113
|
-
end
|
114
|
-
|
115
|
-
it "works when the adapter hasn't been set yet" do
|
116
|
-
stub_no_http_stubbing_adapter
|
117
|
-
VCR::Config.allow_http_connections_when_no_cassette = true
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe '.uri_should_be_ignored?' do
|
122
|
-
before(:each) { described_class.ignore_hosts 'example.com' }
|
123
|
-
|
124
|
-
it 'returns true for a string URI with a host in the ignore_hosts list' do
|
125
|
-
described_class.uri_should_be_ignored?("http://example.com/").should be_true
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'returns true for a URI instance with a host in the ignore_hosts list' do
|
129
|
-
described_class.uri_should_be_ignored?(URI("http://example.com/")).should be_true
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'returns false for a string URI with a host in the ignore_hosts list' do
|
133
|
-
described_class.uri_should_be_ignored?("http://example.net/").should be_false
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'returns false for a URI instance with a host in the ignore_hosts list' do
|
137
|
-
described_class.uri_should_be_ignored?(URI("http://example.net/")).should be_false
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe '.filter_sensitive_data' do
|
142
|
-
let(:interaction) { mock('interaction') }
|
143
|
-
before(:each) { interaction.stub(:filter!) }
|
144
|
-
|
145
|
-
it 'adds a before_record hook that replaces the string returned by the block with the given string' do
|
146
|
-
described_class.filter_sensitive_data('foo', &lambda { 'bar' })
|
147
|
-
interaction.should_receive(:filter!).with('bar', 'foo')
|
148
|
-
described_class.invoke_hook(:before_record, nil, interaction)
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'adds a before_playback hook that replaces the given string with the string returned by the block' do
|
152
|
-
described_class.filter_sensitive_data('foo', &lambda { 'bar' })
|
153
|
-
interaction.should_receive(:filter!).with('foo', 'bar')
|
154
|
-
described_class.invoke_hook(:before_playback, nil, interaction)
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'tags the before_record hook when given a tag' do
|
158
|
-
described_class.should_receive(:before_record).with(:my_tag)
|
159
|
-
described_class.filter_sensitive_data('foo', :my_tag) { 'bar' }
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'tags the before_playback hook when given a tag' do
|
163
|
-
described_class.should_receive(:before_playback).with(:my_tag)
|
164
|
-
described_class.filter_sensitive_data('foo', :my_tag) { 'bar' }
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'yields the interaction to the block for the before_record hook' do
|
168
|
-
yielded_interaction = nil
|
169
|
-
described_class.filter_sensitive_data('foo', &lambda { |i| yielded_interaction = i; 'bar' })
|
170
|
-
described_class.invoke_hook(:before_record, nil, interaction)
|
171
|
-
yielded_interaction.should equal(interaction)
|
172
|
-
end
|
173
|
-
|
174
|
-
it 'yields the interaction to the block for the before_playback hook' do
|
175
|
-
yielded_interaction = nil
|
176
|
-
described_class.filter_sensitive_data('foo', &lambda { |i| yielded_interaction = i; 'bar' })
|
177
|
-
described_class.invoke_hook(:before_playback, nil, interaction)
|
178
|
-
yielded_interaction.should equal(interaction)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe VCR::Cassette, 'deprecations', :disable_warnings => true do
|
4
|
-
|
5
|
-
subject { VCR::Cassette.new('cassette name') }
|
6
|
-
|
7
|
-
it 'raises an error when an :allow_real_http lambda is given' do
|
8
|
-
expect { VCR::Cassette.new('cassette name', :allow_real_http => lambda {}) }.to raise_error(ArgumentError)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "prints a warning: WARNING: VCR::Cassette#allow_real_http_requests_to? is deprecated and should no longer be used" do
|
12
|
-
subject.should_receive(:warn).with("WARNING: VCR::Cassette#allow_real_http_requests_to? is deprecated and should no longer be used.")
|
13
|
-
subject.allow_real_http_requests_to?(URI.parse('http://example.org'))
|
14
|
-
end
|
15
|
-
|
16
|
-
[true, false].each do |orig_ignore_localhost|
|
17
|
-
orig_ignored_hosts = if orig_ignore_localhost
|
18
|
-
VCR::LOCALHOST_ALIASES
|
19
|
-
else
|
20
|
-
[]
|
21
|
-
end
|
22
|
-
|
23
|
-
context "when the ignored_hosts list is set to #{orig_ignored_hosts.inspect} and the :allow_real_http option is set to :localhost" do
|
24
|
-
before(:each) do
|
25
|
-
VCR::Config.ignored_hosts.clear
|
26
|
-
VCR::Config.ignore_hosts(*orig_ignored_hosts)
|
27
|
-
end
|
28
|
-
|
29
|
-
subject { VCR::Cassette.new('cassette name', :allow_real_http => :localhost) }
|
30
|
-
|
31
|
-
it "sets the ignored_hosts list to the list of localhost aliases" do
|
32
|
-
subject
|
33
|
-
VCR::Config.ignored_hosts.should eq(VCR::LOCALHOST_ALIASES)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "prints a warning: VCR's :allow_real_http cassette option is deprecated. Instead, use the ignore_localhost configuration option." do
|
37
|
-
Kernel.should_receive(:warn).with("WARNING: VCR's :allow_real_http cassette option is deprecated. Instead, use the ignore_localhost configuration option.")
|
38
|
-
subject
|
39
|
-
end
|
40
|
-
|
41
|
-
it "reverts ignore_hosts when the cassette is ejected" do
|
42
|
-
subject.eject
|
43
|
-
VCR::Config.ignored_hosts.should eq(orig_ignored_hosts)
|
44
|
-
end
|
45
|
-
|
46
|
-
{
|
47
|
-
'http://localhost' => true,
|
48
|
-
'http://127.0.0.1' => true,
|
49
|
-
'http://example.com' => false
|
50
|
-
}.each do |url, expected_value|
|
51
|
-
it "returns #{expected_value} for #allow_real_http_requests_to? when it is given #{url}" do
|
52
|
-
subject.allow_real_http_requests_to?(URI.parse(url)).should eq(expected_value)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe VCR::Config, 'deprecations', :disable_warnings => true do
|
4
|
-
describe '.http_stubbing_library' do
|
5
|
-
before(:each) { described_class.stub_with :webmock, :typhoeus }
|
6
|
-
|
7
|
-
it 'returns the first configured stubbing library' do
|
8
|
-
described_class.http_stubbing_library.should eq(:webmock)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'prints a warning: WARNING: VCR::Config.http_stubbing_library is deprecated. Use VCR::Config.http_stubbing_libraries instead' do
|
12
|
-
described_class.should_receive(:warn).with("WARNING: `VCR::Config.http_stubbing_library` is deprecated. Use `VCR::Config.http_stubbing_libraries` instead.")
|
13
|
-
described_class.http_stubbing_library
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '.http_stubbing_library=' do
|
18
|
-
it 'sets http_stubbing_libraries to an array of the given value' do
|
19
|
-
described_class.http_stubbing_library = :webmock
|
20
|
-
described_class.http_stubbing_libraries.should eq([:webmock])
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'prints a warning: WARNING: VCR::Config.http_stubbing_library= is deprecated. Use VCR::Config.stub_with instead' do
|
24
|
-
described_class.should_receive(:warn).with("WARNING: `VCR::Config.http_stubbing_library = :webmock` is deprecated. Use `VCR::Config.stub_with :webmock` instead.")
|
25
|
-
described_class.http_stubbing_library = :webmock
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
it_behaves_like '.ignore_localhost? deprecation'
|
30
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe VCR::HttpStubbingAdapters::FakeWeb, 'deprecations', :disable_warnings => true do
|
4
|
-
describe 'LOCALHOST_REGEX constant' do
|
5
|
-
subject { described_class::LOCALHOST_REGEX }
|
6
|
-
|
7
|
-
it 'refers to the expected regex' do
|
8
|
-
should be == %r|\Ahttps?://((\w+:)?\w+@)?(#{VCR::LOCALHOST_ALIASES.sort.map { |a| Regexp.escape(a) }.join('|')})(:\d+)?/|i
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'prints a warning: WARNING: `VCR::HttpStubbingAdapters::FakeWeb::LOCALHOST_REGEX` is deprecated.' do
|
12
|
-
described_class.should_receive(:warn).with("WARNING: `VCR::HttpStubbingAdapters::FakeWeb::LOCALHOST_REGEX` is deprecated.")
|
13
|
-
subject
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Net::HTTP Extensions", :with_monkey_patches => :vcr do
|
4
|
-
before(:all) { VCR::SinatraApp.port } # ensure the server is started before instantiating any Net::HTTP instances
|
5
|
-
|
6
|
-
let(:uri) { URI.parse("http://localhost:#{VCR::SinatraApp.port}/") }
|
7
|
-
before(:each) { VCR.stub(:http_stubbing_adapter).and_return(VCR::HttpStubbingAdapters::FakeWeb) }
|
8
|
-
|
9
|
-
it 'checks if the request is stubbed using a VCR::Request' do
|
10
|
-
VCR.http_stubbing_adapter.should_receive(:request_stubbed?) do |request, _|
|
11
|
-
request.uri.should eq("http://localhost:#{VCR::SinatraApp.port}/")
|
12
|
-
request.method.should eq(:get)
|
13
|
-
true
|
14
|
-
end
|
15
|
-
Net::HTTP.get(uri)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "checks if the request is stubbed using the current VCR cassette's match_request_on option" do
|
19
|
-
VCR.should_receive(:current_cassette).and_return(stub(:match_requests_on => [:body, :header]))
|
20
|
-
VCR.http_stubbing_adapter.should_receive(:request_stubbed?).with(anything, [:body, :header]).and_return(true)
|
21
|
-
Net::HTTP.get(uri)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "checks if the request is stubbed using the default match attributes when there is no current cassette" do
|
25
|
-
VCR.should_receive(:current_cassette).and_return(nil)
|
26
|
-
VCR.http_stubbing_adapter.should_receive(:request_stubbed?).with(anything, VCR::RequestMatcher::DEFAULT_MATCH_ATTRIBUTES).and_return(true)
|
27
|
-
Net::HTTP.get(uri)
|
28
|
-
end
|
29
|
-
|
30
|
-
describe 'a request that is not registered with the http stubbing adapter' do
|
31
|
-
before(:each) do
|
32
|
-
VCR.http_stubbing_adapter.stub(:request_stubbed?).and_return(false)
|
33
|
-
end
|
34
|
-
|
35
|
-
def perform_get_with_returning_block
|
36
|
-
Net::HTTP.new('localhost', VCR::SinatraApp.port).request(Net::HTTP::Get.new('/', {})) do |response|
|
37
|
-
return response
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
it "does not record headers for which Net::HTTP sets defaults near the end of the real request" do
|
42
|
-
VCR.should_receive(:record_http_interaction) do |interaction|
|
43
|
-
interaction.request.headers.should_not have_key('content-type')
|
44
|
-
interaction.request.headers.should_not have_key('host')
|
45
|
-
end
|
46
|
-
Net::HTTP.new('localhost', VCR::SinatraApp.port).send_request('POST', '/', '', { 'x-http-user' => 'me' })
|
47
|
-
end
|
48
|
-
|
49
|
-
it "records headers for which Net::HTTP usually sets defaults when the user manually sets their values" do
|
50
|
-
VCR.should_receive(:record_http_interaction) do |interaction|
|
51
|
-
interaction.request.headers['content-type'].should eq(['foo/bar'])
|
52
|
-
interaction.request.headers['host'].should eq(['my-example.com'])
|
53
|
-
end
|
54
|
-
Net::HTTP.new('localhost', VCR::SinatraApp.port).send_request('POST', '/', '', { 'Content-Type' => 'foo/bar', 'Host' => 'my-example.com' })
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'calls VCR.record_http_interaction' do
|
58
|
-
VCR.should_receive(:record_http_interaction).with(instance_of(VCR::HTTPInteraction))
|
59
|
-
Net::HTTP.get(uri)
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'calls #record_http_interaction only once, even when Net::HTTP internally recursively calls #request' do
|
63
|
-
VCR.should_receive(:record_http_interaction).once
|
64
|
-
Net::HTTP.new('localhost', VCR::SinatraApp.port).post('/', nil)
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'calls #record_http_interaction when Net::HTTP#request is called with a block with a return statement' do
|
68
|
-
VCR.should_receive(:record_http_interaction).once
|
69
|
-
perform_get_with_returning_block
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe 'a request that is registered with the http stubbing adapter' do
|
74
|
-
it 'does not call #record_http_interaction on the current cassette' do
|
75
|
-
VCR.http_stubbing_adapter.stub(:request_stubbed?).and_return(true)
|
76
|
-
VCR.should_receive(:record_http_interaction).never
|
77
|
-
Net::HTTP.get(uri)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe VCR::HttpStubbingAdapters::FakeWeb, :with_monkey_patches => :fakeweb do
|
4
|
-
it_behaves_like 'an http stubbing adapter', ['net/http'], [:method, :uri, :host, :path], :needs_net_http_extension
|
5
|
-
|
6
|
-
it_performs('version checking',
|
7
|
-
:valid => %w[ 1.3.0 1.3.1 1.3.99 ],
|
8
|
-
:too_low => %w[ 1.2.8 1.1.30 0.30.30 ],
|
9
|
-
:too_high => %w[ 1.4.0 1.10.0 2.0.0 ]
|
10
|
-
) do
|
11
|
-
before(:each) { @orig_version = FakeWeb::VERSION }
|
12
|
-
after(:each) { FakeWeb::VERSION = @orig_version }
|
13
|
-
|
14
|
-
# Cannot be regular method def as that raises a "dynamic constant assignment" error
|
15
|
-
define_method :stub_version do |version|
|
16
|
-
FakeWeb::VERSION = version
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe VCR::HttpStubbingAdapters::Faraday do
|
4
|
-
it_behaves_like 'an http stubbing adapter',
|
5
|
-
%w[ faraday-typhoeus faraday-net_http faraday-patron ],
|
6
|
-
[:method, :uri, :host, :path, :body, :headers],
|
7
|
-
:status_message_not_exposed, :does_not_support_rotating_responses
|
8
|
-
|
9
|
-
it_performs('version checking',
|
10
|
-
:valid => %w[ 0.6.0 0.6.10 ],
|
11
|
-
:too_low => %w[ 0.5.9 0.4.99 ],
|
12
|
-
:too_high => %w[ 0.7.0 1.0.0 ]
|
13
|
-
) do
|
14
|
-
before(:each) { @orig_version = Faraday::VERSION }
|
15
|
-
after(:each) { Faraday::VERSION = @orig_version }
|
16
|
-
|
17
|
-
# Cannot be regular method def as that raises a "dynamic constant assignment" error
|
18
|
-
define_method :stub_version do |version|
|
19
|
-
::Faraday::VERSION = version
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when some request have been stubbed' do
|
24
|
-
subject { described_class }
|
25
|
-
let(:request_1) { VCR::Request.new(:get, 'http://foo.com') }
|
26
|
-
let(:request_2) { VCR::Request.new(:get, 'http://bazz.com') }
|
27
|
-
let(:match_attributes) { [:method, :uri] }
|
28
|
-
|
29
|
-
def stubbed_response_for(request)
|
30
|
-
subject.stubbed_response_for(request)
|
31
|
-
end
|
32
|
-
|
33
|
-
before(:each) do
|
34
|
-
subject.stub_requests(
|
35
|
-
[
|
36
|
-
VCR::HTTPInteraction.new(request_1, :response_1),
|
37
|
-
VCR::HTTPInteraction.new(request_1, :response_2),
|
38
|
-
], match_attributes
|
39
|
-
)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_stubbed_responses
|
43
|
-
stubbed_response_for(request_1).should eq(:response_1)
|
44
|
-
stubbed_response_for(request_1).should eq(:response_2)
|
45
|
-
stubbed_response_for(request_1).should eq(:response_2)
|
46
|
-
stubbed_response_for(request_1).should eq(:response_2)
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '.stubbed_response_for' do
|
50
|
-
it 'returns nil when there is no matching response' do
|
51
|
-
stubbed_response_for(request_2).should be_nil
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'dequeues each response and continues to return the last one' do
|
55
|
-
test_stubbed_responses
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe '.restore_stubs_checkpoints' do
|
60
|
-
let(:cassette_1) { VCR::Cassette.new('1') }
|
61
|
-
|
62
|
-
before(:each) do
|
63
|
-
subject.create_stubs_checkpoint(cassette_1)
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'restores the queues to the checkpoint state when a queue has additional responses' do
|
67
|
-
subject.stub_requests( [
|
68
|
-
VCR::HTTPInteraction.new(request_1, :response_3),
|
69
|
-
], match_attributes)
|
70
|
-
|
71
|
-
subject.restore_stubs_checkpoint(cassette_1)
|
72
|
-
test_stubbed_responses
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|