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
@@ -6,21 +6,19 @@ Feature: Naming
|
|
6
6
|
|
7
7
|
Scenario: Name sanitizing
|
8
8
|
Given a file named "name_sanitizing.rb" with:
|
9
|
-
"""
|
10
|
-
require 'vcr_cucumber_helpers'
|
11
|
-
|
9
|
+
"""ruby
|
12
10
|
start_sinatra_app(:port => 7777) do
|
13
11
|
get('/') { "Hello" }
|
14
12
|
end
|
15
13
|
|
16
14
|
require 'vcr'
|
17
15
|
|
18
|
-
VCR.
|
16
|
+
VCR.configure do |c|
|
19
17
|
c.cassette_library_dir = 'cassettes'
|
20
|
-
c.
|
18
|
+
c.hook_into :fakeweb
|
21
19
|
end
|
22
20
|
|
23
|
-
VCR.use_cassette('Fee, Fi Fo Fum'
|
21
|
+
VCR.use_cassette('Fee, Fi Fo Fum') do
|
24
22
|
Net::HTTP.get_response('localhost', '/', 7777)
|
25
23
|
end
|
26
24
|
"""
|
@@ -21,49 +21,48 @@ Feature: Error for HTTP request made when no cassette is in use
|
|
21
21
|
|
22
22
|
Scenario Outline: Error for request when no cassette is in use
|
23
23
|
Given a file named "no_cassette_error.rb" with:
|
24
|
-
"""
|
25
|
-
require 'vcr_cucumber_helpers'
|
24
|
+
"""ruby
|
26
25
|
include_http_adapter_for("<http_lib>")
|
27
26
|
|
28
27
|
require 'vcr'
|
29
28
|
|
30
|
-
VCR.
|
31
|
-
|
29
|
+
VCR.configure do |c|
|
30
|
+
<configuration>
|
32
31
|
c.cassette_library_dir = 'cassettes'
|
33
32
|
end
|
34
33
|
|
35
34
|
response_body_for(:get, 'http://example.com/')
|
36
35
|
"""
|
37
36
|
When I run `ruby no_cassette_error.rb`
|
38
|
-
Then it should fail with "
|
37
|
+
Then it should fail with "Real HTTP connections are disabled"
|
39
38
|
And the output should contain each of the following:
|
40
39
|
| You can use VCR to automatically record this request and replay it later. |
|
41
|
-
| no_cassette_error.rb:
|
40
|
+
| no_cassette_error.rb:10 |
|
42
41
|
|
43
42
|
Examples:
|
44
|
-
|
|
45
|
-
| :fakeweb
|
46
|
-
| :webmock
|
47
|
-
| :webmock
|
48
|
-
| :webmock
|
49
|
-
| :webmock
|
50
|
-
| :webmock
|
51
|
-
| :
|
52
|
-
| :
|
43
|
+
| configuration | http_lib |
|
44
|
+
| c.hook_into :fakeweb | net/http |
|
45
|
+
| c.hook_into :webmock | net/http |
|
46
|
+
| c.hook_into :webmock | httpclient |
|
47
|
+
| c.hook_into :webmock | curb |
|
48
|
+
| c.hook_into :webmock | patron |
|
49
|
+
| c.hook_into :webmock | em-http-request |
|
50
|
+
| c.hook_into :webmock | typhoeus |
|
51
|
+
| c.hook_into :typhoeus | typhoeus |
|
52
|
+
| c.hook_into :excon | excon |
|
53
|
+
| | faraday (w/ net_http) |
|
53
54
|
|
54
55
|
Scenario: Temporarily turn VCR off to allow HTTP requests to procede as normal
|
55
56
|
Given a file named "turn_off_vcr.rb" with:
|
56
|
-
"""
|
57
|
-
require 'vcr_cucumber_helpers'
|
58
|
-
|
57
|
+
"""ruby
|
59
58
|
start_sinatra_app(:port => 7777) do
|
60
59
|
get('/') { 'Hello' }
|
61
60
|
end
|
62
61
|
|
63
62
|
require 'vcr'
|
64
63
|
|
65
|
-
VCR.
|
66
|
-
c.
|
64
|
+
VCR.configure do |c|
|
65
|
+
c.hook_into :fakeweb
|
67
66
|
end
|
68
67
|
|
69
68
|
def make_request(context)
|
@@ -109,11 +108,11 @@ Feature: Error for HTTP request made when no cassette is in use
|
|
109
108
|
|
110
109
|
Scenario: Turning VCR off prevents cassettes from being inserted
|
111
110
|
Given a file named "turn_off_vcr_and_insert_cassette.rb" with:
|
112
|
-
"""
|
111
|
+
"""ruby
|
113
112
|
require 'vcr'
|
114
113
|
|
115
|
-
VCR.
|
116
|
-
c.
|
114
|
+
VCR.configure do |c|
|
115
|
+
c.hook_into :fakeweb
|
117
116
|
end
|
118
117
|
|
119
118
|
VCR.turn_off!
|
@@ -124,18 +123,16 @@ Feature: Error for HTTP request made when no cassette is in use
|
|
124
123
|
|
125
124
|
Scenario: Turning VCR off with `:ignore_cassettes => true` ignores cassettes
|
126
125
|
Given a file named "turn_off_vcr_and_insert_cassette.rb" with:
|
127
|
-
"""
|
128
|
-
require 'vcr_cucumber_helpers'
|
129
|
-
|
126
|
+
"""ruby
|
130
127
|
start_sinatra_app(:port => 7777) do
|
131
128
|
get('/') { 'Hello' }
|
132
129
|
end
|
133
130
|
|
134
131
|
require 'vcr'
|
135
132
|
|
136
|
-
VCR.
|
133
|
+
VCR.configure do |c|
|
137
134
|
c.cassette_library_dir = 'cassettes'
|
138
|
-
c.
|
135
|
+
c.hook_into :fakeweb
|
139
136
|
end
|
140
137
|
|
141
138
|
VCR.turn_off!(:ignore_cassettes => true)
|
@@ -41,12 +41,12 @@ Feature: Update content_length header
|
|
41
41
|
http_version: "1.1"
|
42
42
|
"""
|
43
43
|
And a file named "common_stuff.rb" with:
|
44
|
-
"""
|
44
|
+
"""ruby
|
45
45
|
require 'vcr'
|
46
46
|
|
47
|
-
VCR.
|
47
|
+
VCR.configure do |c|
|
48
48
|
c.cassette_library_dir = 'cassettes'
|
49
|
-
c.
|
49
|
+
c.hook_into :fakeweb
|
50
50
|
end
|
51
51
|
|
52
52
|
def make_request_and_print_results
|
@@ -58,10 +58,10 @@ Feature: Update content_length header
|
|
58
58
|
|
59
59
|
Scenario: Default :update_content_length_header setting
|
60
60
|
Given a file named "default.rb" with:
|
61
|
-
"""
|
61
|
+
"""ruby
|
62
62
|
require 'common_stuff'
|
63
63
|
|
64
|
-
VCR.use_cassette('example'
|
64
|
+
VCR.use_cassette('example') do
|
65
65
|
make_request_and_print_results
|
66
66
|
end
|
67
67
|
"""
|
@@ -74,10 +74,10 @@ Feature: Update content_length header
|
|
74
74
|
|
75
75
|
Scenario: :update_content_length_header => false
|
76
76
|
Given a file named "false.rb" with:
|
77
|
-
"""
|
77
|
+
"""ruby
|
78
78
|
require 'common_stuff'
|
79
79
|
|
80
|
-
VCR.use_cassette('example', :
|
80
|
+
VCR.use_cassette('example', :update_content_length_header => false) do
|
81
81
|
make_request_and_print_results
|
82
82
|
end
|
83
83
|
"""
|
@@ -90,10 +90,10 @@ Feature: Update content_length header
|
|
90
90
|
|
91
91
|
Scenario: :update_content_length_header => true
|
92
92
|
Given a file named "true.rb" with:
|
93
|
-
"""
|
93
|
+
"""ruby
|
94
94
|
require 'common_stuff'
|
95
95
|
|
96
|
-
VCR.use_cassette('example', :
|
96
|
+
VCR.use_cassette('example', :update_content_length_header => true) do
|
97
97
|
make_request_and_print_results
|
98
98
|
end
|
99
99
|
"""
|
@@ -7,9 +7,7 @@ Feature: Allow HTTP connections when no cassette
|
|
7
7
|
|
8
8
|
Background:
|
9
9
|
Given a file named "vcr_setup.rb" with:
|
10
|
-
"""
|
11
|
-
require 'vcr_cucumber_helpers'
|
12
|
-
|
10
|
+
"""ruby
|
13
11
|
if ARGV.include?('--with-server')
|
14
12
|
start_sinatra_app(:port => 7777) do
|
15
13
|
get('/') { "Hello" }
|
@@ -18,9 +16,9 @@ Feature: Allow HTTP connections when no cassette
|
|
18
16
|
|
19
17
|
require 'vcr'
|
20
18
|
|
21
|
-
VCR.
|
19
|
+
VCR.configure do |c|
|
22
20
|
c.allow_http_connections_when_no_cassette = true
|
23
|
-
c.
|
21
|
+
c.hook_into :fakeweb
|
24
22
|
c.cassette_library_dir = 'cassettes'
|
25
23
|
end
|
26
24
|
"""
|
@@ -28,7 +26,7 @@ Feature: Allow HTTP connections when no cassette
|
|
28
26
|
|
29
27
|
Scenario: Allow HTTP connections when no cassette
|
30
28
|
Given a file named "no_cassette.rb" with:
|
31
|
-
"""
|
29
|
+
"""ruby
|
32
30
|
require 'vcr_setup.rb'
|
33
31
|
|
34
32
|
puts "Response: " + Net::HTTP.get_response('localhost', '/', 7777).body
|
@@ -38,10 +36,10 @@ Feature: Allow HTTP connections when no cassette
|
|
38
36
|
|
39
37
|
Scenario: Cassettes record and replay as normal
|
40
38
|
Given a file named "record_replay_cassette.rb" with:
|
41
|
-
"""
|
39
|
+
"""ruby
|
42
40
|
require 'vcr_setup.rb'
|
43
41
|
|
44
|
-
VCR.use_cassette('localhost'
|
42
|
+
VCR.use_cassette('localhost') do
|
45
43
|
puts "Response: " + Net::HTTP.get_response('localhost', '/', 7777).body
|
46
44
|
end
|
47
45
|
"""
|
@@ -5,21 +5,19 @@ Feature: cassette_library_dir
|
|
5
5
|
|
6
6
|
Scenario: cassette_library_dir
|
7
7
|
Given a file named "cassette_library_dir.rb" with:
|
8
|
-
"""
|
9
|
-
require 'vcr_cucumber_helpers'
|
10
|
-
|
8
|
+
"""ruby
|
11
9
|
start_sinatra_app(:port => 7777) do
|
12
10
|
get('/') { "Hello" }
|
13
11
|
end
|
14
12
|
|
15
13
|
require 'vcr'
|
16
14
|
|
17
|
-
VCR.
|
15
|
+
VCR.configure do |c|
|
18
16
|
c.cassette_library_dir = 'vcr/cassettes'
|
19
|
-
c.
|
17
|
+
c.hook_into :fakeweb
|
20
18
|
end
|
21
19
|
|
22
|
-
VCR.use_cassette('localhost'
|
20
|
+
VCR.use_cassette('localhost') do
|
23
21
|
Net::HTTP.get_response('localhost', '/', 7777)
|
24
22
|
end
|
25
23
|
"""
|
@@ -7,23 +7,25 @@ Feature: default_cassette_options
|
|
7
7
|
The `:match_requests_on` option defaults to `[:method, :uri]` when
|
8
8
|
it has not been set.
|
9
9
|
|
10
|
+
The `:record` option defaults to `:once` when it has not been set.
|
11
|
+
|
10
12
|
Background:
|
11
13
|
Given a file named "vcr_setup.rb" with:
|
12
|
-
"""
|
14
|
+
"""ruby
|
13
15
|
require 'vcr'
|
14
16
|
|
15
|
-
VCR.
|
17
|
+
VCR.configure do |c|
|
16
18
|
c.default_cassette_options = { :record => :new_episodes, :erb => true }
|
17
19
|
|
18
20
|
# not important for this example, but must be set to something
|
19
|
-
c.
|
21
|
+
c.hook_into :webmock
|
20
22
|
c.cassette_library_dir = 'cassettes'
|
21
23
|
end
|
22
24
|
"""
|
23
25
|
|
24
26
|
Scenario: cassettes get default values from configured `default_cassette_options`
|
25
27
|
Given a file named "default_cassette_options.rb" with:
|
26
|
-
"""
|
28
|
+
"""ruby
|
27
29
|
require 'vcr_setup.rb'
|
28
30
|
|
29
31
|
VCR.use_cassette('example') do
|
@@ -40,7 +42,7 @@ Feature: default_cassette_options
|
|
40
42
|
|
41
43
|
Scenario: `:match_requests_on` defaults to `[:method, :uri]` when it has not been set
|
42
44
|
Given a file named "default_cassette_options.rb" with:
|
43
|
-
"""
|
45
|
+
"""ruby
|
44
46
|
require 'vcr_setup.rb'
|
45
47
|
|
46
48
|
VCR.use_cassette('example') do
|
@@ -52,12 +54,12 @@ Feature: default_cassette_options
|
|
52
54
|
|
53
55
|
Scenario: `:record` defaults to `:once` when it has not been set
|
54
56
|
Given a file named "default_record_mode.rb" with:
|
55
|
-
"""
|
57
|
+
"""ruby
|
56
58
|
require 'vcr'
|
57
59
|
|
58
|
-
VCR.
|
60
|
+
VCR.configure do |c|
|
59
61
|
# not important for this example, but must be set to something
|
60
|
-
c.
|
62
|
+
c.hook_into :webmock
|
61
63
|
c.cassette_library_dir = 'cassettes'
|
62
64
|
end
|
63
65
|
|
@@ -70,7 +72,7 @@ Feature: default_cassette_options
|
|
70
72
|
|
71
73
|
Scenario: cassettes can set their own options
|
72
74
|
Given a file named "default_cassette_options.rb" with:
|
73
|
-
"""
|
75
|
+
"""ruby
|
74
76
|
require 'vcr_setup.rb'
|
75
77
|
|
76
78
|
VCR.use_cassette('example', :re_record_interval => 10000) do
|
@@ -82,7 +84,7 @@ Feature: default_cassette_options
|
|
82
84
|
|
83
85
|
Scenario: cassettes can override default options
|
84
86
|
Given a file named "default_cassette_options.rb" with:
|
85
|
-
"""
|
87
|
+
"""ruby
|
86
88
|
require 'vcr_setup.rb'
|
87
89
|
|
88
90
|
VCR.use_cassette('example', :record => :none, :erb => false) do
|
@@ -25,9 +25,7 @@ Feature: Filter sensitive data
|
|
25
25
|
|
26
26
|
Scenario: Multiple filterings
|
27
27
|
Given a file named "filtering.rb" with:
|
28
|
-
"""
|
29
|
-
require 'vcr_cucumber_helpers'
|
30
|
-
|
28
|
+
"""ruby
|
31
29
|
if ARGV.include?('--with-server')
|
32
30
|
start_sinatra_app(:port => 7777) do
|
33
31
|
get('/') { "Hello World" }
|
@@ -36,14 +34,14 @@ Feature: Filter sensitive data
|
|
36
34
|
|
37
35
|
require 'vcr'
|
38
36
|
|
39
|
-
VCR.
|
40
|
-
c.
|
37
|
+
VCR.configure do |c|
|
38
|
+
c.hook_into :fakeweb
|
41
39
|
c.cassette_library_dir = 'cassettes'
|
42
40
|
c.filter_sensitive_data('<GREETING>') { 'Hello' }
|
43
41
|
c.filter_sensitive_data('<LOCATION>') { 'World' }
|
44
42
|
end
|
45
43
|
|
46
|
-
VCR.use_cassette('filtering'
|
44
|
+
VCR.use_cassette('filtering') do
|
47
45
|
response = Net::HTTP.get_response('localhost', '/', 7777)
|
48
46
|
puts "Response: #{response.body}"
|
49
47
|
end
|
@@ -59,9 +57,7 @@ Feature: Filter sensitive data
|
|
59
57
|
|
60
58
|
Scenario: Filter tagged cassettes
|
61
59
|
Given a file named "tagged_filtering.rb" with:
|
62
|
-
"""
|
63
|
-
require 'vcr_cucumber_helpers'
|
64
|
-
|
60
|
+
"""ruby
|
65
61
|
if ARGV.include?('--with-server')
|
66
62
|
response_count = 0
|
67
63
|
start_sinatra_app(:port => 7777) do
|
@@ -71,13 +67,13 @@ Feature: Filter sensitive data
|
|
71
67
|
|
72
68
|
require 'vcr'
|
73
69
|
|
74
|
-
VCR.
|
75
|
-
c.
|
70
|
+
VCR.configure do |c|
|
71
|
+
c.hook_into :fakeweb
|
76
72
|
c.cassette_library_dir = 'cassettes'
|
77
73
|
c.filter_sensitive_data('<LOCATION>', :my_tag) { 'World' }
|
78
74
|
end
|
79
75
|
|
80
|
-
VCR.use_cassette('tagged', :tag => :my_tag
|
76
|
+
VCR.use_cassette('tagged', :tag => :my_tag) do
|
81
77
|
response = Net::HTTP.get_response('localhost', '/', 7777)
|
82
78
|
puts "Tagged Response: #{response.body}"
|
83
79
|
end
|
@@ -101,8 +97,7 @@ Feature: Filter sensitive data
|
|
101
97
|
|
102
98
|
Scenario: Filter dynamic data based on yielded HTTP interaction
|
103
99
|
Given a file named "dynamic_filtering.rb" with:
|
104
|
-
"""
|
105
|
-
require 'vcr_cucumber_helpers'
|
100
|
+
"""ruby
|
106
101
|
include_http_adapter_for('net/http')
|
107
102
|
|
108
103
|
if ARGV.include?('--with-server')
|
@@ -125,15 +120,15 @@ Feature: Filter sensitive data
|
|
125
120
|
'jane.doe' => 'cheetah'
|
126
121
|
}
|
127
122
|
|
128
|
-
VCR.
|
129
|
-
c.
|
123
|
+
VCR.configure do |c|
|
124
|
+
c.hook_into :webmock
|
130
125
|
c.cassette_library_dir = 'cassettes'
|
131
126
|
c.filter_sensitive_data('<PASSWORD>') do |interaction|
|
132
127
|
USER_PASSWORDS[interaction.request.headers['x-http-username'].first]
|
133
128
|
end
|
134
129
|
end
|
135
130
|
|
136
|
-
VCR.use_cassette('example', :
|
131
|
+
VCR.use_cassette('example', :match_requests_on => [:method, :uri, :headers]) do
|
137
132
|
puts "Response: " + response_body_for(
|
138
133
|
:get, 'http://localhost:7777/', nil,
|
139
134
|
'X-HTTP-USERNAME' => 'john.doe',
|
@@ -1,99 +1,103 @@
|
|
1
|
-
Feature:
|
1
|
+
Feature: hook_into
|
2
2
|
|
3
|
-
The `
|
4
|
-
|
5
|
-
support many different HTTP libraries:
|
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
6
|
|
7
|
-
-
|
8
|
-
-
|
7
|
+
- :fakeweb can be used to hook into Net::HTTP requests.
|
8
|
+
- :webmock can be used to hook into requests from:
|
9
9
|
- Net::HTTP
|
10
10
|
- HTTPClient
|
11
11
|
- Patron
|
12
12
|
- Curb (Curl::Easy, but not Curl::Multi)
|
13
13
|
- EM HTTP Request
|
14
|
-
|
14
|
+
- Typhoeus (Typhoeus::Hydra, but not Typhoeus::Easy or Typhoeus::Multi)
|
15
|
+
- :typhoeus can be used to hook into itself (as long as you use Typhoeus::Hydra,
|
15
16
|
but not Typhoeus::Easy or Typhoeus::Multi).
|
16
|
-
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
- :excon can be used to hook into itself.
|
18
|
+
|
19
|
+
In addition, you can use VCR with Faraday if you use the provided
|
20
|
+
middleware in your Faraday connection stack. When you use VCR with Faraday,
|
21
|
+
you do not need to configure `hook_into` (since the middleware is sufficient).
|
20
22
|
|
21
23
|
There are some addiitonal trade offs to consider when deciding which
|
22
|
-
|
24
|
+
option to use:
|
23
25
|
|
24
|
-
- FakeWeb
|
25
|
-
Therefore, the `:match_requests_on` option does not support `:body` or
|
26
|
-
`:headers` when you use FakeWeb. Typhoeus, WebMock and Faraday both
|
27
|
-
support matching on `:body` and `:headers`.
|
28
|
-
- FakeWeb is currently about 4 times faster than WebMock for stubbing
|
26
|
+
- FakeWeb is currently about 4 times faster than WebMock for hooking into
|
29
27
|
Net::HTTP (see benchmarks/http_stubbing_libraries.rb for details).
|
30
|
-
- FakeWeb and WebMock both use extensive monkey patching to
|
31
|
-
supported HTTP libraries. No monkey patching is used for Typhoeus or
|
28
|
+
- FakeWeb and WebMock both use extensive monkey patching to hook into their
|
29
|
+
supported HTTP libraries. No monkey patching is used for Typhoeus, Excon or
|
32
30
|
Faraday.
|
33
31
|
- FakeWeb and WebMock cannot both be used at the same time.
|
34
|
-
- Typhoeus, Excon
|
35
|
-
FakeWeb or WebMock.
|
32
|
+
- Typhoeus, Excon, Faraday can be used together, and with either FakeWeb or WebMock.
|
36
33
|
|
37
34
|
Regardless of which library you use, VCR takes care of all of the configuration
|
38
35
|
for you. You should not need to interact directly with FakeWeb, WebMock or the
|
39
36
|
stubbing facilities of Typhoeus, Excon or Faraday. If/when you decide to change stubbing
|
40
37
|
libraries (i.e. if you initially use FakeWeb because it's faster but later need the
|
41
|
-
additional features of WebMock) you can change the `
|
38
|
+
additional features of WebMock) you can change the `hook_into` configuration
|
42
39
|
option and it'll work with no other changes required.
|
43
40
|
|
44
|
-
Scenario Outline: Record and replay a request using each supported
|
45
|
-
Given a file named "
|
46
|
-
"""
|
47
|
-
require 'vcr_cucumber_helpers'
|
41
|
+
Scenario Outline: Record and replay a request using each supported hook_into/http library combination
|
42
|
+
Given a file named "hook_into_http_lib_combo.rb" with:
|
43
|
+
"""ruby
|
48
44
|
include_http_adapter_for("<http_lib>")
|
49
45
|
|
46
|
+
require 'vcr'
|
47
|
+
VCR.configure { |c| c.ignore_localhost = true }
|
48
|
+
|
50
49
|
start_sinatra_app(:port => 7777) do
|
51
50
|
get('/') { ARGV[0] }
|
52
51
|
end
|
53
52
|
|
54
53
|
puts "The response for request 1 was: #{response_body_for(:get, "http://localhost:7777/")}"
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
VCR.config do |c|
|
59
|
-
c.stub_with <stub_with>
|
55
|
+
VCR.configure do |c|
|
56
|
+
<configuration>
|
60
57
|
c.cassette_library_dir = 'vcr_cassettes'
|
58
|
+
c.ignore_localhost = false
|
61
59
|
end
|
62
60
|
|
63
|
-
VCR.use_cassette('example'
|
61
|
+
VCR.use_cassette('example') do
|
64
62
|
puts "The response for request 2 was: #{response_body_for(:get, "http://localhost:7777/")}"
|
65
63
|
end
|
66
64
|
"""
|
67
|
-
When I run `ruby
|
65
|
+
When I run `ruby hook_into_http_lib_combo.rb 'Hello World'`
|
68
66
|
Then the output should contain each of the following:
|
69
67
|
| The response for request 1 was: Hello World |
|
70
68
|
| The response for request 2 was: Hello World |
|
71
69
|
And the file "vcr_cassettes/example.yml" should contain "body: Hello World"
|
72
70
|
|
73
|
-
When I run `ruby
|
71
|
+
When I run `ruby hook_into_http_lib_combo.rb 'Goodbye World'`
|
74
72
|
Then the output should contain each of the following:
|
75
73
|
| The response for request 1 was: Goodbye World |
|
76
74
|
| The response for request 2 was: Hello World |
|
77
75
|
And the file "vcr_cassettes/example.yml" should contain "body: Hello World"
|
78
76
|
|
79
77
|
Examples:
|
80
|
-
|
|
81
|
-
| :fakeweb
|
82
|
-
| :webmock
|
83
|
-
| :webmock
|
84
|
-
| :webmock
|
85
|
-
| :webmock
|
86
|
-
| :webmock
|
87
|
-
| :
|
88
|
-
| :
|
78
|
+
| configuration | http_lib |
|
79
|
+
| c.hook_into :fakeweb | net/http |
|
80
|
+
| c.hook_into :webmock | net/http |
|
81
|
+
| c.hook_into :webmock | httpclient |
|
82
|
+
| c.hook_into :webmock | curb |
|
83
|
+
| c.hook_into :webmock | patron |
|
84
|
+
| c.hook_into :webmock | em-http-request |
|
85
|
+
| c.hook_into :webmock | typhoeus |
|
86
|
+
| c.hook_into :typhoeus | typhoeus |
|
87
|
+
| c.hook_into :excon | excon |
|
88
|
+
| | faraday (w/ net_http) |
|
89
|
+
| | faraday (w/ typhoeus) |
|
89
90
|
|
90
91
|
@exclude-jruby
|
91
92
|
Scenario Outline: Use Typhoeus, Excon and Faraday in combination with FakeWeb or WebMock
|
92
|
-
Given a file named "
|
93
|
-
"""
|
94
|
-
require 'vcr_cucumber_helpers'
|
93
|
+
Given a file named "hook_into_multiple.rb" with:
|
94
|
+
"""ruby
|
95
95
|
require 'typhoeus'
|
96
96
|
require 'excon'
|
97
|
+
require 'faraday'
|
98
|
+
require 'vcr'
|
99
|
+
|
100
|
+
VCR.configure { |c| c.ignore_localhost = true }
|
97
101
|
|
98
102
|
start_sinatra_app(:port => 7777) do
|
99
103
|
get('/:path') { "#{ARGV[0]} #{params[:path]}" }
|
@@ -113,11 +117,7 @@ Feature: stub_with
|
|
113
117
|
|
114
118
|
def faraday_response
|
115
119
|
Faraday::Connection.new(:url => 'http://localhost:7777') do |builder|
|
116
|
-
builder.use VCR::Middleware::Faraday
|
117
|
-
cassette.name 'example'
|
118
|
-
cassette.options :record => :new_episodes
|
119
|
-
end
|
120
|
-
|
120
|
+
builder.use VCR::Middleware::Faraday
|
121
121
|
builder.adapter :<faraday_adapter>
|
122
122
|
end.get('/faraday').body
|
123
123
|
end
|
@@ -125,49 +125,50 @@ Feature: stub_with
|
|
125
125
|
puts "Net::HTTP 1: #{net_http_response}"
|
126
126
|
puts "Typhoeus 1: #{typhoeus_response}"
|
127
127
|
puts "Excon 1: #{excon_response}"
|
128
|
+
puts "Faraday 1: #{faraday_response}"
|
128
129
|
|
129
|
-
|
130
|
-
|
131
|
-
VCR.config do |c|
|
132
|
-
c.stub_with <stub_with>, :typhoeus, :excon, :faraday
|
130
|
+
VCR.configure do |c|
|
131
|
+
c.hook_into <hook_into>, :typhoeus, :excon
|
133
132
|
c.cassette_library_dir = 'vcr_cassettes'
|
133
|
+
c.ignore_localhost = false
|
134
134
|
end
|
135
135
|
|
136
|
-
VCR.use_cassette('example'
|
136
|
+
VCR.use_cassette('example') do
|
137
137
|
puts "Net::HTTP 2: #{net_http_response}"
|
138
138
|
puts "Typhoeus 2: #{typhoeus_response}"
|
139
139
|
puts "Excon 2: #{excon_response}"
|
140
|
+
puts "Faraday 2: #{faraday_response}"
|
140
141
|
end
|
141
|
-
|
142
|
-
puts "Faraday: #{faraday_response}"
|
143
142
|
"""
|
144
|
-
When I run `ruby
|
143
|
+
When I run `ruby hook_into_multiple.rb 'Hello'`
|
145
144
|
Then the output should contain each of the following:
|
146
145
|
| Net::HTTP 1: Hello net_http |
|
147
146
|
| Typhoeus 1: Hello typhoeus |
|
148
147
|
| Excon 1: Hello excon |
|
148
|
+
| Faraday 1: Hello faraday |
|
149
149
|
| Net::HTTP 2: Hello net_http |
|
150
150
|
| Typhoeus 2: Hello typhoeus |
|
151
151
|
| Excon 2: Hello excon |
|
152
|
-
| Faraday: Hello faraday
|
152
|
+
| Faraday 2: Hello faraday |
|
153
153
|
And the cassette "vcr_cassettes/example.yml" should have the following response bodies:
|
154
154
|
| Hello net_http |
|
155
155
|
| Hello typhoeus |
|
156
156
|
| Hello excon |
|
157
157
|
| Hello faraday |
|
158
158
|
|
159
|
-
When I run `ruby
|
159
|
+
When I run `ruby hook_into_multiple.rb 'Goodbye'`
|
160
160
|
Then the output should contain each of the following:
|
161
161
|
| Net::HTTP 1: Goodbye net_http |
|
162
162
|
| Typhoeus 1: Goodbye typhoeus |
|
163
163
|
| Excon 1: Goodbye excon |
|
164
|
+
| Faraday 1: Goodbye faraday |
|
164
165
|
| Net::HTTP 2: Hello net_http |
|
165
166
|
| Typhoeus 2: Hello typhoeus |
|
166
167
|
| Excon 2: Hello excon |
|
167
|
-
| Faraday: Hello faraday
|
168
|
+
| Faraday 2: Hello faraday |
|
168
169
|
|
169
170
|
Examples:
|
170
|
-
|
|
171
|
+
| hook_into | faraday_adapter |
|
171
172
|
| :fakeweb | net_http |
|
172
173
|
| :webmock | net_http |
|
173
174
|
| :fakeweb | typhoeus |
|