vcr 3.0.3 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +5 -5
  2. data/lib/vcr/cassette/erb_renderer.rb +4 -2
  3. data/lib/vcr/cassette/http_interaction_list.rb +14 -9
  4. data/lib/vcr/cassette/migrator.rb +5 -6
  5. data/lib/vcr/cassette/persisters/file_system.rb +9 -1
  6. data/lib/vcr/cassette/serializers/compressed.rb +2 -2
  7. data/lib/vcr/cassette/serializers/json.rb +14 -8
  8. data/lib/vcr/cassette/serializers/psych.rb +10 -2
  9. data/lib/vcr/cassette/serializers/syck.rb +7 -1
  10. data/lib/vcr/cassette/serializers/yaml.rb +14 -2
  11. data/lib/vcr/cassette/serializers.rb +10 -0
  12. data/lib/vcr/cassette.rb +50 -15
  13. data/lib/vcr/configuration.rb +20 -8
  14. data/lib/vcr/deprecations.rb +0 -62
  15. data/lib/vcr/errors.rb +17 -12
  16. data/lib/vcr/library_hooks/excon.rb +8 -0
  17. data/lib/vcr/library_hooks/typhoeus.rb +91 -79
  18. data/lib/vcr/library_hooks/webmock.rb +2 -11
  19. data/lib/vcr/linked_cassette.rb +4 -4
  20. data/lib/vcr/middleware/excon.rb +1 -1
  21. data/lib/vcr/middleware/faraday.rb +10 -1
  22. data/lib/vcr/request_ignorer.rb +8 -1
  23. data/lib/vcr/request_matcher_registry.rb +3 -3
  24. data/lib/vcr/structs.rb +48 -32
  25. data/lib/vcr/test_frameworks/cucumber.rb +16 -5
  26. data/lib/vcr/test_frameworks/rspec.rb +34 -22
  27. data/lib/vcr/util/hooks.rb +1 -0
  28. data/lib/vcr/util/internet_connection.rb +15 -21
  29. data/lib/vcr/version.rb +2 -2
  30. data/lib/vcr.rb +52 -2
  31. metadata +45 -272
  32. data/features/CHANGELOG.md +0 -710
  33. data/features/CONTRIBUTING.md +0 -26
  34. data/features/LICENSE.md +0 -20
  35. data/features/README.md +0 -339
  36. data/features/Upgrade.md +0 -289
  37. data/features/about_these_examples.md +0 -18
  38. data/features/cassettes/allow_unused_http_interactions.feature +0 -100
  39. data/features/cassettes/automatic_re_recording.feature +0 -72
  40. data/features/cassettes/decompress.feature +0 -74
  41. data/features/cassettes/dynamic_erb.feature +0 -100
  42. data/features/cassettes/exclusive.feature +0 -126
  43. data/features/cassettes/format.feature +0 -411
  44. data/features/cassettes/freezing_time.feature +0 -68
  45. data/features/cassettes/naming.feature +0 -28
  46. data/features/cassettes/no_cassette.feature +0 -152
  47. data/features/cassettes/update_content_length_header.feature +0 -112
  48. data/features/configuration/allow_http_connections_when_no_cassette.feature +0 -55
  49. data/features/configuration/cassette_library_dir.feature +0 -31
  50. data/features/configuration/debug_logging.feature +0 -58
  51. data/features/configuration/default_cassette_options.feature +0 -100
  52. data/features/configuration/filter_sensitive_data.feature +0 -153
  53. data/features/configuration/hook_into.feature +0 -172
  54. data/features/configuration/ignore_request.feature +0 -192
  55. data/features/configuration/preserve_exact_body_bytes.feature +0 -108
  56. data/features/configuration/query_parser.feature +0 -84
  57. data/features/configuration/uri_parser.feature +0 -93
  58. data/features/getting_started.md +0 -82
  59. data/features/hooks/after_http_request.feature +0 -58
  60. data/features/hooks/around_http_request.feature +0 -57
  61. data/features/hooks/before_http_request.feature +0 -63
  62. data/features/hooks/before_playback.feature +0 -184
  63. data/features/hooks/before_record.feature +0 -172
  64. data/features/http_libraries/em_http_request.feature +0 -250
  65. data/features/http_libraries/net_http.feature +0 -179
  66. data/features/middleware/faraday.feature +0 -56
  67. data/features/middleware/rack.feature +0 -92
  68. data/features/record_modes/all.feature +0 -82
  69. data/features/record_modes/new_episodes.feature +0 -79
  70. data/features/record_modes/none.feature +0 -72
  71. data/features/record_modes/once.feature +0 -95
  72. data/features/request_matching/README.md +0 -30
  73. data/features/request_matching/body.feature +0 -91
  74. data/features/request_matching/body_as_json.feature +0 -90
  75. data/features/request_matching/custom_matcher.feature +0 -135
  76. data/features/request_matching/headers.feature +0 -85
  77. data/features/request_matching/host.feature +0 -95
  78. data/features/request_matching/identical_request_sequence.feature +0 -89
  79. data/features/request_matching/method.feature +0 -96
  80. data/features/request_matching/path.feature +0 -96
  81. data/features/request_matching/playback_repeats.feature +0 -98
  82. data/features/request_matching/query.feature +0 -97
  83. data/features/request_matching/uri.feature +0 -94
  84. data/features/request_matching/uri_without_param.feature +0 -101
  85. data/features/step_definitions/cli_steps.rb +0 -199
  86. data/features/support/env.rb +0 -46
  87. data/features/support/http_lib_filters.rb +0 -46
  88. data/features/test_frameworks/cucumber.feature +0 -211
  89. data/features/test_frameworks/rspec_macro.feature +0 -81
  90. data/features/test_frameworks/rspec_metadata.feature +0 -150
  91. data/features/test_frameworks/test_unit.feature +0 -49
  92. data/lib/vcr/extensions/net_http_response.rb +0 -36
  93. data/lib/vcr/library_hooks/fakeweb.rb +0 -197
  94. data/lib/vcr/library_hooks/typhoeus_0.4.rb +0 -103
  95. data/spec/acceptance/concurrency_spec.rb +0 -51
  96. data/spec/acceptance/threading_spec.rb +0 -34
  97. data/spec/fixtures/cassette_spec/1_x_cassette.yml +0 -110
  98. data/spec/fixtures/cassette_spec/empty.yml +0 -0
  99. data/spec/fixtures/cassette_spec/example.yml +0 -111
  100. data/spec/fixtures/cassette_spec/with_localhost_requests.yml +0 -111
  101. data/spec/fixtures/fake_example_responses.yml +0 -110
  102. data/spec/fixtures/match_requests_on.yml +0 -187
  103. data/spec/lib/vcr/cassette/erb_renderer_spec.rb +0 -53
  104. data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +0 -295
  105. data/spec/lib/vcr/cassette/migrator_spec.rb +0 -196
  106. data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +0 -75
  107. data/spec/lib/vcr/cassette/persisters_spec.rb +0 -39
  108. data/spec/lib/vcr/cassette/serializers_spec.rb +0 -182
  109. data/spec/lib/vcr/cassette_spec.rb +0 -618
  110. data/spec/lib/vcr/configuration_spec.rb +0 -326
  111. data/spec/lib/vcr/deprecations_spec.rb +0 -85
  112. data/spec/lib/vcr/errors_spec.rb +0 -178
  113. data/spec/lib/vcr/extensions/net_http_response_spec.rb +0 -86
  114. data/spec/lib/vcr/library_hooks/excon_spec.rb +0 -104
  115. data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +0 -169
  116. data/spec/lib/vcr/library_hooks/faraday_spec.rb +0 -68
  117. data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +0 -36
  118. data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +0 -162
  119. data/spec/lib/vcr/library_hooks/webmock_spec.rb +0 -117
  120. data/spec/lib/vcr/library_hooks_spec.rb +0 -51
  121. data/spec/lib/vcr/middleware/faraday_spec.rb +0 -181
  122. data/spec/lib/vcr/middleware/rack_spec.rb +0 -115
  123. data/spec/lib/vcr/request_ignorer_spec.rb +0 -70
  124. data/spec/lib/vcr/request_matcher_registry_spec.rb +0 -345
  125. data/spec/lib/vcr/structs_spec.rb +0 -732
  126. data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +0 -107
  127. data/spec/lib/vcr/test_frameworks/rspec_spec.rb +0 -94
  128. data/spec/lib/vcr/util/hooks_spec.rb +0 -158
  129. data/spec/lib/vcr/util/internet_connection_spec.rb +0 -37
  130. data/spec/lib/vcr/util/version_checker_spec.rb +0 -31
  131. data/spec/lib/vcr/version_spec.rb +0 -27
  132. data/spec/lib/vcr_spec.rb +0 -354
  133. data/spec/monkey_patches.rb +0 -186
  134. data/spec/spec_helper.rb +0 -63
  135. data/spec/support/configuration_stubbing.rb +0 -8
  136. data/spec/support/cucumber_helpers.rb +0 -39
  137. data/spec/support/fixnum_extension.rb +0 -10
  138. data/spec/support/http_library_adapters.rb +0 -289
  139. data/spec/support/limited_uri.rb +0 -21
  140. data/spec/support/ruby_interpreter.rb +0 -7
  141. data/spec/support/shared_example_groups/excon.rb +0 -63
  142. data/spec/support/shared_example_groups/hook_into_http_library.rb +0 -594
  143. data/spec/support/shared_example_groups/request_hooks.rb +0 -59
  144. data/spec/support/sinatra_app.rb +0 -86
  145. data/spec/support/vcr_localhost_server.rb +0 -76
  146. data/spec/support/vcr_stub_helpers.rb +0 -17
