vcr 2.9.3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/features/about_these_examples.md +1 -1
- data/features/cassettes/automatic_re_recording.feature +4 -4
- data/features/cassettes/decompress.feature +3 -3
- data/features/cassettes/exclusive.feature +11 -8
- data/features/cassettes/format.feature +135 -32
- data/features/cassettes/naming.feature +2 -2
- data/features/cassettes/no_cassette.feature +4 -4
- data/features/configuration/allow_http_connections_when_no_cassette.feature +6 -3
- data/features/configuration/cassette_library_dir.feature +2 -2
- data/features/configuration/debug_logging.feature +15 -8
- data/features/configuration/filter_sensitive_data.feature +8 -7
- data/features/configuration/hook_into.feature +8 -8
- data/features/configuration/ignore_request.feature +13 -14
- data/features/configuration/preserve_exact_body_bytes.feature +5 -5
- data/features/configuration/uri_parser.feature +15 -11
- data/features/hooks/after_http_request.feature +5 -4
- data/features/hooks/around_http_request.feature +3 -3
- data/features/hooks/before_http_request.feature +4 -2
- data/features/hooks/before_playback.feature +14 -15
- data/features/hooks/before_record.feature +10 -10
- data/features/http_libraries/em_http_request.feature +6 -3
- data/features/http_libraries/net_http.feature +15 -5
- data/features/middleware/faraday.feature +2 -2
- data/features/middleware/rack.feature +4 -4
- data/features/record_modes/all.feature +5 -5
- data/features/record_modes/new_episodes.feature +2 -2
- data/features/record_modes/once.feature +3 -3
- data/features/step_definitions/cli_steps.rb +37 -39
- data/features/support/env.rb +29 -26
- data/features/support/http_lib_filters.rb +0 -7
- data/features/test_frameworks/cucumber.feature +11 -10
- data/features/test_frameworks/rspec_macro.feature +5 -30
- data/features/test_frameworks/rspec_metadata.feature +9 -8
- data/features/test_frameworks/test_unit.feature +5 -2
- data/lib/vcr.rb +86 -14
- data/lib/vcr/cassette.rb +4 -2
- data/lib/vcr/cassette/serializers.rb +10 -8
- data/lib/vcr/cassette/serializers/compressed.rb +45 -0
- data/lib/vcr/configuration.rb +38 -17
- data/lib/vcr/library_hooks/fakeweb.rb +1 -0
- data/lib/vcr/library_hooks/faraday.rb +5 -1
- data/lib/vcr/middleware/faraday.rb +13 -9
- data/lib/vcr/test_frameworks/cucumber.rb +39 -5
- data/lib/vcr/version.rb +1 -1
- data/spec/acceptance/concurrency_spec.rb +51 -0
- data/spec/{vcr → lib/vcr}/cassette/erb_renderer_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/cassette/http_interaction_list_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/cassette/migrator_spec.rb +10 -9
- data/spec/{vcr → lib/vcr}/cassette/persisters/file_system_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/cassette/persisters_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/cassette/serializers_spec.rb +8 -2
- data/spec/{vcr → lib/vcr}/cassette_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/configuration_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/deprecations_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/errors_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/extensions/net_http_response_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/library_hooks/excon_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/library_hooks/fakeweb_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/library_hooks/faraday_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/library_hooks/typhoeus_0.4_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/library_hooks/typhoeus_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/library_hooks/webmock_spec.rb +2 -2
- data/spec/{vcr → lib/vcr}/library_hooks_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/middleware/faraday_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/middleware/rack_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/request_ignorer_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/request_matcher_registry_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/structs_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/test_frameworks/cucumber_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/test_frameworks/rspec_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/util/hooks_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/util/internet_connection_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/util/version_checker_spec.rb +0 -0
- data/spec/{vcr → lib/vcr}/version_spec.rb +0 -0
- data/spec/{vcr_spec.rb → lib/vcr_spec.rb} +2 -2
- data/spec/spec_helper.rb +21 -50
- data/spec/support/cucumber_helpers.rb +39 -0
- data/spec/support/limited_uri.rb +1 -11
- data/spec/support/shared_example_groups/hook_into_http_library.rb +2 -1
- data/spec/support/vcr_localhost_server.rb +2 -3
- metadata +475 -123
- data/.gemtest +0 -0
- data/.gitignore +0 -52
- data/.gitmodules +0 -3
- data/.rspec +0 -2
- data/.travis.yml +0 -27
- data/.yardopts +0 -9
- data/Appraisals +0 -5
- data/CHANGELOG.md +0 -987
- data/CONTRIBUTING.md +0 -26
- data/Gemfile +0 -54
- data/Gemfile.lock +0 -159
- data/LICENSE +0 -20
- data/README.md +0 -243
- data/Rakefile +0 -197
- data/Upgrade.md +0 -289
- data/benchmarks/http_stubbing_libraries.rb +0 -59
- data/benchmarks/null_logging.rb +0 -62
- data/cucumber.yml +0 -16
- data/features/.nav +0 -62
- data/features/cassettes/persistence.feature +0 -63
- data/features/support/vcr_cucumber_helpers.rb +0 -46
- data/gemfiles/typhoeus_old.gemfile +0 -34
- data/gemfiles/typhoeus_old.gemfile.lock +0 -133
- data/script/ci.sh +0 -27
- data/spec/capture_warnings.rb +0 -73
- data/spec/quality_spec.rb +0 -51
- data/vcr.gemspec +0 -23
@@ -11,7 +11,7 @@ Feature: cassette_library_dir
|
|
11
11
|
Scenario: cassette_library_dir
|
12
12
|
Given a file named "cassette_library_dir.rb" with:
|
13
13
|
"""ruby
|
14
|
-
|
14
|
+
$server = start_sinatra_app do
|
15
15
|
get('/') { "Hello" }
|
16
16
|
end
|
17
17
|
|
@@ -23,7 +23,7 @@ Feature: cassette_library_dir
|
|
23
23
|
end
|
24
24
|
|
25
25
|
VCR.use_cassette('localhost') do
|
26
|
-
Net::HTTP.get_response('localhost', '/',
|
26
|
+
Net::HTTP.get_response('localhost', '/', $server.port)
|
27
27
|
end
|
28
28
|
"""
|
29
29
|
And the directory "vcr/cassettes" does not exist
|
@@ -10,7 +10,7 @@ Feature: Debug Logging
|
|
10
10
|
Given a file named "debug_logger.rb" with:
|
11
11
|
"""ruby
|
12
12
|
if ARGV.include?('--with-server')
|
13
|
-
|
13
|
+
$server = start_sinatra_app do
|
14
14
|
get('/') { "Hello World" }
|
15
15
|
end
|
16
16
|
end
|
@@ -21,31 +21,38 @@ Feature: Debug Logging
|
|
21
21
|
c.hook_into :webmock
|
22
22
|
c.cassette_library_dir = 'cassettes'
|
23
23
|
c.debug_logger = File.open(ARGV.first, 'w')
|
24
|
+
c.default_cassette_options = {
|
25
|
+
:match_requests_on => [:method, :host, :path]
|
26
|
+
}
|
24
27
|
end
|
25
28
|
|
26
29
|
VCR.use_cassette('example') do
|
27
|
-
|
30
|
+
port = $server ? $server.port : 7777
|
31
|
+
Net::HTTP.get_response(URI("http://localhost:#{port}/"))
|
28
32
|
end
|
29
33
|
"""
|
30
34
|
When I run `ruby debug_logger.rb record.log --with-server`
|
35
|
+
Given that port numbers in "record.log" are normalized to "7777"
|
31
36
|
Then the file "record.log" should contain exactly:
|
32
37
|
"""
|
33
|
-
[Cassette: 'example'] Initialized with options: {:record=>:once, :match_requests_on=>[:method, :
|
38
|
+
[Cassette: 'example'] Initialized with options: {:record=>:once, :match_requests_on=>[:method, :host, :path], :allow_unused_http_interactions=>true, :serialize_with=>:yaml, :persist_with=>:file_system}
|
34
39
|
[webmock] Handling request: [get http://localhost:7777/] (disabled: false)
|
35
|
-
[Cassette: 'example'] Initialized HTTPInteractionList with request matchers [:method, :
|
40
|
+
[Cassette: 'example'] Initialized HTTPInteractionList with request matchers [:method, :host, :path] and 0 interaction(s): { }
|
36
41
|
[webmock] Identified request type (recordable) for [get http://localhost:7777/]
|
37
42
|
[Cassette: 'example'] Recorded HTTP interaction [get http://localhost:7777/] => [200 "Hello World"]
|
38
43
|
|
39
44
|
"""
|
40
45
|
When I run `ruby debug_logger.rb playback.log`
|
46
|
+
Given that port numbers in "playback.log" are normalized to "7777"
|
41
47
|
Then the file "playback.log" should contain exactly:
|
42
48
|
"""
|
43
|
-
[Cassette: 'example'] Initialized with options: {:record=>:once, :match_requests_on=>[:method, :
|
49
|
+
[Cassette: 'example'] Initialized with options: {:record=>:once, :match_requests_on=>[:method, :host, :path], :allow_unused_http_interactions=>true, :serialize_with=>:yaml, :persist_with=>:file_system}
|
44
50
|
[webmock] Handling request: [get http://localhost:7777/] (disabled: false)
|
45
|
-
[Cassette: 'example'] Initialized HTTPInteractionList with request matchers [:method, :
|
46
|
-
[Cassette: 'example'] Checking if [get http://localhost:7777/] matches [get http://localhost:7777/] using [:method, :
|
51
|
+
[Cassette: 'example'] Initialized HTTPInteractionList with request matchers [:method, :host, :path] and 1 interaction(s): { [get http://localhost:7777/] => [200 "Hello World"] }
|
52
|
+
[Cassette: 'example'] Checking if [get http://localhost:7777/] matches [get http://localhost:7777/] using [:method, :host, :path]
|
47
53
|
[Cassette: 'example'] method (matched): current request [get http://localhost:7777/] vs [get http://localhost:7777/]
|
48
|
-
[Cassette: 'example']
|
54
|
+
[Cassette: 'example'] host (matched): current request [get http://localhost:7777/] vs [get http://localhost:7777/]
|
55
|
+
[Cassette: 'example'] path (matched): current request [get http://localhost:7777/] vs [get http://localhost:7777/]
|
49
56
|
[Cassette: 'example'] Found matching interaction for [get http://localhost:7777/] at index 0: [200 "Hello World"]
|
50
57
|
[webmock] Identified request type (stubbed_by_vcr) for [get http://localhost:7777/]
|
51
58
|
|
@@ -30,7 +30,7 @@ Feature: Filter sensitive data
|
|
30
30
|
Given a file named "filtering.rb" with:
|
31
31
|
"""ruby
|
32
32
|
if ARGV.include?('--with-server')
|
33
|
-
|
33
|
+
$server = start_sinatra_app do
|
34
34
|
get('/') { "Hello World" }
|
35
35
|
end
|
36
36
|
end
|
@@ -45,7 +45,7 @@ Feature: Filter sensitive data
|
|
45
45
|
end
|
46
46
|
|
47
47
|
VCR.use_cassette('filtering') do
|
48
|
-
response = Net::HTTP.get_response('localhost', '/',
|
48
|
+
response = Net::HTTP.get_response('localhost', '/', $server ? $server.port : 0)
|
49
49
|
puts "Response: #{response.body}"
|
50
50
|
end
|
51
51
|
"""
|
@@ -63,7 +63,7 @@ Feature: Filter sensitive data
|
|
63
63
|
"""ruby
|
64
64
|
if ARGV.include?('--with-server')
|
65
65
|
response_count = 0
|
66
|
-
|
66
|
+
$server = start_sinatra_app do
|
67
67
|
get('/') { "Hello World #{response_count += 1 }" }
|
68
68
|
end
|
69
69
|
end
|
@@ -77,12 +77,12 @@ Feature: Filter sensitive data
|
|
77
77
|
end
|
78
78
|
|
79
79
|
VCR.use_cassette('tagged', :tag => :my_tag) do
|
80
|
-
response = Net::HTTP.get_response('localhost', '/',
|
80
|
+
response = Net::HTTP.get_response('localhost', '/', $server ? $server.port : 0)
|
81
81
|
puts "Tagged Response: #{response.body}"
|
82
82
|
end
|
83
83
|
|
84
84
|
VCR.use_cassette('untagged', :record => :new_episodes) do
|
85
|
-
response = Net::HTTP.get_response('localhost', '/',
|
85
|
+
response = Net::HTTP.get_response('localhost', '/', $server ? $server.port : 0)
|
86
86
|
puts "Untagged Response: #{response.body}"
|
87
87
|
end
|
88
88
|
"""
|
@@ -104,7 +104,7 @@ Feature: Filter sensitive data
|
|
104
104
|
include_http_adapter_for('net/http')
|
105
105
|
|
106
106
|
if ARGV.include?('--with-server')
|
107
|
-
|
107
|
+
$server = start_sinatra_app do
|
108
108
|
helpers do
|
109
109
|
def request_header_for(header_key_fragment)
|
110
110
|
key = env.keys.find { |k| k =~ /#{header_key_fragment}/i }
|
@@ -132,8 +132,9 @@ Feature: Filter sensitive data
|
|
132
132
|
end
|
133
133
|
|
134
134
|
VCR.use_cassette('example', :match_requests_on => [:method, :uri, :headers]) do
|
135
|
+
port = $server ? $server.port : 0
|
135
136
|
puts "Response: " + response_body_for(
|
136
|
-
:get,
|
137
|
+
:get, "http://localhost:#{port}/", nil,
|
137
138
|
'X-Http-Username' => 'john.doe',
|
138
139
|
'X-Http-Password' => USER_PASSWORDS['john.doe']
|
139
140
|
)
|
@@ -41,11 +41,11 @@ Feature: hook_into
|
|
41
41
|
require 'vcr'
|
42
42
|
VCR.configure { |c| c.ignore_localhost = true }
|
43
43
|
|
44
|
-
|
44
|
+
$server = start_sinatra_app do
|
45
45
|
get('/') { ARGV[0] }
|
46
46
|
end
|
47
47
|
|
48
|
-
puts "The response for request 1 was: #{response_body_for(:get, "http://localhost
|
48
|
+
puts "The response for request 1 was: #{response_body_for(:get, "http://localhost:#{$server.port}/")}"
|
49
49
|
|
50
50
|
VCR.configure do |c|
|
51
51
|
<configuration>
|
@@ -55,7 +55,7 @@ Feature: hook_into
|
|
55
55
|
end
|
56
56
|
|
57
57
|
VCR.use_cassette('example') do
|
58
|
-
puts "The response for request 2 was: #{response_body_for(:get, "http://localhost
|
58
|
+
puts "The response for request 2 was: #{response_body_for(:get, "http://localhost:#{$server.port}/")}"
|
59
59
|
end
|
60
60
|
"""
|
61
61
|
When I run `ruby hook_into_http_lib_combo.rb 'Hello World'`
|
@@ -97,24 +97,24 @@ Feature: hook_into
|
|
97
97
|
|
98
98
|
VCR.configure { |c| c.ignore_localhost = true }
|
99
99
|
|
100
|
-
|
100
|
+
$server = start_sinatra_app do
|
101
101
|
get('/:path') { "#{ARGV[0]} #{params[:path]}" }
|
102
102
|
end
|
103
103
|
|
104
104
|
def net_http_response
|
105
|
-
Net::HTTP.get_response('localhost', '/net_http',
|
105
|
+
Net::HTTP.get_response('localhost', '/net_http', $server.port).body
|
106
106
|
end
|
107
107
|
|
108
108
|
def typhoeus_response
|
109
|
-
Typhoeus::Request.get("http://localhost
|
109
|
+
Typhoeus::Request.get("http://localhost:#{$server.port}/typhoeus").body
|
110
110
|
end
|
111
111
|
|
112
112
|
def excon_response
|
113
|
-
Excon.get("http://localhost
|
113
|
+
Excon.get("http://localhost:#{$server.port}/excon").body
|
114
114
|
end
|
115
115
|
|
116
116
|
def faraday_response
|
117
|
-
Faraday::Connection.new(:url =>
|
117
|
+
Faraday::Connection.new(:url => "http://localhost:#{$server.port}") do |builder|
|
118
118
|
builder.adapter :<faraday_adapter>
|
119
119
|
end.get('/faraday').body
|
120
120
|
end
|
@@ -24,7 +24,7 @@ Feature: Ignore Request
|
|
24
24
|
Given a file named "sinatra_app.rb" with:
|
25
25
|
"""ruby
|
26
26
|
response_count = 0
|
27
|
-
|
27
|
+
$server = start_sinatra_app do
|
28
28
|
get('/') { "Port 7777 Response #{response_count += 1}" }
|
29
29
|
end
|
30
30
|
"""
|
@@ -37,7 +37,7 @@ Feature: Ignore Request
|
|
37
37
|
require 'sinatra_app.rb'
|
38
38
|
|
39
39
|
response_count = 0
|
40
|
-
|
40
|
+
$server_8888 = start_sinatra_app do
|
41
41
|
get('/') { "Port 8888 Response #{response_count += 1}" }
|
42
42
|
end
|
43
43
|
|
@@ -45,7 +45,7 @@ Feature: Ignore Request
|
|
45
45
|
|
46
46
|
VCR.configure do |c|
|
47
47
|
c.ignore_request do |request|
|
48
|
-
URI(request.uri).port ==
|
48
|
+
URI(request.uri).port == $server.port
|
49
49
|
end
|
50
50
|
|
51
51
|
c.default_cassette_options = { :serialize_with => :syck }
|
@@ -54,21 +54,20 @@ Feature: Ignore Request
|
|
54
54
|
end
|
55
55
|
|
56
56
|
VCR.use_cassette('example') do
|
57
|
-
puts response_body_for(:get, "http://localhost
|
57
|
+
puts response_body_for(:get, "http://localhost:#{$server_8888.port}/")
|
58
58
|
end
|
59
59
|
|
60
60
|
VCR.use_cassette('example') do
|
61
|
-
puts response_body_for(:get, "http://localhost
|
61
|
+
puts response_body_for(:get, "http://localhost:#{$server.port}/")
|
62
62
|
end
|
63
63
|
|
64
|
-
puts response_body_for(:get, "http://localhost
|
65
|
-
puts response_body_for(:get, "http://localhost
|
64
|
+
puts response_body_for(:get, "http://localhost:#{$server.port}/")
|
65
|
+
puts response_body_for(:get, "http://localhost:#{$server_8888.port}/")
|
66
66
|
"""
|
67
67
|
When I run `ruby ignore_request.rb`
|
68
68
|
Then it should fail with an error like:
|
69
69
|
"""
|
70
70
|
An HTTP request has been made that VCR does not know how to handle:
|
71
|
-
GET http://localhost:8888/
|
72
71
|
"""
|
73
72
|
And the output should contain:
|
74
73
|
"""
|
@@ -101,10 +100,10 @@ Feature: Ignore Request
|
|
101
100
|
end
|
102
101
|
|
103
102
|
VCR.use_cassette('example') do
|
104
|
-
puts response_body_for(:get, "http://localhost
|
103
|
+
puts response_body_for(:get, "http://localhost:#{$server.port}/")
|
105
104
|
end
|
106
105
|
|
107
|
-
puts response_body_for(:get, "http://localhost
|
106
|
+
puts response_body_for(:get, "http://localhost:#{$server.port}/")
|
108
107
|
"""
|
109
108
|
When I run `ruby ignore_hosts.rb`
|
110
109
|
Then it should pass with:
|
@@ -138,10 +137,10 @@ Feature: Ignore Request
|
|
138
137
|
end
|
139
138
|
|
140
139
|
VCR.use_cassette('localhost') do
|
141
|
-
response_body_for(:get, "http://localhost
|
140
|
+
response_body_for(:get, "http://localhost:#{$server.port}/")
|
142
141
|
end
|
143
142
|
|
144
|
-
response_body_for(:get, "http://localhost
|
143
|
+
response_body_for(:get, "http://localhost:#{$server.port}/")
|
145
144
|
"""
|
146
145
|
When I run `ruby localhost_not_ignored.rb`
|
147
146
|
Then it should fail with "An HTTP request has been made that VCR does not know how to handle"
|
@@ -170,10 +169,10 @@ Feature: Ignore Request
|
|
170
169
|
end
|
171
170
|
|
172
171
|
VCR.use_cassette('localhost') do
|
173
|
-
puts response_body_for(:get, "http://localhost
|
172
|
+
puts response_body_for(:get, "http://localhost:#{$server.port}/")
|
174
173
|
end
|
175
174
|
|
176
|
-
puts response_body_for(:get, "http://localhost
|
175
|
+
puts response_body_for(:get, "http://localhost:#{$server.port}/")
|
177
176
|
"""
|
178
177
|
When I run `ruby ignore_localhost_true.rb`
|
179
178
|
Then it should pass with:
|
@@ -24,7 +24,7 @@ Feature: Preserve Exact Body Bytes
|
|
24
24
|
string = "abc \xFA"
|
25
25
|
puts "Valid encoding: #{string.valid_encoding?}"
|
26
26
|
|
27
|
-
|
27
|
+
$server = start_sinatra_app do
|
28
28
|
get('/') { string }
|
29
29
|
end
|
30
30
|
|
@@ -43,7 +43,7 @@ Feature: Preserve Exact Body Bytes
|
|
43
43
|
puts
|
44
44
|
puts label
|
45
45
|
VCR.use_cassette('example', :serialize_with => :json) do
|
46
|
-
body = Net::HTTP.get_response(
|
46
|
+
body = Net::HTTP.get_response('localhost', '/', $server.port).body
|
47
47
|
puts "Body: #{body.inspect}"
|
48
48
|
end
|
49
49
|
end
|
@@ -71,7 +71,7 @@ Feature: Preserve Exact Body Bytes
|
|
71
71
|
Scenario: Preserve exact bytes for cassette with `:preserve_exact_body_bytes` option
|
72
72
|
Given a file named "preserve.rb" with:
|
73
73
|
"""ruby
|
74
|
-
|
74
|
+
$server = start_sinatra_app do
|
75
75
|
get('/') { "Hello World" }
|
76
76
|
end
|
77
77
|
|
@@ -89,11 +89,11 @@ Feature: Preserve Exact Body Bytes
|
|
89
89
|
end
|
90
90
|
|
91
91
|
VCR.use_cassette('preserve_bytes', :preserve_exact_body_bytes => true) do
|
92
|
-
Net::HTTP.get_response(
|
92
|
+
Net::HTTP.get_response('localhost', '/', $server.port)
|
93
93
|
end
|
94
94
|
|
95
95
|
VCR.use_cassette('dont_preserve_bytes') do
|
96
|
-
Net::HTTP.get_response(
|
96
|
+
Net::HTTP.get_response('localhost', '/', $server.port)
|
97
97
|
end
|
98
98
|
"""
|
99
99
|
When I run `ruby preserve.rb`
|
@@ -27,7 +27,7 @@ Feature: uri_parser
|
|
27
27
|
http_interactions:
|
28
28
|
- request:
|
29
29
|
method: get
|
30
|
-
uri: http://
|
30
|
+
uri: http://example.com/hello
|
31
31
|
body:
|
32
32
|
encoding: UTF-8
|
33
33
|
string: ""
|
@@ -51,16 +51,25 @@ Feature: uri_parser
|
|
51
51
|
Given a file named "uri_parser.rb" with:
|
52
52
|
"""ruby
|
53
53
|
require 'vcr'
|
54
|
-
require '
|
54
|
+
require 'uri'
|
55
|
+
|
56
|
+
module MyURI
|
57
|
+
def self.parse(url)
|
58
|
+
uri = URI.parse(url)
|
59
|
+
uri.host = 'example.com'
|
60
|
+
uri.path = '/hello'
|
61
|
+
uri
|
62
|
+
end
|
63
|
+
end
|
55
64
|
|
56
65
|
VCR.configure do |c|
|
57
|
-
c.uri_parser =
|
66
|
+
c.uri_parser = MyURI
|
58
67
|
c.hook_into :webmock
|
59
68
|
c.cassette_library_dir = 'cassettes'
|
60
69
|
end
|
61
70
|
|
62
71
|
VCR.use_cassette('example') do
|
63
|
-
puts Net::HTTP.get_response('
|
72
|
+
puts Net::HTTP.get_response('evil.org', '/projects').body
|
64
73
|
end
|
65
74
|
"""
|
66
75
|
When I run `ruby uri_parser.rb`
|
@@ -70,7 +79,6 @@ Feature: uri_parser
|
|
70
79
|
Given a file named "uri_parser_default.rb" with:
|
71
80
|
"""ruby
|
72
81
|
require 'vcr'
|
73
|
-
require 'addressable/uri'
|
74
82
|
|
75
83
|
VCR.configure do |c|
|
76
84
|
c.hook_into :webmock
|
@@ -78,12 +86,8 @@ Feature: uri_parser
|
|
78
86
|
end
|
79
87
|
|
80
88
|
VCR.use_cassette('example') do
|
81
|
-
puts Net::HTTP.get_response('
|
89
|
+
puts Net::HTTP.get_response('example.com', '/hello').body
|
82
90
|
end
|
83
91
|
"""
|
84
92
|
When I run `ruby uri_parser_default.rb`
|
85
|
-
Then it should
|
86
|
-
"""
|
87
|
-
URI::InvalidURIError
|
88
|
-
"""
|
89
|
-
|
93
|
+
Then it should pass with "Hello"
|
@@ -22,7 +22,7 @@ Feature: after_http_request hook
|
|
22
22
|
"""ruby
|
23
23
|
include_http_adapter_for("<http_lib>")
|
24
24
|
|
25
|
-
|
25
|
+
$server = start_sinatra_app do
|
26
26
|
get('/foo') { "Hello World (foo)" }
|
27
27
|
get('/bar') { "Hello World (bar)" }
|
28
28
|
end
|
@@ -34,12 +34,13 @@ Feature: after_http_request hook
|
|
34
34
|
c.cassette_library_dir = 'cassettes'
|
35
35
|
c.ignore_localhost = true
|
36
36
|
c.after_http_request(:ignored?, lambda { |req| req.uri =~ /foo/ }) do |request, response|
|
37
|
-
|
37
|
+
uri = request.uri.sub(/:\d+/, ":7777")
|
38
|
+
puts "Response for #{request.method} #{uri}: #{response.body}"
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
|
-
make_http_request(:get, "http://localhost
|
42
|
-
make_http_request(:get, "http://localhost
|
42
|
+
make_http_request(:get, "http://localhost:#{$server.port}/foo")
|
43
|
+
make_http_request(:get, "http://localhost:#{$server.port}/bar")
|
43
44
|
"""
|
44
45
|
When I run `ruby after_http_request.rb`
|
45
46
|
Then the output should contain "Response for get http://localhost:7777/foo: Hello World (foo)"
|
@@ -19,7 +19,7 @@ Feature: around_http_request hook
|
|
19
19
|
include_http_adapter_for("<http_lib>")
|
20
20
|
|
21
21
|
request_count = 0
|
22
|
-
|
22
|
+
$server = start_sinatra_app do
|
23
23
|
get('/') { "Response #{request_count += 1 }" }
|
24
24
|
end
|
25
25
|
|
@@ -34,8 +34,8 @@ Feature: around_http_request hook
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
puts "Response for request 1: " + response_body_for(:get, "http://localhost
|
38
|
-
puts "Response for request 2: " + response_body_for(:get, "http://localhost
|
37
|
+
puts "Response for request 1: " + response_body_for(:get, "http://localhost:#{$server.port}/")
|
38
|
+
puts "Response for request 2: " + response_body_for(:get, "http://localhost:#{$server.port}/")
|
39
39
|
"""
|
40
40
|
When I run `ruby globally_handle_requests.rb`
|
41
41
|
Then it should pass with:
|
@@ -23,7 +23,7 @@ Feature: before_http_request hook
|
|
23
23
|
include_http_adapter_for("<http_lib>")
|
24
24
|
|
25
25
|
if ARGV.include?('--with-server')
|
26
|
-
|
26
|
+
$server = start_sinatra_app do
|
27
27
|
get('/') { "Hello World" }
|
28
28
|
end
|
29
29
|
end
|
@@ -41,10 +41,12 @@ Feature: before_http_request hook
|
|
41
41
|
end
|
42
42
|
|
43
43
|
VCR.use_cassette('hook_example') do
|
44
|
-
|
44
|
+
port = $server ? $server.port : 0
|
45
|
+
make_http_request(:get, "http://localhost:#{port}/")
|
45
46
|
end
|
46
47
|
"""
|
47
48
|
When I run `ruby before_http_request.rb run1.log --with-server`
|
49
|
+
Given that port numbers in "run1.log" are normalized to "7777"
|
48
50
|
Then the file "run1.log" should contain "before real request: get http://localhost:7777/"
|
49
51
|
When I run `ruby before_http_request.rb run2.log`
|
50
52
|
Then the file "run2.log" should not exist
|
@@ -10,8 +10,7 @@ Feature: before_playback hook
|
|
10
10
|
You can also call `#ignore!` on the HTTP interaction to prevent VCR
|
11
11
|
from playing it back.
|
12
12
|
|
13
|
-
|
14
|
-
this purpose. Consider this code:
|
13
|
+
You can use tags to specify a cassette, otherwise your hook will apply to all cassettes. Consider this code:
|
15
14
|
|
16
15
|
VCR.configure do |c|
|
17
16
|
c.before_playback(:twitter) { ... } # modify the interactions somehow
|
@@ -26,25 +25,25 @@ Feature: before_playback hook
|
|
26
25
|
Background:
|
27
26
|
Given a previously recorded cassette file "cassettes/example.yml" with:
|
28
27
|
"""
|
29
|
-
---
|
30
|
-
http_interactions:
|
31
|
-
- request:
|
28
|
+
---
|
29
|
+
http_interactions:
|
30
|
+
- request:
|
32
31
|
method: get
|
33
32
|
uri: http://localhost:7777/
|
34
|
-
body:
|
33
|
+
body:
|
35
34
|
encoding: UTF-8
|
36
35
|
string: ""
|
37
36
|
headers: {}
|
38
|
-
response:
|
39
|
-
status:
|
37
|
+
response:
|
38
|
+
status:
|
40
39
|
code: 200
|
41
40
|
message: OK
|
42
|
-
headers:
|
43
|
-
Content-Type:
|
41
|
+
headers:
|
42
|
+
Content-Type:
|
44
43
|
- text/html;charset=utf-8
|
45
|
-
Content-Length:
|
44
|
+
Content-Length:
|
46
45
|
- "20"
|
47
|
-
body:
|
46
|
+
body:
|
48
47
|
encoding: UTF-8
|
49
48
|
string: previously recorded response
|
50
49
|
http_version: "1.1"
|
@@ -99,7 +98,7 @@ Feature: before_playback hook
|
|
99
98
|
Scenario: Prevent playback by ignoring interaction in before_playback hook
|
100
99
|
Given a file named "before_playback_ignore.rb" with:
|
101
100
|
"""ruby
|
102
|
-
|
101
|
+
$server = start_sinatra_app do
|
103
102
|
get('/') { "sinatra response" }
|
104
103
|
end
|
105
104
|
|
@@ -111,8 +110,8 @@ Feature: before_playback hook
|
|
111
110
|
c.before_playback { |i| i.ignore! }
|
112
111
|
end
|
113
112
|
|
114
|
-
VCR.use_cassette('localhost', :record => :new_episodes) do
|
115
|
-
response = Net::HTTP.get_response('localhost', '/',
|
113
|
+
VCR.use_cassette('localhost', :record => :new_episodes, :match_requests_on => [:method, :host, :path]) do
|
114
|
+
response = Net::HTTP.get_response('localhost', '/', $server.port)
|
116
115
|
puts "Response: #{response.body}"
|
117
116
|
end
|
118
117
|
"""
|