mustwin-vcr 2.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/features/about_these_examples.md +18 -0
- data/features/cassettes/allow_unused_http_interactions.feature +100 -0
- data/features/cassettes/automatic_re_recording.feature +72 -0
- data/features/cassettes/decompress.feature +74 -0
- data/features/cassettes/dynamic_erb.feature +100 -0
- data/features/cassettes/exclusive.feature +126 -0
- data/features/cassettes/format.feature +323 -0
- data/features/cassettes/freezing_time.feature +68 -0
- data/features/cassettes/naming.feature +28 -0
- data/features/cassettes/no_cassette.feature +152 -0
- data/features/cassettes/update_content_length_header.feature +112 -0
- data/features/configuration/allow_http_connections_when_no_cassette.feature +55 -0
- data/features/configuration/cassette_library_dir.feature +31 -0
- data/features/configuration/debug_logging.feature +59 -0
- data/features/configuration/default_cassette_options.feature +100 -0
- data/features/configuration/filter_sensitive_data.feature +153 -0
- data/features/configuration/hook_into.feature +172 -0
- data/features/configuration/ignore_request.feature +192 -0
- data/features/configuration/preserve_exact_body_bytes.feature +108 -0
- data/features/configuration/query_parser.feature +84 -0
- data/features/configuration/uri_parser.feature +89 -0
- data/features/getting_started.md +82 -0
- data/features/hooks/after_http_request.feature +58 -0
- data/features/hooks/around_http_request.feature +57 -0
- data/features/hooks/before_http_request.feature +63 -0
- data/features/hooks/before_playback.feature +184 -0
- data/features/hooks/before_record.feature +172 -0
- data/features/http_libraries/em_http_request.feature +250 -0
- data/features/http_libraries/net_http.feature +179 -0
- data/features/middleware/faraday.feature +56 -0
- data/features/middleware/rack.feature +92 -0
- data/features/record_modes/all.feature +82 -0
- data/features/record_modes/new_episodes.feature +79 -0
- data/features/record_modes/none.feature +72 -0
- data/features/record_modes/once.feature +95 -0
- data/features/request_matching/README.md +30 -0
- data/features/request_matching/body.feature +91 -0
- data/features/request_matching/body_as_json.feature +90 -0
- data/features/request_matching/custom_matcher.feature +135 -0
- data/features/request_matching/headers.feature +85 -0
- data/features/request_matching/host.feature +95 -0
- data/features/request_matching/identical_request_sequence.feature +89 -0
- data/features/request_matching/method.feature +96 -0
- data/features/request_matching/path.feature +96 -0
- data/features/request_matching/playback_repeats.feature +98 -0
- data/features/request_matching/query.feature +97 -0
- data/features/request_matching/uri.feature +94 -0
- data/features/request_matching/uri_without_param.feature +101 -0
- data/features/step_definitions/cli_steps.rb +193 -0
- data/features/support/env.rb +44 -0
- data/features/support/http_lib_filters.rb +53 -0
- data/features/test_frameworks/cucumber.feature +211 -0
- data/features/test_frameworks/rspec_macro.feature +81 -0
- data/features/test_frameworks/rspec_metadata.feature +150 -0
- data/features/test_frameworks/test_unit.feature +49 -0
- data/lib/vcr.rb +347 -0
- data/lib/vcr/cassette.rb +291 -0
- data/lib/vcr/cassette/erb_renderer.rb +55 -0
- data/lib/vcr/cassette/http_interaction_list.rb +108 -0
- data/lib/vcr/cassette/migrator.rb +118 -0
- data/lib/vcr/cassette/persisters.rb +42 -0
- data/lib/vcr/cassette/persisters/file_system.rb +64 -0
- data/lib/vcr/cassette/serializers.rb +57 -0
- data/lib/vcr/cassette/serializers/json.rb +48 -0
- data/lib/vcr/cassette/serializers/psych.rb +48 -0
- data/lib/vcr/cassette/serializers/syck.rb +61 -0
- data/lib/vcr/cassette/serializers/yaml.rb +50 -0
- data/lib/vcr/configuration.rb +555 -0
- data/lib/vcr/deprecations.rb +109 -0
- data/lib/vcr/errors.rb +266 -0
- data/lib/vcr/extensions/net_http_response.rb +36 -0
- data/lib/vcr/library_hooks.rb +18 -0
- data/lib/vcr/library_hooks/excon.rb +27 -0
- data/lib/vcr/library_hooks/fakeweb.rb +196 -0
- data/lib/vcr/library_hooks/faraday.rb +51 -0
- data/lib/vcr/library_hooks/typhoeus.rb +120 -0
- data/lib/vcr/library_hooks/typhoeus_0.4.rb +103 -0
- data/lib/vcr/library_hooks/webmock.rb +164 -0
- data/lib/vcr/middleware/excon.rb +221 -0
- data/lib/vcr/middleware/excon/legacy_methods.rb +33 -0
- data/lib/vcr/middleware/faraday.rb +118 -0
- data/lib/vcr/middleware/rack.rb +79 -0
- data/lib/vcr/request_handler.rb +114 -0
- data/lib/vcr/request_ignorer.rb +43 -0
- data/lib/vcr/request_matcher_registry.rb +149 -0
- data/lib/vcr/structs.rb +578 -0
- data/lib/vcr/tasks/vcr.rake +9 -0
- data/lib/vcr/test_frameworks/cucumber.rb +64 -0
- data/lib/vcr/test_frameworks/rspec.rb +47 -0
- data/lib/vcr/util/hooks.rb +61 -0
- data/lib/vcr/util/internet_connection.rb +43 -0
- data/lib/vcr/util/logger.rb +59 -0
- data/lib/vcr/util/variable_args_block_caller.rb +13 -0
- data/lib/vcr/util/version_checker.rb +48 -0
- data/lib/vcr/version.rb +34 -0
- data/spec/acceptance/threading_spec.rb +34 -0
- data/spec/fixtures/cassette_spec/1_x_cassette.yml +110 -0
- data/spec/fixtures/cassette_spec/empty.yml +0 -0
- data/spec/fixtures/cassette_spec/example.yml +111 -0
- data/spec/fixtures/cassette_spec/with_localhost_requests.yml +111 -0
- data/spec/fixtures/fake_example_responses.yml +110 -0
- data/spec/fixtures/match_requests_on.yml +187 -0
- data/spec/lib/vcr/cassette/erb_renderer_spec.rb +53 -0
- data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +295 -0
- data/spec/lib/vcr/cassette/migrator_spec.rb +195 -0
- data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +69 -0
- data/spec/lib/vcr/cassette/persisters_spec.rb +39 -0
- data/spec/lib/vcr/cassette/serializers_spec.rb +176 -0
- data/spec/lib/vcr/cassette_spec.rb +618 -0
- data/spec/lib/vcr/configuration_spec.rb +326 -0
- data/spec/lib/vcr/deprecations_spec.rb +85 -0
- data/spec/lib/vcr/errors_spec.rb +162 -0
- data/spec/lib/vcr/extensions/net_http_response_spec.rb +86 -0
- data/spec/lib/vcr/library_hooks/excon_spec.rb +104 -0
- data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +169 -0
- data/spec/lib/vcr/library_hooks/faraday_spec.rb +68 -0
- data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +36 -0
- data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +162 -0
- data/spec/lib/vcr/library_hooks/webmock_spec.rb +118 -0
- data/spec/lib/vcr/library_hooks_spec.rb +51 -0
- data/spec/lib/vcr/middleware/faraday_spec.rb +182 -0
- data/spec/lib/vcr/middleware/rack_spec.rb +115 -0
- data/spec/lib/vcr/request_ignorer_spec.rb +70 -0
- data/spec/lib/vcr/request_matcher_registry_spec.rb +345 -0
- data/spec/lib/vcr/structs_spec.rb +732 -0
- data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +107 -0
- data/spec/lib/vcr/test_frameworks/rspec_spec.rb +83 -0
- data/spec/lib/vcr/util/hooks_spec.rb +158 -0
- data/spec/lib/vcr/util/internet_connection_spec.rb +37 -0
- data/spec/lib/vcr/util/version_checker_spec.rb +31 -0
- data/spec/lib/vcr/version_spec.rb +27 -0
- data/spec/lib/vcr_spec.rb +349 -0
- data/spec/monkey_patches.rb +182 -0
- data/spec/spec_helper.rb +62 -0
- data/spec/support/configuration_stubbing.rb +8 -0
- data/spec/support/cucumber_helpers.rb +35 -0
- data/spec/support/fixnum_extension.rb +10 -0
- data/spec/support/http_library_adapters.rb +289 -0
- data/spec/support/limited_uri.rb +21 -0
- data/spec/support/ruby_interpreter.rb +7 -0
- data/spec/support/shared_example_groups/excon.rb +63 -0
- data/spec/support/shared_example_groups/hook_into_http_library.rb +594 -0
- data/spec/support/shared_example_groups/request_hooks.rb +59 -0
- data/spec/support/sinatra_app.rb +86 -0
- data/spec/support/vcr_localhost_server.rb +76 -0
- data/spec/support/vcr_stub_helpers.rb +17 -0
- metadata +677 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
Feature: Faraday middleware
|
2
|
+
|
3
|
+
VCR provides middleware that can be used with Faraday. You can use this as
|
4
|
+
an alternative to Faraday's built-in test adapter.
|
5
|
+
|
6
|
+
VCR will automatically insert this middleware in the Faraday stack
|
7
|
+
when you configure `hook_into :faraday`. However, if you want to control
|
8
|
+
where the middleware goes in the faraday stack, you can use it yourself.
|
9
|
+
The middleware should come before the Faraday HTTP adapter.
|
10
|
+
|
11
|
+
Note that when you use the middleware directly, you don't need to configure
|
12
|
+
`hook_into :faraday`.
|
13
|
+
|
14
|
+
Scenario Outline: Use Faraday middleware
|
15
|
+
Given a file named "faraday_example.rb" with:
|
16
|
+
"""ruby
|
17
|
+
request_count = 0
|
18
|
+
$server = start_sinatra_app do
|
19
|
+
get('/:path') { "Hello #{params[:path]} #{request_count += 1}" }
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'faraday'
|
23
|
+
require 'vcr'
|
24
|
+
<extra_require>
|
25
|
+
|
26
|
+
VCR.configure do |c|
|
27
|
+
c.default_cassette_options = { :serialize_with => :syck }
|
28
|
+
c.cassette_library_dir = 'cassettes'
|
29
|
+
end
|
30
|
+
|
31
|
+
conn = Faraday::Connection.new(:url => "http://localhost:#{$server.port}") do |builder|
|
32
|
+
builder.use VCR::Middleware::Faraday
|
33
|
+
builder.adapter :<adapter>
|
34
|
+
end
|
35
|
+
|
36
|
+
VCR.use_cassette('example') do
|
37
|
+
puts "Response 1: #{conn.get('/foo').body}"
|
38
|
+
end
|
39
|
+
|
40
|
+
VCR.use_cassette('example') do
|
41
|
+
puts "Response 2: #{conn.get('/foo').body}"
|
42
|
+
end
|
43
|
+
"""
|
44
|
+
When I run `ruby faraday_example.rb`
|
45
|
+
Then the output should contain:
|
46
|
+
"""
|
47
|
+
Response 1: Hello foo 1
|
48
|
+
Response 2: Hello foo 1
|
49
|
+
"""
|
50
|
+
And the file "cassettes/example.yml" should contain "Hello foo 1"
|
51
|
+
|
52
|
+
Examples:
|
53
|
+
| adapter | extra_require |
|
54
|
+
| net_http | |
|
55
|
+
| typhoeus | require 'typhoeus/adapters/faraday' |
|
56
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
Feature: Rack
|
2
|
+
|
3
|
+
VCR provides a rack middleware that uses a cassette for the duration of
|
4
|
+
a request. Simply provide `VCR::Middleware::Rack` with a block that sets
|
5
|
+
the cassette name and options. You can set these based on the rack env
|
6
|
+
if your block accepts two arguments.
|
7
|
+
|
8
|
+
This is useful in a couple different ways:
|
9
|
+
|
10
|
+
- In a rails app, you could use this to log all HTTP API calls made by
|
11
|
+
the rails app (using the `:all` record mode). Of course, this will only
|
12
|
+
record HTTP API calls made in the request-response cycle--API calls that
|
13
|
+
are offloaded to a background job will not be logged.
|
14
|
+
- This can be used as middleware in a simple rack HTTP proxy, to record
|
15
|
+
and replay the proxied requests.
|
16
|
+
|
17
|
+
Background:
|
18
|
+
Given a file named "remote_server.rb" with:
|
19
|
+
"""ruby
|
20
|
+
request_count = 0
|
21
|
+
$server = start_sinatra_app do
|
22
|
+
get('/:path') { "Hello #{params[:path]} #{request_count += 1}" }
|
23
|
+
end
|
24
|
+
"""
|
25
|
+
And a file named "client.rb" with:
|
26
|
+
"""ruby
|
27
|
+
require 'remote_server'
|
28
|
+
require 'proxy_server'
|
29
|
+
require 'cgi'
|
30
|
+
|
31
|
+
url = URI.parse("http://localhost:#{$proxy.port}?url=#{CGI.escape("http://localhost:#{$server.port}/foo")}")
|
32
|
+
|
33
|
+
puts "Response 1: #{Net::HTTP.get_response(url).body}"
|
34
|
+
puts "Response 2: #{Net::HTTP.get_response(url).body}"
|
35
|
+
"""
|
36
|
+
And the directory "cassettes" does not exist
|
37
|
+
|
38
|
+
Scenario: Use VCR rack middleware to record HTTP responses for a simple rack proxy app
|
39
|
+
Given a file named "proxy_server.rb" with:
|
40
|
+
"""ruby
|
41
|
+
require 'vcr'
|
42
|
+
|
43
|
+
$proxy = start_sinatra_app do
|
44
|
+
use VCR::Middleware::Rack do |cassette|
|
45
|
+
cassette.name 'proxied'
|
46
|
+
cassette.options :record => :new_episodes
|
47
|
+
end
|
48
|
+
|
49
|
+
get('/') { Net::HTTP.get_response(URI.parse(params[:url])).body }
|
50
|
+
end
|
51
|
+
|
52
|
+
VCR.configure do |c|
|
53
|
+
c.cassette_library_dir = 'cassettes'
|
54
|
+
c.hook_into :webmock
|
55
|
+
c.allow_http_connections_when_no_cassette = true
|
56
|
+
end
|
57
|
+
"""
|
58
|
+
When I run `ruby client.rb`
|
59
|
+
Then the output should contain:
|
60
|
+
"""
|
61
|
+
Response 1: Hello foo 1
|
62
|
+
Response 2: Hello foo 1
|
63
|
+
"""
|
64
|
+
And the file "cassettes/proxied.yml" should contain "Hello foo 1"
|
65
|
+
|
66
|
+
Scenario: Set cassette name based on rack request env
|
67
|
+
Given a file named "proxy_server.rb" with:
|
68
|
+
"""ruby
|
69
|
+
require 'vcr'
|
70
|
+
|
71
|
+
$proxy = start_sinatra_app do
|
72
|
+
use VCR::Middleware::Rack do |cassette, env|
|
73
|
+
cassette.name env['SERVER_NAME']
|
74
|
+
end
|
75
|
+
|
76
|
+
get('/') { Net::HTTP.get_response(URI.parse(params[:url])).body }
|
77
|
+
end
|
78
|
+
|
79
|
+
VCR.configure do |c|
|
80
|
+
c.cassette_library_dir = 'cassettes'
|
81
|
+
c.hook_into :webmock
|
82
|
+
c.allow_http_connections_when_no_cassette = true
|
83
|
+
end
|
84
|
+
"""
|
85
|
+
When I run `ruby client.rb`
|
86
|
+
Then the output should contain:
|
87
|
+
"""
|
88
|
+
Response 1: Hello foo 1
|
89
|
+
Response 2: Hello foo 1
|
90
|
+
"""
|
91
|
+
And the file "cassettes/localhost.yml" should contain "Hello foo 1"
|
92
|
+
|
@@ -0,0 +1,82 @@
|
|
1
|
+
Feature: :all
|
2
|
+
|
3
|
+
The `:all` record mode will:
|
4
|
+
|
5
|
+
- Record new interactions.
|
6
|
+
- Never replay previously recorded interactions.
|
7
|
+
|
8
|
+
This can be temporarily used to force VCR to re-record
|
9
|
+
a cassette (i.e. to ensure the responses are not out of date)
|
10
|
+
or can be used when you simply want to log all HTTP requests.
|
11
|
+
|
12
|
+
Background:
|
13
|
+
Given a file named "setup.rb" with:
|
14
|
+
"""ruby
|
15
|
+
$server = start_sinatra_app do
|
16
|
+
get('/') { 'Hello' }
|
17
|
+
get('/foo') { 'Goodbye' }
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'vcr'
|
21
|
+
|
22
|
+
VCR.configure do |c|
|
23
|
+
c.hook_into :webmock
|
24
|
+
c.cassette_library_dir = 'cassettes'
|
25
|
+
end
|
26
|
+
"""
|
27
|
+
And a previously recorded cassette file "cassettes/example.yml" with:
|
28
|
+
"""
|
29
|
+
---
|
30
|
+
http_interactions:
|
31
|
+
- request:
|
32
|
+
method: get
|
33
|
+
uri: http://localhost/
|
34
|
+
body:
|
35
|
+
encoding: UTF-8
|
36
|
+
string: ""
|
37
|
+
headers: {}
|
38
|
+
response:
|
39
|
+
status:
|
40
|
+
code: 200
|
41
|
+
message: OK
|
42
|
+
headers:
|
43
|
+
Content-Length:
|
44
|
+
- "20"
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: old response
|
48
|
+
http_version: "1.1"
|
49
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
50
|
+
recorded_with: VCR 2.0.0
|
51
|
+
"""
|
52
|
+
|
53
|
+
Scenario: Re-record previously recorded response
|
54
|
+
Given a file named "re_record.rb" with:
|
55
|
+
"""ruby
|
56
|
+
require 'setup'
|
57
|
+
|
58
|
+
VCR.use_cassette('example', :record => :all, :match_requests_on => [:method, :host, :path]) do
|
59
|
+
response = Net::HTTP.get_response('localhost', '/', $server.port)
|
60
|
+
puts "Response: #{response.body}"
|
61
|
+
end
|
62
|
+
"""
|
63
|
+
When I run `ruby re_record.rb`
|
64
|
+
Then it should pass with "Response: Hello"
|
65
|
+
And the file "cassettes/example.yml" should contain "Hello"
|
66
|
+
But the file "cassettes/example.yml" should not contain "old response"
|
67
|
+
|
68
|
+
Scenario: Record new request
|
69
|
+
Given a file named "record_new.rb" with:
|
70
|
+
"""ruby
|
71
|
+
require 'setup'
|
72
|
+
|
73
|
+
VCR.use_cassette('example', :record => :all) do
|
74
|
+
response = Net::HTTP.get_response('localhost', '/foo', $server.port)
|
75
|
+
puts "Response: #{response.body}"
|
76
|
+
end
|
77
|
+
"""
|
78
|
+
When I run `ruby record_new.rb`
|
79
|
+
Then it should pass with "Response: Goodbye"
|
80
|
+
And the file "cassettes/example.yml" should contain each of these:
|
81
|
+
| old response |
|
82
|
+
| Goodbye |
|
@@ -0,0 +1,79 @@
|
|
1
|
+
Feature: :new_episodes
|
2
|
+
|
3
|
+
The `:new_episodes` record mode will:
|
4
|
+
|
5
|
+
- Record new interactions.
|
6
|
+
- Replay previously recorded interactions.
|
7
|
+
|
8
|
+
It is similar to the `:once` record mode, but will _always_ record new
|
9
|
+
interactions, even if you have an existing recorded one that is similar
|
10
|
+
(but not identical, based on the `:match_request_on` option).
|
11
|
+
|
12
|
+
Background:
|
13
|
+
Given a file named "setup.rb" with:
|
14
|
+
"""ruby
|
15
|
+
$server = start_sinatra_app do
|
16
|
+
get('/') { 'Hello' }
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'vcr'
|
20
|
+
|
21
|
+
VCR.configure do |c|
|
22
|
+
c.hook_into :webmock
|
23
|
+
c.cassette_library_dir = 'cassettes'
|
24
|
+
end
|
25
|
+
"""
|
26
|
+
And a previously recorded cassette file "cassettes/example.yml" with:
|
27
|
+
"""
|
28
|
+
---
|
29
|
+
http_interactions:
|
30
|
+
- request:
|
31
|
+
method: get
|
32
|
+
uri: http://example.com/foo
|
33
|
+
body:
|
34
|
+
encoding: UTF-8
|
35
|
+
string: ""
|
36
|
+
headers: {}
|
37
|
+
response:
|
38
|
+
status:
|
39
|
+
code: 200
|
40
|
+
message: OK
|
41
|
+
headers:
|
42
|
+
Content-Length:
|
43
|
+
- "20"
|
44
|
+
body:
|
45
|
+
encoding: UTF-8
|
46
|
+
string: example.com response
|
47
|
+
http_version: "1.1"
|
48
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
49
|
+
recorded_with: VCR 2.0.0
|
50
|
+
"""
|
51
|
+
|
52
|
+
Scenario: Previously recorded responses are replayed
|
53
|
+
Given a file named "replay_recorded_response.rb" with:
|
54
|
+
"""ruby
|
55
|
+
require 'setup'
|
56
|
+
|
57
|
+
VCR.use_cassette('example', :record => :new_episodes) do
|
58
|
+
response = Net::HTTP.get_response('example.com', '/foo')
|
59
|
+
puts "Response: #{response.body}"
|
60
|
+
end
|
61
|
+
"""
|
62
|
+
When I run `ruby replay_recorded_response.rb`
|
63
|
+
Then it should pass with "Response: example.com response"
|
64
|
+
|
65
|
+
Scenario: New requests get recorded
|
66
|
+
Given a file named "record_new_requests.rb" with:
|
67
|
+
"""ruby
|
68
|
+
require 'setup'
|
69
|
+
|
70
|
+
VCR.use_cassette('example', :record => :new_episodes) do
|
71
|
+
response = Net::HTTP.get_response('localhost', '/', $server.port)
|
72
|
+
puts "Response: #{response.body}"
|
73
|
+
end
|
74
|
+
"""
|
75
|
+
When I run `ruby record_new_requests.rb`
|
76
|
+
Then it should pass with "Response: Hello"
|
77
|
+
And the file "cassettes/example.yml" should contain each of these:
|
78
|
+
| example.com response |
|
79
|
+
| Hello |
|
@@ -0,0 +1,72 @@
|
|
1
|
+
Feature: :none
|
2
|
+
|
3
|
+
The `:none` record mode will:
|
4
|
+
|
5
|
+
- Replay previously recorded interactions.
|
6
|
+
- Cause an error to be raised for any new requests.
|
7
|
+
|
8
|
+
This is useful when your code makes potentially dangerous
|
9
|
+
HTTP requests. The `:none` record mode guarantees that no
|
10
|
+
new HTTP requests will be made.
|
11
|
+
|
12
|
+
Background:
|
13
|
+
Given a file named "vcr_config.rb" with:
|
14
|
+
"""ruby
|
15
|
+
require 'vcr'
|
16
|
+
|
17
|
+
VCR.configure do |c|
|
18
|
+
c.hook_into :webmock
|
19
|
+
c.cassette_library_dir = 'cassettes'
|
20
|
+
end
|
21
|
+
"""
|
22
|
+
And a previously recorded cassette file "cassettes/example.yml" with:
|
23
|
+
"""
|
24
|
+
---
|
25
|
+
http_interactions:
|
26
|
+
- request:
|
27
|
+
method: get
|
28
|
+
uri: http://example.com/foo
|
29
|
+
body:
|
30
|
+
encoding: UTF-8
|
31
|
+
string: ""
|
32
|
+
headers: {}
|
33
|
+
response:
|
34
|
+
status:
|
35
|
+
code: 200
|
36
|
+
message: OK
|
37
|
+
headers:
|
38
|
+
Content-Length:
|
39
|
+
- "5"
|
40
|
+
body:
|
41
|
+
encoding: UTF-8
|
42
|
+
string: Hello
|
43
|
+
http_version: "1.1"
|
44
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
45
|
+
recorded_with: VCR 2.0.0
|
46
|
+
"""
|
47
|
+
|
48
|
+
Scenario: Previously recorded responses are replayed
|
49
|
+
Given a file named "replay_recorded_response.rb" with:
|
50
|
+
"""ruby
|
51
|
+
require 'vcr_config'
|
52
|
+
|
53
|
+
VCR.use_cassette('example', :record => :none) do
|
54
|
+
response = Net::HTTP.get_response('example.com', '/foo')
|
55
|
+
puts "Response: #{response.body}"
|
56
|
+
end
|
57
|
+
"""
|
58
|
+
When I run `ruby replay_recorded_response.rb`
|
59
|
+
Then it should pass with "Response: Hello"
|
60
|
+
|
61
|
+
@exclude-jruby
|
62
|
+
Scenario: New requests are prevented
|
63
|
+
Given a file named "prevent_new_request.rb" with:
|
64
|
+
"""ruby
|
65
|
+
require 'vcr_config'
|
66
|
+
|
67
|
+
VCR.use_cassette('example', :record => :none) do
|
68
|
+
Net::HTTP.get_response('example.com', '/bar')
|
69
|
+
end
|
70
|
+
"""
|
71
|
+
When I run `ruby prevent_new_request.rb`
|
72
|
+
Then it should fail with "An HTTP request has been made that VCR does not know how to handle"
|
@@ -0,0 +1,95 @@
|
|
1
|
+
Feature: :once
|
2
|
+
|
3
|
+
The `:once` record mode will:
|
4
|
+
|
5
|
+
- Replay previously recorded interactions.
|
6
|
+
- Record new interactions if there is no cassette file.
|
7
|
+
- Cause an error to be raised for new requests if there is a cassette file.
|
8
|
+
|
9
|
+
It is similar to the `:new_episodes` record mode, but will prevent new,
|
10
|
+
unexpected requests from being made (i.e. because the request URI changed
|
11
|
+
or whatever).
|
12
|
+
|
13
|
+
`:once` is the default record mode, used when you do not set one.
|
14
|
+
|
15
|
+
Background:
|
16
|
+
Given a file named "setup.rb" with:
|
17
|
+
"""ruby
|
18
|
+
$server = start_sinatra_app do
|
19
|
+
get('/') { 'Hello' }
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'vcr'
|
23
|
+
|
24
|
+
VCR.configure do |c|
|
25
|
+
c.hook_into :webmock
|
26
|
+
c.cassette_library_dir = 'cassettes'
|
27
|
+
end
|
28
|
+
"""
|
29
|
+
And a previously recorded cassette file "cassettes/example.yml" with:
|
30
|
+
"""
|
31
|
+
---
|
32
|
+
http_interactions:
|
33
|
+
- request:
|
34
|
+
method: get
|
35
|
+
uri: http://example.com/foo
|
36
|
+
body:
|
37
|
+
encoding: UTF-8
|
38
|
+
string: ""
|
39
|
+
headers: {}
|
40
|
+
response:
|
41
|
+
status:
|
42
|
+
code: 200
|
43
|
+
message: OK
|
44
|
+
headers:
|
45
|
+
Content-Length:
|
46
|
+
- "20"
|
47
|
+
body:
|
48
|
+
encoding: UTF-8
|
49
|
+
string: example.com response
|
50
|
+
http_version: "1.1"
|
51
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
52
|
+
recorded_with: VCR 2.0.0
|
53
|
+
"""
|
54
|
+
|
55
|
+
Scenario: Previously recorded responses are replayed
|
56
|
+
Given a file named "replay_recorded_response.rb" with:
|
57
|
+
"""ruby
|
58
|
+
require 'setup'
|
59
|
+
|
60
|
+
VCR.use_cassette('example', :record => :once) do
|
61
|
+
response = Net::HTTP.get_response('example.com', '/foo')
|
62
|
+
puts "Response: #{response.body}"
|
63
|
+
end
|
64
|
+
"""
|
65
|
+
When I run `ruby replay_recorded_response.rb`
|
66
|
+
Then it should pass with "Response: example.com response"
|
67
|
+
|
68
|
+
@exclude-jruby
|
69
|
+
Scenario: New requests result in an error when the cassette file exists
|
70
|
+
Given a file named "error_for_new_requests_when_cassette_exists.rb" with:
|
71
|
+
"""ruby
|
72
|
+
require 'setup'
|
73
|
+
|
74
|
+
VCR.use_cassette('example', :record => :once) do
|
75
|
+
response = Net::HTTP.get_response('localhost', '/', $server.port)
|
76
|
+
puts "Response: #{response.body}"
|
77
|
+
end
|
78
|
+
"""
|
79
|
+
When I run `ruby error_for_new_requests_when_cassette_exists.rb`
|
80
|
+
Then it should fail with "An HTTP request has been made that VCR does not know how to handle"
|
81
|
+
|
82
|
+
Scenario: New requests get recorded when there is no cassette file
|
83
|
+
Given a file named "record_new_requests.rb" with:
|
84
|
+
"""ruby
|
85
|
+
require 'setup'
|
86
|
+
|
87
|
+
VCR.use_cassette('example', :record => :once) do
|
88
|
+
response = Net::HTTP.get_response('localhost', '/', $server.port)
|
89
|
+
puts "Response: #{response.body}"
|
90
|
+
end
|
91
|
+
"""
|
92
|
+
When I remove the file "cassettes/example.yml"
|
93
|
+
And I run `ruby record_new_requests.rb`
|
94
|
+
Then it should pass with "Response: Hello"
|
95
|
+
And the file "cassettes/example.yml" should contain "Hello"
|