@@ -1,104 +0,0 @@
1
- require 'spec_helper'
2
- require 'support/shared_example_groups/excon'
3
-
4
- describe "Excon hook", :with_monkey_patches => :excon do
5
- after(:each) do
6
- ::Excon.stubs.clear
7
- ::Excon.defaults[:mock] = false
8
- end
9
-
10
- def directly_stub_request(method, url, response_body)
11
- ::Excon.defaults[:mock] = true
12
- ::Excon.stub({ :method => method, :url => url }, { :body => response_body })
13
- end
14
-
15
- it_behaves_like 'a hook into an HTTP library', :excon, 'excon', :status_message_not_exposed
16
-
17
- context "when the query is specified as a hash option" do
18
- let(:excon) { ::Excon.new("http://localhost:#{VCR::SinatraApp.port}/search") }
19
-
20
- it 'properly records and plays back the response' do
21
- allow(VCR).to receive(:real_http_connections_allowed?).and_return(true)
22
- recorded, played_back = [1, 2].map do
23
- VCR.use_cassette('excon_query', :record => :once) do
24
- excon.request(:method => :get, :query => { :q => 'Tolkien' }).body
25
- end
26
- end
27
-
28
- expect(recorded).to eq(played_back)
29
- expect(recorded).to eq('query: Tolkien')
30
- end
31
- end
32
-
33
- context "when Excon's expects and idempotent middlewares cause errors to be raised" do
34
- let(:excon) { ::Excon.new("http://localhost:#{VCR::SinatraApp.port}/404_not_200") }
35
-
36
- def make_request
37
- VCR.use_cassette('with_errors', :record => :once) do
38
- excon.request(:method => :get, :expects => [200], :idempotent => true).body
39
- end
40
- end
41
-
42
- it 'records and plays back properly' do
43
- expect { make_request }.to raise_error(Excon::Errors::NotFound)
44
- expect { make_request }.to raise_error(Excon::Errors::NotFound)
45
- end
46
- end
47
-
48
- include_examples "Excon streaming"
49
-
50
- context 'when Excon raises an error due to an unexpected response status' do
51
- before(:each) do
52
- allow(VCR).to receive(:real_http_connections_allowed?).and_return(true)
53
- end
54
-
55
- it 'still records properly' do
56
- expect(VCR).to receive(:record_http_interaction) do |interaction|
57
- expect(interaction.response.status.code).to eq(404)
58
- expect(interaction.response.body).to eq('404 not 200')
59
- end
60
-
61
- expect {
62
- Excon.get("http://localhost:#{VCR::SinatraApp.port}/404_not_200", :expects => 200)
63
- }.to raise_error(Excon::Errors::Error)
64
- end
65
-
66
- def error_raised_by
67
- yield
68
- rescue => e
69
- return e
70
- else
71
- raise "No error was raised"
72
- end
73
-
74
- it 'raises the same error class as excon itself raises' do
75
- real_error, stubbed_error = 2.times.map do
76
- error_raised_by do
77
- VCR.use_cassette('excon_error', :record => :once) do
78
- Excon.get("http://localhost:#{VCR::SinatraApp.port}/not_found", :expects => 200)
79
- end
80
- end
81
- end
82
-
83
- expect(stubbed_error.class).to be(real_error.class)
84
- end
85
-
86
- it_behaves_like "request hooks", :excon, :recordable do
87
- undef make_request
88
- def make_request(disabled = false)
89
- expect {
90
- Excon.get(request_url, :expects => 404)
91
- }.to raise_error(Excon::Errors::Error)
92
- end
93
- end
94
- end
95
-
96
- describe "VCR.configuration.after_library_hooks_loaded hook" do
97
- it 'disables the webmock excon adapter so it does not conflict with our typhoeus hook' do
98
- expect(::WebMock::HttpLibAdapters::ExconAdapter).to respond_to(:disable!)
99
- expect(::WebMock::HttpLibAdapters::ExconAdapter).to receive(:disable!)
100
- $excon_after_loaded_hook.conditionally_invoke
101
- end
102
- end
103
- end
104
-
@@ -1,169 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "FakeWeb hook", :with_monkey_patches => :fakeweb do
4
- after(:each) do
5
- ::FakeWeb.clean_registry
6
- end
7
-
8
- def disable_real_connections
9
- ::FakeWeb.allow_net_connect = false
10
- ::FakeWeb::NetConnectNotAllowedError
11
- end
12
-
13
- def enable_real_connections
14
- ::FakeWeb.allow_net_connect = true
15
- end
16
-
17
- def directly_stub_request(method, url, response_body)
18
- ::FakeWeb.register_uri(method, url, :body => response_body)
19
- end
20
-
21
- it_behaves_like 'a hook into an HTTP library', :fakeweb, 'net/http'
22
-
23
- describe "some specific Net::HTTP edge cases" do
24
- before(:each) do
25
- allow(VCR).to receive(:real_http_connections_allowed?).and_return(true)
26
- end
27
-
28
- it 'records the request body when using #post_form' do
29
- expect(VCR).to receive(:record_http_interaction) do |interaction|
30
- expect(interaction.request.body).to eq("q=ruby")
31
- end
32
-
33
- uri = URI("http://localhost:#{VCR::SinatraApp.port}/foo")
34
- Net::HTTP.post_form(uri, 'q' => 'ruby')
35
- end
36
-
37
- it "does not record headers for which Net::HTTP sets defaults near the end of the real request" do
38
- expect(VCR).to receive(:record_http_interaction) do |interaction|
39
- expect(interaction.request.headers).not_to have_key('content-type')
40
- expect(interaction.request.headers).not_to have_key('host')
41
- end
42
- Net::HTTP.new('localhost', VCR::SinatraApp.port).send_request('POST', '/', '', { 'x-http-user' => 'me' })
43
- end
44
-
45
- it "records headers for which Net::HTTP usually sets defaults when the user manually sets their values" do
46
- expect(VCR).to receive(:record_http_interaction) do |interaction|
47
- expect(interaction.request.headers['content-type']).to eq(['foo/bar'])
48
- expect(interaction.request.headers['host']).to eq(['my-example.com'])
49
- end
50
- Net::HTTP.new('localhost', VCR::SinatraApp.port).send_request('POST', '/', '', { 'Content-Type' => 'foo/bar', 'Host' => 'my-example.com' })
51
- end
52
-
53
- def perform_get_with_returning_block
54
- Net::HTTP.new('localhost', VCR::SinatraApp.port).request(Net::HTTP::Get.new('/', {})) do |response|
55
- return response
56
- end
57
- end
58
-
59
- it 'records the interaction when Net::HTTP#request is called with a block with a return statement' do
60
- expect(VCR).to receive(:record_http_interaction).once
61
- expect(perform_get_with_returning_block.body).to eq("GET to root")
62
- end
63
-
64
- def make_post_request
65
- Net::HTTP.new('localhost', VCR::SinatraApp.port).post('/record-and-playback', '')
66
- end
67
-
68
- it 'records the interaction only once, even when Net::HTTP internally recursively calls #request' do
69
- expect(VCR).to receive(:record_http_interaction).once
70
- make_post_request
71
- end
72
-
73
- it 'properly returns the response body for a post request when recording, stubbing or ignoring the request' do
74
- recorded_body = nil
75
- VCR.use_cassette("new_cassette", :record => :once) do
76
- recorded_body = make_post_request.body
77
- expect(recorded_body).to match(/Response \d+/)
78
- end
79
-
80
- VCR.use_cassette("new_cassette", :record => :once) do
81
- expect(make_post_request.body).to eq(recorded_body)
82
- end
83
-
84
- VCR.configuration.ignore_request { |r| true }
85
- ignored_body = make_post_request.body
86
- expect(ignored_body).not_to eq(recorded_body)
87
- expect(ignored_body).to match(/Response \d+/)
88
- end
89
-
90
- context 'when the same Net::HTTP request object is used twice' do
91
- let(:uri) { URI("http://localhost:#{VCR::SinatraApp.port}/foo") }
92
- let(:http) { Net::HTTP.new(uri.host, uri.port) }
93
-
94
- it 'raises an UnhandledHTTPRequestError when using a cassette that only recorded one request' do
95
- VCR.use_cassette("new_cassette", :record => :once) do
96
- request = Net::HTTP::Get.new(uri.request_uri)
97
- http.request(request)
98
- end
99
-
100
- VCR.use_cassette("new_cassette", :record => :once) do
101
- request = Net::HTTP::Get.new(uri.request_uri)
102
- http.request(request)
103
- http.request(request)
104
- end
105
- end
106
- end
107
- end
108
-
109
- describe "VCR.configuration.after_library_hooks_loaded hook" do
110
- let(:run_hook) { $fakeweb_after_loaded_hook.conditionally_invoke }
111
-
112
- context 'when WebMock has been loaded' do
113
- before(:each) do
114
- expect(defined?(WebMock)).to be_truthy
115
- end
116
-
117
- it 'raises an error since FakeWeb and WebMock cannot both be used simultaneously' do
118
- expect { run_hook }.to raise_error(ArgumentError, /cannot use both/)
119
- end
120
- end
121
-
122
- context 'when WebMock has not been loaded' do
123
- let!(:orig_webmock_constant) { ::WebMock }
124
- before(:each) { Object.send(:remove_const, :WebMock) }
125
- after(:each) { ::WebMock = orig_webmock_constant }
126
-
127
- it 'does not raise an error' do
128
- run_hook # should not raise an error
129
- end
130
-
131
- it "warns about FakeWeb deprecation" do
132
- expect(::Kernel).to receive(:warn).with("WARNING: VCR's FakeWeb integration is deprecated and will be removed in VCR 4.0.")
133
- run_hook
134
- end
135
- end
136
- end
137
-
138
- describe "when a SocketError occurs" do
139
- before(:each) do
140
- VCR.configuration.ignore_request { |r| true }
141
- end
142
-
143
- it_behaves_like "request hooks", :fakeweb, :ignored do
144
- undef assert_expected_response
145
- def assert_expected_response(response)
146
- expect(response).to be_nil
147
- end
148
-
149
- undef make_request
150
- def make_request(disabled = false)
151
- allow_any_instance_of(::Net::HTTP).to receive(:request_without_vcr).and_raise(SocketError)
152
- expect {
153
- ::Net::HTTP.get_response(URI(request_url))
154
- }.to raise_error(SocketError)
155
- end
156
- end
157
- end
158
-
159
- describe "when VCR is turned off" do
160
- it 'allows white listed connections' do
161
- ::FakeWeb.allow_net_connect = %r[localhost]
162
-
163
- VCR.turn_off!
164
-
165
- uri = URI("http://localhost:#{VCR::SinatraApp.port}/foo")
166
- expect(Net::HTTP.get(uri)).to eq("FOO!")
167
- end
168
- end
169
- end
@@ -1,68 +0,0 @@
1
- require 'spec_helper'
2
- require 'vcr/library_hooks/faraday'
3
-
4
- describe "Faraday hook" do
5
- it 'inserts the VCR middleware just before the adapter' do
6
- conn = Faraday.new(:url => 'http://sushi.com') do |builder|
7
- builder.request :url_encoded
8
- builder.response :logger
9
- builder.adapter :net_http
10
- end
11
-
12
- conn.builder.lock!
13
- expect(conn.builder.handlers.last(2).map(&:klass)).to eq([
14
- VCR::Middleware::Faraday,
15
- Faraday::Adapter::NetHttp
16
- ])
17
- end
18
-
19
- it 'handles the case where no adapter is declared' do
20
- conn = Faraday.new
21
-
22
- conn.builder.lock!
23
- expect(conn.builder.handlers.last(2).map(&:klass)).to eq([
24
- VCR::Middleware::Faraday,
25
- Faraday::Adapter::NetHttp
26
- ])
27
- end
28
-
29
- it 'does nothing if the VCR middleware has already been included' do
30
- conn = Faraday.new(:url => 'http://sushi.com') do |builder|
31
- builder.use VCR::Middleware::Faraday
32
- builder.use Faraday::Response::Logger
33
- builder.use Faraday::Adapter::NetHttp
34
- end
35
-
36
- conn.builder.lock!
37
- expect(conn.builder.handlers.map(&:klass)).to eq([
38
- VCR::Middleware::Faraday,
39
- Faraday::Response::Logger,
40
- Faraday::Adapter::NetHttp
41
- ])
42
- end
43
-
44
- it 'prints a warning if the faraday connection stack contains a middleware after the HTTP adapter' do
45
- conn = Faraday.new(:url => 'http://sushi.com') do |builder|
46
- builder.use Faraday::Adapter::NetHttp
47
- builder.use Faraday::Response::Logger
48
- end
49
-
50
- expect(conn.builder).to receive(:warn).with(/Faraday::Response::Logger/)
51
- conn.builder.lock!
52
- end
53
-
54
- it 'gracefully handles the case where there is no explicit HTTP adapter' do
55
- conn = Faraday.new(:url => 'http://sushi.com') do |builder|
56
- builder.request :url_encoded
57
- builder.response :logger
58
- end
59
-
60
- conn.builder.lock!
61
- expect(conn.builder.handlers.map(&:klass)).to eq([
62
- Faraday::Request::UrlEncoded,
63
- Faraday::Response::Logger,
64
- VCR::Middleware::Faraday
65
- ])
66
- end
67
- end
68
-
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Typhoeus 0.4 hook", :with_monkey_patches => :typhoeus_0_4 do
4
- after(:each) do
5
- ::Typhoeus::Hydra.clear_stubs
6
- end
7
-
8
- def disable_real_connections
9
- ::Typhoeus::Hydra.allow_net_connect = false
10
- ::Typhoeus::Hydra::NetConnectNotAllowedError
11
- end
12
-
13
- def enable_real_connections
14
- ::Typhoeus::Hydra.allow_net_connect = true
15
- end
16
-
17
- def directly_stub_request(method, url, response_body)
18
- response = ::Typhoeus::Response.new(:code => 200, :body => response_body)
19
- ::Typhoeus::Hydra.stub(method, url).and_return(response)
20
- end
21
-
22
- it_behaves_like 'a hook into an HTTP library', :typhoeus, 'typhoeus 0.4'
23
-
24
- describe "VCR.configuration.after_library_hooks_loaded hook" do
25
- it 'disables the webmock typhoeus adapter so it does not conflict with our typhoeus hook' do
26
- expect(::WebMock::HttpLibAdapters::TyphoeusAdapter).to receive(:disable!)
27
- $typhoeus_after_loaded_hook.conditionally_invoke
28
- end
29
-
30
- it "warns about Typhoeus 0.4 deprecation" do
31
- expect(::Kernel).to receive(:warn).with("WARNING: VCR's Typhoeus 0.4 integration is deprecated and will be removed in VCR 3.0.")
32
- $typhoeus_0_4_after_loaded_hook.conditionally_invoke
33
- end
34
- end
35
- end if RUBY_INTERPRETER == :mri && ::Typhoeus::VERSION.to_f < 0.5
36
-
@@ -1,162 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Typhoeus hook", :with_monkey_patches => :typhoeus, :if => (RUBY_INTERPRETER == :mri) do
4
- after(:each) do
5
- ::Typhoeus::Expectation.clear
6
- end
7
-
8
- def disable_real_connections
9
- ::Typhoeus::Config.block_connection = true
10
- ::Typhoeus::Errors::NoStub
11
- end
12
-
13
- def enable_real_connections
14
- ::Typhoeus::Config.block_connection = false
15
- end
16
-
17
- def directly_stub_request(method, url, response_body)
18
- response = ::Typhoeus::Response.new(:code => 200, :body => response_body)
19
- ::Typhoeus.stub(url, :method => method).and_return(response)
20
- end
21
-
22
- it_behaves_like 'a hook into an HTTP library', :typhoeus, 'typhoeus'
23
-
24
- describe "VCR.configuration.after_library_hooks_loaded hook" do
25
- it 'disables the webmock typhoeus adapter so it does not conflict with our typhoeus hook' do
26
- expect(::WebMock::HttpLibAdapters::TyphoeusAdapter).to receive(:disable!)
27
- $typhoeus_after_loaded_hook.conditionally_invoke
28
- end
29
- end
30
-
31
- context 'when there are nested hydra queues' do
32
- def make_requests
33
- VCR.use_cassette("nested") do
34
- response_1 = response_2 = nil
35
-
36
- hydra = Typhoeus::Hydra.new
37
- request = Typhoeus::Request.new("http://localhost:#{VCR::SinatraApp.port}/")
38
-
39
- request.on_success do |r1|
40
- response_1 = r1
41
-
42
- nested = Typhoeus::Request.new("http://localhost:#{VCR::SinatraApp.port}/foo")
43
- nested.on_success { |r2| response_2 = r2 }
44
-
45
- hydra.queue(nested)
46
- end
47
-
48
- hydra.queue(request)
49
- hydra.run
50
-
51
- return body_for(response_1), body_for(response_2)
52
- end
53
- end
54
-
55
- def body_for(response)
56
- return :no_response if response.nil?
57
- response.body
58
- end
59
-
60
- it 'records and plays back properly' do
61
- recorded = make_requests
62
- played_back = make_requests
63
-
64
- expect(played_back).to eq(recorded)
65
- end
66
- end
67
-
68
- context "when used with a typhoeus-based faraday connection" do
69
- let(:base_url) { "http://localhost:#{VCR::SinatraApp.port}" }
70
-
71
- let(:conn) do
72
- Faraday.new(:url => base_url) do |faraday|
73
- faraday.adapter :typhoeus
74
- end
75
- end
76
-
77
- def get_response
78
- # Ensure faraday hook doesn't handle the request.
79
- VCR.library_hooks.exclusively_enabled(:typhoeus) do
80
- VCR.use_cassette("faraday") do
81
- conn.get("/")
82
- end
83
- end
84
- end
85
-
86
- it 'records and replays headers correctly' do
87
- recorded = get_response
88
- played_back = get_response
89
-
90
- expect(played_back.headers).to eq(recorded.headers)
91
- end
92
- end
93
-
94
- context 'when a request is made with a hash for the POST body' do
95
- def make_request
96
- VCR.use_cassette("hash_body") do
97
- Typhoeus::Request.post(
98
- "http://localhost:#{VCR::SinatraApp.port}/return-request-body",
99
- :body => { :foo => "17" }
100
- )
101
- end
102
- end
103
-
104
- it 'records and replays correctly' do
105
- recorded = make_request
106
- played_back = make_request
107
-
108
- expect(recorded.body).to eq("foo=17")
109
- expect(played_back.body).to eq(recorded.body)
110
- end
111
- end
112
-
113
- context '#effective_url' do
114
- ResponseValues = Struct.new(:status, :body, :effective_url)
115
-
116
- def url_for(path)
117
- "http://localhost:#{VCR::SinatraApp.port}#{path}"
118
- end
119
-
120
- def make_single_request(path, options = {})
121
- VCR.use_cassette('single') do |cassette|
122
- response = Typhoeus::Request.new(url_for(path), options).run
123
-
124
- yield cassette if block_given?
125
-
126
- ResponseValues.new(
127
- response.code,
128
- response.body,
129
- response.effective_url
130
- )
131
- end
132
- end
133
-
134
- it 'records and plays back properly' do
135
- recorded = make_single_request('/')
136
- played_back = make_single_request('/')
137
-
138
- expect(recorded.effective_url).to eq(url_for('/'))
139
- expect(played_back).to eq(recorded)
140
- end
141
-
142
- it 'falls back to the request url when it was not recorded (e.g. on VCR <= 2.5.0)' do
143
- make_single_request('/') do |cassette|
144
- cassette.new_recorded_interactions.each { |i| i.response.adapter_metadata.clear }
145
- end
146
-
147
- played_back = make_single_request('/')
148
- expect(played_back.effective_url).to eq(url_for('/'))
149
- end
150
-
151
- context "when following redirects" do
152
- it 'records and plays back properly' do
153
- recorded = make_single_request('/redirect-to-root', :followlocation => true)
154
- played_back = make_single_request('/redirect-to-root', :followlocation => true)
155
-
156
- expect(recorded.effective_url).to eq(url_for('/'))
157
- expect(played_back).to eq(recorded)
158
- end
159
- end
160
- end
161
- end
162
-
@@ -1,117 +0,0 @@
1
- require 'spec_helper'
2
- require 'support/shared_example_groups/excon'
3
-
4
- describe "WebMock hook", :with_monkey_patches => :webmock do
5
- after(:each) do
6
- ::WebMock.reset!
7
- end
8
-
9
- def disable_real_connections(options = {})
10
- ::WebMock.disable_net_connect!(options)
11
- ::WebMock::NetConnectNotAllowedError
12
- end
13
-
14
- def enable_real_connections
15
- ::WebMock.allow_net_connect!
16
- end
17
-
18
- def directly_stub_request(method, url, response_body)
19
- ::WebMock.stub_request(method, url).to_return(:body => response_body)
20
- end
21
-
22
- describe "our WebMock.after_request hook" do
23
- let(:webmock_request) { ::WebMock::RequestSignature.new(:get, "http://foo.com/", :body => "", :headers => {}) }
24
- let(:webmock_response) { ::WebMock::Response.new(:body => 'OK', :status => [200, '']) }
25
-
26
- def run_after_request_callback
27
- ::WebMock::CallbackRegistry.invoke_callbacks(
28
- { :real_request => true },
29
- webmock_request,
30
- webmock_response)
31
- end
32
-
33
- it 'removes the @__typed_vcr_request instance variable so as not to pollute the webmock object' do
34
- request = VCR::Request::Typed.new(VCR::Request, :ignored?)
35
- webmock_request.instance_variable_set(:@__typed_vcr_request, request)
36
-
37
- run_after_request_callback
38
- expect(webmock_request.instance_variables.map(&:to_sym)).not_to include(:@__typed_vcr_request)
39
- end
40
-
41
- context "when there'ss a bug and the request does not have the @__typed_vcr_request in the after_request callbacks" do
42
- let(:warner) { VCR::LibraryHooks::WebMock }
43
- before { allow(warner).to receive(:warn) }
44
-
45
- it 'records the HTTP interaction properly' do
46
- expect(VCR).to receive(:record_http_interaction) do |i|
47
- expect(i.request.uri).to eq("http://foo.com/")
48
- expect(i.response.body).to eq("OK")
49
- end
50
-
51
- run_after_request_callback
52
- end
53
-
54
- it 'invokes the after_http_request hook with an :unknown request' do
55
- request = nil
56
- VCR.configuration.after_http_request do |req, res|
57
- request = req
58
- end
59
-
60
- run_after_request_callback
61
- expect(request.uri).to eq("http://foo.com/")
62
- expect(request.type).to eq(:unknown)
63
- end
64
-
65
- it 'prints a warning' do
66
- expect(warner).to receive(:warn).at_least(:once).with(/bug.*after_request/)
67
-
68
- run_after_request_callback
69
- end
70
- end
71
- end
72
-
73
- http_libs = %w[net/http patron httpclient em-http-request curb typhoeus excon]
74
- http_libs.each do |lib|
75
- other = []
76
- other << :status_message_not_exposed if lib == 'excon'
77
- it_behaves_like 'a hook into an HTTP library', :webmock, lib, *other do
78
- if lib == 'net/http'
79
- def normalize_request_headers(headers)
80
- headers.merge(DEFAULT_REQUEST_HEADERS)
81
- end
82
- end
83
- end
84
-
85
- http_lib_unsupported = (RUBY_INTERPRETER != :mri && lib =~ /(typhoeus|curb|patron|em-http)/)
86
-
87
- adapter_module = HTTP_LIBRARY_ADAPTERS.fetch(lib)
88
- describe "using #{adapter_module.http_library_name}", :unless => http_lib_unsupported do
89
- include adapter_module
90
-
91
- let!(:request_url) { "http://localhost:#{VCR::SinatraApp.port}/foo" }
92
-
93
- context 'when real connections are disabled and VCR is turned off' do
94
- it 'can allow connections to localhost' do
95
- VCR.turn_off!
96
- disable_real_connections(:allow_localhost => true)
97
-
98
- expect {
99
- make_http_request(:get, request_url)
100
- }.to_not raise_error
101
- end
102
-
103
- it 'can allow connections to matching urls' do
104
- VCR.turn_off!
105
- disable_real_connections(:allow => /foo/)
106
-
107
- expect {
108
- make_http_request(:get, request_url)
109
- }.to_not raise_error
110
- end
111
- end
112
- end
113
- end
114
-
115
- it_behaves_like "Excon streaming"
116
- end
117
-