vcr 3.0.2 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/vcr.rb +33 -1
- data/lib/vcr/cassette.rb +47 -12
- data/lib/vcr/cassette/http_interaction_list.rb +14 -9
- data/lib/vcr/cassette/migrator.rb +0 -5
- 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 +7 -7
- data/lib/vcr/cassette/serializers/psych.rb +3 -1
- data/lib/vcr/cassette/serializers/yaml.rb +3 -1
- data/lib/vcr/configuration.rb +20 -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 +37 -8
- data/lib/vcr/linked_cassette.rb +4 -4
- data/lib/vcr/middleware/faraday.rb +10 -1
- data/lib/vcr/request_ignorer.rb +4 -1
- data/lib/vcr/request_matcher_registry.rb +1 -1
- data/lib/vcr/structs.rb +48 -32
- data/lib/vcr/test_frameworks/cucumber.rb +4 -4
- data/lib/vcr/test_frameworks/rspec.rb +12 -3
- data/lib/vcr/util/hooks.rb +1 -0
- data/lib/vcr/util/internet_connection.rb +15 -21
- data/lib/vcr/version.rb +1 -1
- metadata +36 -263
- data/features/CHANGELOG.md +0 -1
- data/features/CONTRIBUTING.md +0 -1
- data/features/LICENSE.md +0 -1
- data/features/README.md +0 -1
- data/features/Upgrade.md +0 -1
- data/features/about_these_examples.md +0 -18
- data/features/cassettes/allow_unused_http_interactions.feature +0 -100
- data/features/cassettes/automatic_re_recording.feature +0 -72
- data/features/cassettes/decompress.feature +0 -74
- data/features/cassettes/dynamic_erb.feature +0 -100
- data/features/cassettes/exclusive.feature +0 -126
- data/features/cassettes/format.feature +0 -411
- data/features/cassettes/freezing_time.feature +0 -68
- data/features/cassettes/naming.feature +0 -28
- data/features/cassettes/no_cassette.feature +0 -152
- data/features/cassettes/update_content_length_header.feature +0 -112
- data/features/configuration/allow_http_connections_when_no_cassette.feature +0 -55
- data/features/configuration/cassette_library_dir.feature +0 -31
- data/features/configuration/debug_logging.feature +0 -58
- data/features/configuration/default_cassette_options.feature +0 -100
- data/features/configuration/filter_sensitive_data.feature +0 -153
- data/features/configuration/hook_into.feature +0 -172
- data/features/configuration/ignore_request.feature +0 -192
- data/features/configuration/preserve_exact_body_bytes.feature +0 -108
- data/features/configuration/query_parser.feature +0 -84
- data/features/configuration/uri_parser.feature +0 -93
- data/features/getting_started.md +0 -82
- data/features/hooks/after_http_request.feature +0 -58
- data/features/hooks/around_http_request.feature +0 -57
- data/features/hooks/before_http_request.feature +0 -63
- data/features/hooks/before_playback.feature +0 -184
- data/features/hooks/before_record.feature +0 -172
- data/features/http_libraries/em_http_request.feature +0 -250
- data/features/http_libraries/net_http.feature +0 -179
- data/features/middleware/faraday.feature +0 -56
- data/features/middleware/rack.feature +0 -92
- data/features/record_modes/all.feature +0 -82
- data/features/record_modes/new_episodes.feature +0 -79
- data/features/record_modes/none.feature +0 -72
- data/features/record_modes/once.feature +0 -95
- data/features/request_matching/README.md +0 -30
- data/features/request_matching/body.feature +0 -91
- data/features/request_matching/body_as_json.feature +0 -90
- data/features/request_matching/custom_matcher.feature +0 -135
- data/features/request_matching/headers.feature +0 -85
- data/features/request_matching/host.feature +0 -95
- data/features/request_matching/identical_request_sequence.feature +0 -89
- data/features/request_matching/method.feature +0 -96
- data/features/request_matching/path.feature +0 -96
- data/features/request_matching/playback_repeats.feature +0 -98
- data/features/request_matching/query.feature +0 -97
- data/features/request_matching/uri.feature +0 -94
- data/features/request_matching/uri_without_param.feature +0 -101
- data/features/step_definitions/cli_steps.rb +0 -199
- data/features/support/env.rb +0 -46
- data/features/support/http_lib_filters.rb +0 -46
- data/features/test_frameworks/cucumber.feature +0 -211
- data/features/test_frameworks/rspec_macro.feature +0 -81
- data/features/test_frameworks/rspec_metadata.feature +0 -150
- data/features/test_frameworks/test_unit.feature +0 -49
- data/lib/vcr/extensions/net_http_response.rb +0 -36
- data/lib/vcr/library_hooks/fakeweb.rb +0 -197
- data/spec/acceptance/concurrency_spec.rb +0 -51
- data/spec/acceptance/threading_spec.rb +0 -34
- data/spec/fixtures/cassette_spec/1_x_cassette.yml +0 -110
- data/spec/fixtures/cassette_spec/empty.yml +0 -0
- data/spec/fixtures/cassette_spec/example.yml +0 -111
- data/spec/fixtures/cassette_spec/with_localhost_requests.yml +0 -111
- data/spec/fixtures/fake_example_responses.yml +0 -110
- data/spec/fixtures/match_requests_on.yml +0 -187
- data/spec/lib/vcr/cassette/erb_renderer_spec.rb +0 -53
- data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +0 -295
- data/spec/lib/vcr/cassette/migrator_spec.rb +0 -196
- data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +0 -75
- data/spec/lib/vcr/cassette/persisters_spec.rb +0 -39
- data/spec/lib/vcr/cassette/serializers_spec.rb +0 -182
- data/spec/lib/vcr/cassette_spec.rb +0 -618
- data/spec/lib/vcr/configuration_spec.rb +0 -326
- data/spec/lib/vcr/deprecations_spec.rb +0 -85
- data/spec/lib/vcr/errors_spec.rb +0 -178
- data/spec/lib/vcr/extensions/net_http_response_spec.rb +0 -86
- data/spec/lib/vcr/library_hooks/excon_spec.rb +0 -104
- data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +0 -169
- data/spec/lib/vcr/library_hooks/faraday_spec.rb +0 -68
- data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +0 -36
- data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +0 -162
- data/spec/lib/vcr/library_hooks/webmock_spec.rb +0 -117
- data/spec/lib/vcr/library_hooks_spec.rb +0 -51
- data/spec/lib/vcr/middleware/faraday_spec.rb +0 -181
- data/spec/lib/vcr/middleware/rack_spec.rb +0 -115
- data/spec/lib/vcr/request_ignorer_spec.rb +0 -70
- data/spec/lib/vcr/request_matcher_registry_spec.rb +0 -345
- data/spec/lib/vcr/structs_spec.rb +0 -732
- data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +0 -107
- data/spec/lib/vcr/test_frameworks/rspec_spec.rb +0 -94
- data/spec/lib/vcr/util/hooks_spec.rb +0 -158
- data/spec/lib/vcr/util/internet_connection_spec.rb +0 -37
- data/spec/lib/vcr/util/version_checker_spec.rb +0 -31
- data/spec/lib/vcr/version_spec.rb +0 -27
- data/spec/lib/vcr_spec.rb +0 -354
- data/spec/monkey_patches.rb +0 -186
- data/spec/spec_helper.rb +0 -63
- data/spec/support/configuration_stubbing.rb +0 -8
- data/spec/support/cucumber_helpers.rb +0 -39
- data/spec/support/fixnum_extension.rb +0 -10
- data/spec/support/http_library_adapters.rb +0 -289
- data/spec/support/limited_uri.rb +0 -21
- data/spec/support/ruby_interpreter.rb +0 -7
- data/spec/support/shared_example_groups/excon.rb +0 -63
- data/spec/support/shared_example_groups/hook_into_http_library.rb +0 -594
- data/spec/support/shared_example_groups/request_hooks.rb +0 -59
- data/spec/support/sinatra_app.rb +0 -86
- data/spec/support/vcr_localhost_server.rb +0 -76
- data/spec/support/vcr_stub_helpers.rb +0 -17
@@ -1,153 +0,0 @@
|
|
1
|
-
Feature: Filter sensitive data
|
2
|
-
|
3
|
-
Note: this config option is also available as `define_cassette_placeholder`
|
4
|
-
to reflect the fact that it is useful for more than just sensitive data.
|
5
|
-
|
6
|
-
The `filter_sensitive_data` configuration option can be used to prevent
|
7
|
-
sensitive data from being written to your cassette files. This may be
|
8
|
-
important if you commit your cassettes files to source control and do
|
9
|
-
not want your sensitive data exposed. Pass the following arguments to
|
10
|
-
`filter_sensitive_data`:
|
11
|
-
|
12
|
-
- A substitution string. This is the string that will be written to
|
13
|
-
the cassettte file as a placeholder. It should be unique and you
|
14
|
-
may want to wrap it in special characters like `{ }` or `< >`.
|
15
|
-
- A symbol specifying a tag (optional). If a tag is given, the
|
16
|
-
filtering will only be applied to cassettes with the given tag.
|
17
|
-
- A block. The block should return the sensitive text that you want
|
18
|
-
replaced with the substitution string. If your block accepts an
|
19
|
-
argument, the HTTP interaction will be yielded so that you can
|
20
|
-
dynamically specify the sensitive text based on the interaction
|
21
|
-
(see the last scenario for an example of this).
|
22
|
-
|
23
|
-
When the interactions are replayed, the sensitive text will replace the
|
24
|
-
substitution string so that the interaction will be identical to what was
|
25
|
-
originally recorded.
|
26
|
-
|
27
|
-
You can specify as many filterings as you want.
|
28
|
-
|
29
|
-
Scenario: Multiple filterings
|
30
|
-
Given a file named "filtering.rb" with:
|
31
|
-
"""ruby
|
32
|
-
if ARGV.include?('--with-server')
|
33
|
-
$server = start_sinatra_app do
|
34
|
-
get('/') { "Hello World" }
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
require 'vcr'
|
39
|
-
|
40
|
-
VCR.configure do |c|
|
41
|
-
c.hook_into :webmock
|
42
|
-
c.cassette_library_dir = 'cassettes'
|
43
|
-
c.filter_sensitive_data('<GREETING>') { 'Hello' }
|
44
|
-
c.filter_sensitive_data('<LOCATION>') { 'World' }
|
45
|
-
end
|
46
|
-
|
47
|
-
VCR.use_cassette('filtering') do
|
48
|
-
response = Net::HTTP.get_response('localhost', '/', $server ? $server.port : 0)
|
49
|
-
puts "Response: #{response.body}"
|
50
|
-
end
|
51
|
-
"""
|
52
|
-
When I run `ruby filtering.rb --with-server`
|
53
|
-
Then the output should contain "Response: Hello World"
|
54
|
-
And the file "cassettes/filtering.yml" should contain "<GREETING> <LOCATION>"
|
55
|
-
And the file "cassettes/filtering.yml" should not contain "Hello"
|
56
|
-
And the file "cassettes/filtering.yml" should not contain "World"
|
57
|
-
|
58
|
-
When I run `ruby filtering.rb`
|
59
|
-
Then the output should contain "Hello World"
|
60
|
-
|
61
|
-
Scenario: Filter tagged cassettes
|
62
|
-
Given a file named "tagged_filtering.rb" with:
|
63
|
-
"""ruby
|
64
|
-
if ARGV.include?('--with-server')
|
65
|
-
response_count = 0
|
66
|
-
$server = start_sinatra_app do
|
67
|
-
get('/') { "Hello World #{response_count += 1 }" }
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
require 'vcr'
|
72
|
-
|
73
|
-
VCR.configure do |c|
|
74
|
-
c.hook_into :webmock
|
75
|
-
c.cassette_library_dir = 'cassettes'
|
76
|
-
c.filter_sensitive_data('<LOCATION>', :my_tag) { 'World' }
|
77
|
-
end
|
78
|
-
|
79
|
-
VCR.use_cassette('tagged', :tag => :my_tag) do
|
80
|
-
response = Net::HTTP.get_response('localhost', '/', $server ? $server.port : 0)
|
81
|
-
puts "Tagged Response: #{response.body}"
|
82
|
-
end
|
83
|
-
|
84
|
-
VCR.use_cassette('untagged', :record => :new_episodes) do
|
85
|
-
response = Net::HTTP.get_response('localhost', '/', $server ? $server.port : 0)
|
86
|
-
puts "Untagged Response: #{response.body}"
|
87
|
-
end
|
88
|
-
"""
|
89
|
-
When I run `ruby tagged_filtering.rb --with-server`
|
90
|
-
Then the output should contain each of the following:
|
91
|
-
| Tagged Response: Hello World 1 |
|
92
|
-
| Untagged Response: Hello World 2 |
|
93
|
-
And the file "cassettes/tagged.yml" should contain "Hello <LOCATION> 1"
|
94
|
-
And the file "cassettes/untagged.yml" should contain "Hello World 2"
|
95
|
-
|
96
|
-
When I run `ruby tagged_filtering.rb`
|
97
|
-
Then the output should contain each of the following:
|
98
|
-
| Tagged Response: Hello World 1 |
|
99
|
-
| Untagged Response: Hello World 2 |
|
100
|
-
|
101
|
-
Scenario: Filter dynamic data based on yielded HTTP interaction
|
102
|
-
Given a file named "dynamic_filtering.rb" with:
|
103
|
-
"""ruby
|
104
|
-
include_http_adapter_for('net/http')
|
105
|
-
|
106
|
-
if ARGV.include?('--with-server')
|
107
|
-
$server = start_sinatra_app do
|
108
|
-
helpers do
|
109
|
-
def request_header_for(header_key_fragment)
|
110
|
-
key = env.keys.find { |k| k =~ /#{header_key_fragment}/i }
|
111
|
-
env[key]
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
get('/') { "#{request_header_for('username')}/#{request_header_for('password')}" }
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
require 'vcr'
|
120
|
-
|
121
|
-
USER_PASSWORDS = {
|
122
|
-
'john.doe' => 'monkey',
|
123
|
-
'jane.doe' => 'cheetah'
|
124
|
-
}
|
125
|
-
|
126
|
-
VCR.configure do |c|
|
127
|
-
c.hook_into :webmock
|
128
|
-
c.cassette_library_dir = 'cassettes'
|
129
|
-
c.filter_sensitive_data('<PASSWORD>') do |interaction|
|
130
|
-
USER_PASSWORDS[interaction.request.headers['X-Http-Username'].first]
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
VCR.use_cassette('example', :match_requests_on => [:method, :uri, :headers]) do
|
135
|
-
port = $server ? $server.port : 0
|
136
|
-
puts "Response: " + response_body_for(
|
137
|
-
:get, "http://localhost:#{port}/", nil,
|
138
|
-
'X-Http-Username' => 'john.doe',
|
139
|
-
'X-Http-Password' => USER_PASSWORDS['john.doe']
|
140
|
-
)
|
141
|
-
end
|
142
|
-
"""
|
143
|
-
When I run `ruby dynamic_filtering.rb --with-server`
|
144
|
-
Then the output should contain "john.doe/monkey"
|
145
|
-
And the file "cassettes/example.yml" should contain "john.doe/<PASSWORD>"
|
146
|
-
And the file "cassettes/example.yml" should contain a YAML fragment like:
|
147
|
-
"""
|
148
|
-
X-Http-Password:
|
149
|
-
- <PASSWORD>
|
150
|
-
"""
|
151
|
-
|
152
|
-
When I run `ruby dynamic_filtering.rb`
|
153
|
-
Then the output should contain "john.doe/monkey"
|
@@ -1,172 +0,0 @@
|
|
1
|
-
Feature: hook_into
|
2
|
-
|
3
|
-
The `hook_into` configuration option determines how VCR hooks into the
|
4
|
-
HTTP requests to record and replay them. There are currently 4 valid
|
5
|
-
options which support many different HTTP libraries:
|
6
|
-
|
7
|
-
- :webmock can be used to hook into requests from:
|
8
|
-
- Net::HTTP
|
9
|
-
- HTTPClient
|
10
|
-
- Patron
|
11
|
-
- Curb (Curl::Easy, but not Curl::Multi)
|
12
|
-
- EM HTTP Request
|
13
|
-
- Typhoeus (Typhoeus::Hydra, but not Typhoeus::Easy or Typhoeus::Multi)
|
14
|
-
- Excon
|
15
|
-
- :typhoeus can be used to hook into itself (as long as you use Typhoeus::Hydra,
|
16
|
-
but not Typhoeus::Easy or Typhoeus::Multi).
|
17
|
-
- :excon can be used to hook into itself.
|
18
|
-
- :faraday can be used to hook into itself.
|
19
|
-
- :fakeweb (deprecated) can be used to hook into Net::HTTP requests.
|
20
|
-
|
21
|
-
There are some addiitonal trade offs to consider when deciding which
|
22
|
-
option to use:
|
23
|
-
|
24
|
-
- WebMock uses extensive monkey patching to hook into supported HTTP
|
25
|
-
libraries. No monkey patching is used for Typhoeus, Excon or Faraday.
|
26
|
-
- Typhoeus, Excon, Faraday can be used together, and with either FakeWeb or WebMock.
|
27
|
-
- FakeWeb and WebMock cannot both be used at the same time.
|
28
|
-
|
29
|
-
Regardless of which library you use, VCR takes care of all of the configuration
|
30
|
-
for you. You should not need to interact directly with FakeWeb, WebMock or the
|
31
|
-
stubbing facilities of Typhoeus, Excon or Faraday. If/when you decide to change stubbing
|
32
|
-
libraries (i.e. if you initially use FakeWeb because it's faster but later need the
|
33
|
-
additional features of WebMock) you can change the `hook_into` configuration
|
34
|
-
option and it'll work with no other changes required.
|
35
|
-
|
36
|
-
Scenario Outline: Record and replay a request using each supported hook_into/http library combination
|
37
|
-
Given a file named "hook_into_http_lib_combo.rb" with:
|
38
|
-
"""ruby
|
39
|
-
include_http_adapter_for("<http_lib>")
|
40
|
-
|
41
|
-
require 'vcr'
|
42
|
-
VCR.configure { |c| c.ignore_localhost = true }
|
43
|
-
|
44
|
-
$server = start_sinatra_app do
|
45
|
-
get('/') { ARGV[0] }
|
46
|
-
end
|
47
|
-
|
48
|
-
puts "The response for request 1 was: #{response_body_for(:get, "http://localhost:#{$server.port}/")}"
|
49
|
-
|
50
|
-
VCR.configure do |c|
|
51
|
-
<configuration>
|
52
|
-
c.cassette_library_dir = 'vcr_cassettes'
|
53
|
-
c.ignore_localhost = false
|
54
|
-
c.default_cassette_options = { :serialize_with => :syck }
|
55
|
-
end
|
56
|
-
|
57
|
-
VCR.use_cassette('example') do
|
58
|
-
puts "The response for request 2 was: #{response_body_for(:get, "http://localhost:#{$server.port}/")}"
|
59
|
-
end
|
60
|
-
"""
|
61
|
-
When I run `ruby hook_into_http_lib_combo.rb 'Hello World'`
|
62
|
-
Then the output should contain each of the following:
|
63
|
-
| The response for request 1 was: Hello World |
|
64
|
-
| The response for request 2 was: Hello World |
|
65
|
-
And the file "vcr_cassettes/example.yml" should contain "Hello World"
|
66
|
-
|
67
|
-
When I run `ruby hook_into_http_lib_combo.rb 'Goodbye World'`
|
68
|
-
Then the output should contain each of the following:
|
69
|
-
| The response for request 1 was: Goodbye World |
|
70
|
-
| The response for request 2 was: Hello World |
|
71
|
-
And the file "vcr_cassettes/example.yml" should contain "Hello World"
|
72
|
-
|
73
|
-
Examples:
|
74
|
-
| configuration | http_lib |
|
75
|
-
| c.hook_into :fakeweb | net/http |
|
76
|
-
| c.hook_into :webmock | net/http |
|
77
|
-
| c.hook_into :webmock | httpclient |
|
78
|
-
| c.hook_into :webmock | curb |
|
79
|
-
| c.hook_into :webmock | patron |
|
80
|
-
| c.hook_into :webmock | em-http-request |
|
81
|
-
| c.hook_into :webmock | typhoeus |
|
82
|
-
| c.hook_into :webmock | excon |
|
83
|
-
| c.hook_into :typhoeus | typhoeus |
|
84
|
-
| c.hook_into :excon | excon |
|
85
|
-
| c.hook_into :faraday | faraday (w/ net_http) |
|
86
|
-
| c.hook_into :faraday | faraday (w/ typhoeus) |
|
87
|
-
|
88
|
-
@exclude-jruby @exclude-rbx
|
89
|
-
Scenario Outline: Use Typhoeus, Excon and Faraday in combination with FakeWeb or WebMock
|
90
|
-
Given a file named "hook_into_multiple.rb" with:
|
91
|
-
"""ruby
|
92
|
-
require 'typhoeus'
|
93
|
-
require 'excon'
|
94
|
-
require 'faraday'
|
95
|
-
require 'vcr'
|
96
|
-
<extra_require>
|
97
|
-
|
98
|
-
VCR.configure { |c| c.ignore_localhost = true }
|
99
|
-
|
100
|
-
$server = start_sinatra_app do
|
101
|
-
get('/:path') { "#{ARGV[0]} #{params[:path]}" }
|
102
|
-
end
|
103
|
-
|
104
|
-
def net_http_response
|
105
|
-
Net::HTTP.get_response('localhost', '/net_http', $server.port).body
|
106
|
-
end
|
107
|
-
|
108
|
-
def typhoeus_response
|
109
|
-
Typhoeus::Request.get("http://localhost:#{$server.port}/typhoeus").body
|
110
|
-
end
|
111
|
-
|
112
|
-
def excon_response
|
113
|
-
Excon.get("http://localhost:#{$server.port}/excon").body
|
114
|
-
end
|
115
|
-
|
116
|
-
def faraday_response
|
117
|
-
Faraday::Connection.new(:url => "http://localhost:#{$server.port}") do |builder|
|
118
|
-
builder.adapter :<faraday_adapter>
|
119
|
-
end.get('/faraday').body
|
120
|
-
end
|
121
|
-
|
122
|
-
puts "Net::HTTP 1: #{net_http_response}"
|
123
|
-
puts "Typhoeus 1: #{typhoeus_response}"
|
124
|
-
puts "Excon 1: #{excon_response}"
|
125
|
-
puts "Faraday 1: #{faraday_response}"
|
126
|
-
|
127
|
-
VCR.configure do |c|
|
128
|
-
c.hook_into <hook_into>, :typhoeus, :excon, :faraday
|
129
|
-
c.cassette_library_dir = 'vcr_cassettes'
|
130
|
-
c.ignore_localhost = false
|
131
|
-
end
|
132
|
-
|
133
|
-
VCR.use_cassette('example') do
|
134
|
-
puts "Net::HTTP 2: #{net_http_response}"
|
135
|
-
puts "Typhoeus 2: #{typhoeus_response}"
|
136
|
-
puts "Excon 2: #{excon_response}"
|
137
|
-
puts "Faraday 2: #{faraday_response}"
|
138
|
-
end
|
139
|
-
"""
|
140
|
-
When I run `ruby hook_into_multiple.rb 'Hello'`
|
141
|
-
Then the output should contain each of the following:
|
142
|
-
| Net::HTTP 1: Hello net_http |
|
143
|
-
| Typhoeus 1: Hello typhoeus |
|
144
|
-
| Excon 1: Hello excon |
|
145
|
-
| Faraday 1: Hello faraday |
|
146
|
-
| Net::HTTP 2: Hello net_http |
|
147
|
-
| Typhoeus 2: Hello typhoeus |
|
148
|
-
| Excon 2: Hello excon |
|
149
|
-
| Faraday 2: Hello faraday |
|
150
|
-
And the cassette "vcr_cassettes/example.yml" should have the following response bodies:
|
151
|
-
| Hello net_http |
|
152
|
-
| Hello typhoeus |
|
153
|
-
| Hello excon |
|
154
|
-
| Hello faraday |
|
155
|
-
|
156
|
-
When I run `ruby hook_into_multiple.rb 'Goodbye'`
|
157
|
-
Then the output should contain each of the following:
|
158
|
-
| Net::HTTP 1: Goodbye net_http |
|
159
|
-
| Typhoeus 1: Goodbye typhoeus |
|
160
|
-
| Excon 1: Goodbye excon |
|
161
|
-
| Faraday 1: Goodbye faraday |
|
162
|
-
| Net::HTTP 2: Hello net_http |
|
163
|
-
| Typhoeus 2: Hello typhoeus |
|
164
|
-
| Excon 2: Hello excon |
|
165
|
-
| Faraday 2: Hello faraday |
|
166
|
-
|
167
|
-
Examples:
|
168
|
-
| hook_into | faraday_adapter | extra_require |
|
169
|
-
| :fakeweb | net_http | |
|
170
|
-
| :webmock | net_http | |
|
171
|
-
| :fakeweb | typhoeus | require 'typhoeus/adapters/faraday' |
|
172
|
-
| :webmock | typhoeus | require 'typhoeus/adapters/faraday' |
|
@@ -1,192 +0,0 @@
|
|
1
|
-
Feature: Ignore Request
|
2
|
-
|
3
|
-
By default, VCR hooks into every request, either allowing it and recording
|
4
|
-
it, or playing back a recorded response, or raising an error to force you
|
5
|
-
to deal with the new request. In some situations, you may prefer to have
|
6
|
-
VCR ignore some requests.
|
7
|
-
|
8
|
-
VCR provides 3 configuration options to accomplish this:
|
9
|
-
|
10
|
-
* `ignore_request { |req| ... }` will ignore any request for which the
|
11
|
-
given block returns true.
|
12
|
-
* `ignore_hosts 'foo.com', 'bar.com'` allows you to specify particular
|
13
|
-
hosts to ignore.
|
14
|
-
* `ignore_localhost = true` is equivalent to `ignore_hosts 'localhost',
|
15
|
-
'127.0.0.1', '0.0.0.0'`. It is particularly useful for when you use
|
16
|
-
VCR with a javascript-enabled capybara driver, since capybara boots
|
17
|
-
your rack app and makes localhost requests to it to check that it has
|
18
|
-
booted.
|
19
|
-
|
20
|
-
Ignored requests are not recorded and are always allowed, regardless of
|
21
|
-
the record mode, and even outside of a `VCR.use_cassette` block.
|
22
|
-
|
23
|
-
Background:
|
24
|
-
Given a file named "sinatra_app.rb" with:
|
25
|
-
"""ruby
|
26
|
-
response_count = 0
|
27
|
-
$server = start_sinatra_app do
|
28
|
-
get('/') { "Port 7777 Response #{response_count += 1}" }
|
29
|
-
end
|
30
|
-
"""
|
31
|
-
|
32
|
-
@exclude-jruby
|
33
|
-
Scenario Outline: ignore requests to a specific port
|
34
|
-
Given a file named "ignore_request.rb" with:
|
35
|
-
"""ruby
|
36
|
-
include_http_adapter_for("<http_lib>")
|
37
|
-
require 'sinatra_app.rb'
|
38
|
-
|
39
|
-
response_count = 0
|
40
|
-
$server_8888 = start_sinatra_app do
|
41
|
-
get('/') { "Port 8888 Response #{response_count += 1}" }
|
42
|
-
end
|
43
|
-
|
44
|
-
require 'vcr'
|
45
|
-
|
46
|
-
VCR.configure do |c|
|
47
|
-
c.ignore_request do |request|
|
48
|
-
URI(request.uri).port == $server.port
|
49
|
-
end
|
50
|
-
|
51
|
-
c.default_cassette_options = { :serialize_with => :syck }
|
52
|
-
c.cassette_library_dir = 'cassettes'
|
53
|
-
<configuration>
|
54
|
-
end
|
55
|
-
|
56
|
-
VCR.use_cassette('example') do
|
57
|
-
puts response_body_for(:get, "http://localhost:#{$server_8888.port}/")
|
58
|
-
end
|
59
|
-
|
60
|
-
VCR.use_cassette('example') do
|
61
|
-
puts response_body_for(:get, "http://localhost:#{$server.port}/")
|
62
|
-
end
|
63
|
-
|
64
|
-
puts response_body_for(:get, "http://localhost:#{$server.port}/")
|
65
|
-
puts response_body_for(:get, "http://localhost:#{$server_8888.port}/")
|
66
|
-
"""
|
67
|
-
When I run `ruby ignore_request.rb`
|
68
|
-
Then it should fail with an error like:
|
69
|
-
"""
|
70
|
-
An HTTP request has been made that VCR does not know how to handle:
|
71
|
-
"""
|
72
|
-
And the output should contain:
|
73
|
-
"""
|
74
|
-
Port 8888 Response 1
|
75
|
-
Port 7777 Response 1
|
76
|
-
Port 7777 Response 2
|
77
|
-
"""
|
78
|
-
And the file "cassettes/example.yml" should contain "Port 8888"
|
79
|
-
And the file "cassettes/example.yml" should not contain "Port 7777"
|
80
|
-
|
81
|
-
Examples:
|
82
|
-
| configuration | http_lib |
|
83
|
-
| c.hook_into :fakeweb | net/http |
|
84
|
-
| c.hook_into :webmock | net/http |
|
85
|
-
| c.hook_into :typhoeus | typhoeus |
|
86
|
-
| c.hook_into :faraday | faraday (w/ net_http) |
|
87
|
-
|
88
|
-
Scenario Outline: ignored host requests are not recorded and are always allowed
|
89
|
-
Given a file named "ignore_hosts.rb" with:
|
90
|
-
"""ruby
|
91
|
-
include_http_adapter_for("<http_lib>")
|
92
|
-
require 'sinatra_app.rb'
|
93
|
-
|
94
|
-
require 'vcr'
|
95
|
-
|
96
|
-
VCR.configure do |c|
|
97
|
-
c.ignore_hosts '127.0.0.1', 'localhost'
|
98
|
-
c.cassette_library_dir = 'cassettes'
|
99
|
-
<configuration>
|
100
|
-
end
|
101
|
-
|
102
|
-
VCR.use_cassette('example') do
|
103
|
-
puts response_body_for(:get, "http://localhost:#{$server.port}/")
|
104
|
-
end
|
105
|
-
|
106
|
-
puts response_body_for(:get, "http://localhost:#{$server.port}/")
|
107
|
-
"""
|
108
|
-
When I run `ruby ignore_hosts.rb`
|
109
|
-
Then it should pass with:
|
110
|
-
"""
|
111
|
-
Port 7777 Response 1
|
112
|
-
Port 7777 Response 2
|
113
|
-
"""
|
114
|
-
And the file "cassettes/example.yml" should not exist
|
115
|
-
|
116
|
-
Examples:
|
117
|
-
| configuration | http_lib |
|
118
|
-
| c.hook_into :fakeweb | net/http |
|
119
|
-
| c.hook_into :webmock | net/http |
|
120
|
-
| c.hook_into :typhoeus | typhoeus |
|
121
|
-
| c.hook_into :excon | excon |
|
122
|
-
| c.hook_into :faraday | faraday (w/ net_http) |
|
123
|
-
|
124
|
-
@exclude-jruby
|
125
|
-
Scenario Outline: localhost requests are not treated differently by default
|
126
|
-
Given a file named "localhost_not_ignored.rb" with:
|
127
|
-
"""ruby
|
128
|
-
include_http_adapter_for("<http_lib>")
|
129
|
-
require 'sinatra_app.rb'
|
130
|
-
|
131
|
-
require 'vcr'
|
132
|
-
|
133
|
-
VCR.configure do |c|
|
134
|
-
c.cassette_library_dir = 'cassettes'
|
135
|
-
c.default_cassette_options = { :serialize_with => :syck }
|
136
|
-
<configuration>
|
137
|
-
end
|
138
|
-
|
139
|
-
VCR.use_cassette('localhost') do
|
140
|
-
response_body_for(:get, "http://localhost:#{$server.port}/")
|
141
|
-
end
|
142
|
-
|
143
|
-
response_body_for(:get, "http://localhost:#{$server.port}/")
|
144
|
-
"""
|
145
|
-
When I run `ruby localhost_not_ignored.rb`
|
146
|
-
Then it should fail with "An HTTP request has been made that VCR does not know how to handle"
|
147
|
-
And the file "cassettes/localhost.yml" should contain "Port 7777 Response 1"
|
148
|
-
|
149
|
-
Examples:
|
150
|
-
| configuration | http_lib |
|
151
|
-
| c.hook_into :fakeweb | net/http |
|
152
|
-
| c.hook_into :webmock | net/http |
|
153
|
-
| c.hook_into :typhoeus | typhoeus |
|
154
|
-
| c.hook_into :excon | excon |
|
155
|
-
| c.hook_into :faraday | faraday (w/ net_http) |
|
156
|
-
|
157
|
-
Scenario Outline: localhost requests are allowed and not recorded when ignore_localhost = true
|
158
|
-
Given a file named "ignore_localhost_true.rb" with:
|
159
|
-
"""ruby
|
160
|
-
include_http_adapter_for("<http_lib>")
|
161
|
-
require 'sinatra_app.rb'
|
162
|
-
|
163
|
-
require 'vcr'
|
164
|
-
|
165
|
-
VCR.configure do |c|
|
166
|
-
c.ignore_localhost = true
|
167
|
-
c.cassette_library_dir = 'cassettes'
|
168
|
-
<configuration>
|
169
|
-
end
|
170
|
-
|
171
|
-
VCR.use_cassette('localhost') do
|
172
|
-
puts response_body_for(:get, "http://localhost:#{$server.port}/")
|
173
|
-
end
|
174
|
-
|
175
|
-
puts response_body_for(:get, "http://localhost:#{$server.port}/")
|
176
|
-
"""
|
177
|
-
When I run `ruby ignore_localhost_true.rb`
|
178
|
-
Then it should pass with:
|
179
|
-
"""
|
180
|
-
Port 7777 Response 1
|
181
|
-
Port 7777 Response 2
|
182
|
-
"""
|
183
|
-
And the file "cassettes/localhost.yml" should not exist
|
184
|
-
|
185
|
-
Examples:
|
186
|
-
| configuration | http_lib |
|
187
|
-
| c.hook_into :fakeweb | net/http |
|
188
|
-
| c.hook_into :webmock | net/http |
|
189
|
-
| c.hook_into :typhoeus | typhoeus |
|
190
|
-
| c.hook_into :excon | excon |
|
191
|
-
| c.hook_into :faraday | faraday (w/ net_http) |
|
192
|
-
|