vcr 3.0.3 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +5 -5
  2. data/lib/vcr/cassette/erb_renderer.rb +4 -2
  3. data/lib/vcr/cassette/http_interaction_list.rb +14 -9
  4. data/lib/vcr/cassette/migrator.rb +5 -6
  5. data/lib/vcr/cassette/persisters/file_system.rb +9 -1
  6. data/lib/vcr/cassette/serializers/compressed.rb +2 -2
  7. data/lib/vcr/cassette/serializers/json.rb +14 -8
  8. data/lib/vcr/cassette/serializers/psych.rb +10 -2
  9. data/lib/vcr/cassette/serializers/syck.rb +7 -1
  10. data/lib/vcr/cassette/serializers/yaml.rb +14 -2
  11. data/lib/vcr/cassette/serializers.rb +10 -0
  12. data/lib/vcr/cassette.rb +63 -16
  13. data/lib/vcr/configuration.rb +21 -8
  14. data/lib/vcr/deprecations.rb +0 -62
  15. data/lib/vcr/errors.rb +17 -12
  16. data/lib/vcr/library_hooks/excon.rb +8 -0
  17. data/lib/vcr/library_hooks/typhoeus.rb +91 -79
  18. data/lib/vcr/library_hooks/webmock.rb +2 -11
  19. data/lib/vcr/linked_cassette.rb +4 -4
  20. data/lib/vcr/middleware/excon.rb +1 -1
  21. data/lib/vcr/middleware/faraday.rb +29 -2
  22. data/lib/vcr/request_ignorer.rb +8 -1
  23. data/lib/vcr/request_matcher_registry.rb +3 -3
  24. data/lib/vcr/structs.rb +48 -32
  25. data/lib/vcr/test_frameworks/cucumber.rb +16 -5
  26. data/lib/vcr/test_frameworks/rspec.rb +34 -22
  27. data/lib/vcr/util/hooks.rb +1 -0
  28. data/lib/vcr/util/internet_connection.rb +15 -21
  29. data/lib/vcr/version.rb +2 -2
  30. data/lib/vcr.rb +52 -2
  31. metadata +45 -272
  32. data/features/CHANGELOG.md +0 -710
  33. data/features/CONTRIBUTING.md +0 -26
  34. data/features/LICENSE.md +0 -20
  35. data/features/README.md +0 -339
  36. data/features/Upgrade.md +0 -289
  37. data/features/about_these_examples.md +0 -18
  38. data/features/cassettes/allow_unused_http_interactions.feature +0 -100
  39. data/features/cassettes/automatic_re_recording.feature +0 -72
  40. data/features/cassettes/decompress.feature +0 -74
  41. data/features/cassettes/dynamic_erb.feature +0 -100
  42. data/features/cassettes/exclusive.feature +0 -126
  43. data/features/cassettes/format.feature +0 -411
  44. data/features/cassettes/freezing_time.feature +0 -68
  45. data/features/cassettes/naming.feature +0 -28
  46. data/features/cassettes/no_cassette.feature +0 -152
  47. data/features/cassettes/update_content_length_header.feature +0 -112
  48. data/features/configuration/allow_http_connections_when_no_cassette.feature +0 -55
  49. data/features/configuration/cassette_library_dir.feature +0 -31
  50. data/features/configuration/debug_logging.feature +0 -58
  51. data/features/configuration/default_cassette_options.feature +0 -100
  52. data/features/configuration/filter_sensitive_data.feature +0 -153
  53. data/features/configuration/hook_into.feature +0 -172
  54. data/features/configuration/ignore_request.feature +0 -192
  55. data/features/configuration/preserve_exact_body_bytes.feature +0 -108
  56. data/features/configuration/query_parser.feature +0 -84
  57. data/features/configuration/uri_parser.feature +0 -93
  58. data/features/getting_started.md +0 -82
  59. data/features/hooks/after_http_request.feature +0 -58
  60. data/features/hooks/around_http_request.feature +0 -57
  61. data/features/hooks/before_http_request.feature +0 -63
  62. data/features/hooks/before_playback.feature +0 -184
  63. data/features/hooks/before_record.feature +0 -172
  64. data/features/http_libraries/em_http_request.feature +0 -250
  65. data/features/http_libraries/net_http.feature +0 -179
  66. data/features/middleware/faraday.feature +0 -56
  67. data/features/middleware/rack.feature +0 -92
  68. data/features/record_modes/all.feature +0 -82
  69. data/features/record_modes/new_episodes.feature +0 -79
  70. data/features/record_modes/none.feature +0 -72
  71. data/features/record_modes/once.feature +0 -95
  72. data/features/request_matching/README.md +0 -30
  73. data/features/request_matching/body.feature +0 -91
  74. data/features/request_matching/body_as_json.feature +0 -90
  75. data/features/request_matching/custom_matcher.feature +0 -135
  76. data/features/request_matching/headers.feature +0 -85
  77. data/features/request_matching/host.feature +0 -95
  78. data/features/request_matching/identical_request_sequence.feature +0 -89
  79. data/features/request_matching/method.feature +0 -96
  80. data/features/request_matching/path.feature +0 -96
  81. data/features/request_matching/playback_repeats.feature +0 -98
  82. data/features/request_matching/query.feature +0 -97
  83. data/features/request_matching/uri.feature +0 -94
  84. data/features/request_matching/uri_without_param.feature +0 -101
  85. data/features/step_definitions/cli_steps.rb +0 -199
  86. data/features/support/env.rb +0 -46
  87. data/features/support/http_lib_filters.rb +0 -46
  88. data/features/test_frameworks/cucumber.feature +0 -211
  89. data/features/test_frameworks/rspec_macro.feature +0 -81
  90. data/features/test_frameworks/rspec_metadata.feature +0 -150
  91. data/features/test_frameworks/test_unit.feature +0 -49
  92. data/lib/vcr/extensions/net_http_response.rb +0 -36
  93. data/lib/vcr/library_hooks/fakeweb.rb +0 -197
  94. data/lib/vcr/library_hooks/typhoeus_0.4.rb +0 -103
  95. data/spec/acceptance/concurrency_spec.rb +0 -51
  96. data/spec/acceptance/threading_spec.rb +0 -34
  97. data/spec/fixtures/cassette_spec/1_x_cassette.yml +0 -110
  98. data/spec/fixtures/cassette_spec/empty.yml +0 -0
  99. data/spec/fixtures/cassette_spec/example.yml +0 -111
  100. data/spec/fixtures/cassette_spec/with_localhost_requests.yml +0 -111
  101. data/spec/fixtures/fake_example_responses.yml +0 -110
  102. data/spec/fixtures/match_requests_on.yml +0 -187
  103. data/spec/lib/vcr/cassette/erb_renderer_spec.rb +0 -53
  104. data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +0 -295
  105. data/spec/lib/vcr/cassette/migrator_spec.rb +0 -196
  106. data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +0 -75
  107. data/spec/lib/vcr/cassette/persisters_spec.rb +0 -39
  108. data/spec/lib/vcr/cassette/serializers_spec.rb +0 -182
  109. data/spec/lib/vcr/cassette_spec.rb +0 -618
  110. data/spec/lib/vcr/configuration_spec.rb +0 -326
  111. data/spec/lib/vcr/deprecations_spec.rb +0 -85
  112. data/spec/lib/vcr/errors_spec.rb +0 -178
  113. data/spec/lib/vcr/extensions/net_http_response_spec.rb +0 -86
  114. data/spec/lib/vcr/library_hooks/excon_spec.rb +0 -104
  115. data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +0 -169
  116. data/spec/lib/vcr/library_hooks/faraday_spec.rb +0 -68
  117. data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +0 -36
  118. data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +0 -162
  119. data/spec/lib/vcr/library_hooks/webmock_spec.rb +0 -117
  120. data/spec/lib/vcr/library_hooks_spec.rb +0 -51
  121. data/spec/lib/vcr/middleware/faraday_spec.rb +0 -181
  122. data/spec/lib/vcr/middleware/rack_spec.rb +0 -115
  123. data/spec/lib/vcr/request_ignorer_spec.rb +0 -70
  124. data/spec/lib/vcr/request_matcher_registry_spec.rb +0 -345
  125. data/spec/lib/vcr/structs_spec.rb +0 -732
  126. data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +0 -107
  127. data/spec/lib/vcr/test_frameworks/rspec_spec.rb +0 -94
  128. data/spec/lib/vcr/util/hooks_spec.rb +0 -158
  129. data/spec/lib/vcr/util/internet_connection_spec.rb +0 -37
  130. data/spec/lib/vcr/util/version_checker_spec.rb +0 -31
  131. data/spec/lib/vcr/version_spec.rb +0 -27
  132. data/spec/lib/vcr_spec.rb +0 -354
  133. data/spec/monkey_patches.rb +0 -186
  134. data/spec/spec_helper.rb +0 -63
  135. data/spec/support/configuration_stubbing.rb +0 -8
  136. data/spec/support/cucumber_helpers.rb +0 -39
  137. data/spec/support/fixnum_extension.rb +0 -10
  138. data/spec/support/http_library_adapters.rb +0 -289
  139. data/spec/support/limited_uri.rb +0 -21
  140. data/spec/support/ruby_interpreter.rb +0 -7
  141. data/spec/support/shared_example_groups/excon.rb +0 -63
  142. data/spec/support/shared_example_groups/hook_into_http_library.rb +0 -594
  143. data/spec/support/shared_example_groups/request_hooks.rb +0 -59
  144. data/spec/support/sinatra_app.rb +0 -86
  145. data/spec/support/vcr_localhost_server.rb +0 -76
  146. data/spec/support/vcr_stub_helpers.rb +0 -17
@@ -1,152 +0,0 @@
1
- Feature: Error for HTTP request made when no cassette is in use
2
-
3
- VCR is designed to help you remove all HTTP dependencies from your
4
- test suite. To assist with this, VCR will cause an exception to be
5
- raised when an HTTP request is made while there is no cassette in
6
- use. The error is helpful to pinpoint where HTTP requests are
7
- made so you can use a VCR cassette at that point in your code.
8
-
9
- If you want insight about how VCR attempted to handle the request,
10
- you can use the [debug\_logger](../configuration/debug-logging)
11
- configuration option to log more details.
12
-
13
- If you want to allow an HTTP request to proceed as normal, you can
14
- set the [allow\_http\_connections\_when\_no\_cassette](../configuration/allow-http-connections-when-no-cassette)
15
- configuration option or you can temporarily turn VCR off:
16
-
17
- - `VCR.turn_off!` => turn VCR off so HTTP requests are allowed.
18
- Cassette insertions will trigger an error.
19
- - `VCR.turn_off!(:ignore_cassettes => true)` => turn
20
- VCR off and ignore cassette insertions (so that no error is raised).
21
- - `VCR.turn_on!` => turn VCR back on
22
- - `VCR.turned_off { ... }` => turn VCR off for the duration of the
23
- provided block.
24
-
25
- @exclude-jruby
26
- Scenario Outline: Error for request when no cassette is in use
27
- Given a file named "no_cassette_error.rb" with:
28
- """ruby
29
- include_http_adapter_for("<http_lib>")
30
-
31
- require 'vcr'
32
-
33
- VCR.configure do |c|
34
- <configuration>
35
- c.cassette_library_dir = 'cassettes'
36
- end
37
-
38
- response_body_for(:get, 'http://example.com/')
39
- """
40
- When I run `ruby no_cassette_error.rb`
41
- Then it should fail with "An HTTP request has been made that VCR does not know how to handle"
42
-
43
- Examples:
44
- | configuration | http_lib |
45
- | c.hook_into :fakeweb | net/http |
46
- | c.hook_into :webmock | net/http |
47
- | c.hook_into :webmock | httpclient |
48
- | c.hook_into :webmock | curb |
49
- | c.hook_into :webmock | patron |
50
- | c.hook_into :webmock | em-http-request |
51
- | c.hook_into :webmock | typhoeus |
52
- | c.hook_into :typhoeus | typhoeus |
53
- | c.hook_into :excon | excon |
54
- | c.hook_into :faraday | faraday (w/ net_http) |
55
-
56
- Scenario: Temporarily turn VCR off to allow HTTP requests to procede as normal
57
- Given a file named "turn_off_vcr.rb" with:
58
- """ruby
59
- $server = start_sinatra_app do
60
- get('/') { 'Hello' }
61
- end
62
-
63
- require 'vcr'
64
-
65
- VCR.configure do |c|
66
- c.hook_into :webmock
67
- end
68
- WebMock.allow_net_connect!
69
-
70
- def make_request(context)
71
- puts context
72
- puts Net::HTTP.get_response('localhost', '/', $server.port).body
73
- rescue => e
74
- puts "Error: #{e.class}"
75
- end
76
-
77
- VCR.turned_off do
78
- make_request "In VCR.turned_off block"
79
- end
80
-
81
- make_request "Outside of VCR.turned_off block"
82
-
83
- VCR.turn_off!
84
- make_request "After calling VCR.turn_off!"
85
-
86
- VCR.turn_on!
87
- make_request "After calling VCR.turn_on!"
88
- """
89
- When I run `ruby turn_off_vcr.rb`
90
- Then the output should contain:
91
- """
92
- In VCR.turned_off block
93
- Hello
94
- """
95
- And the output should contain:
96
- """
97
- Outside of VCR.turned_off block
98
- Error: VCR::Errors::UnhandledHTTPRequestError
99
- """
100
- And the output should contain:
101
- """
102
- After calling VCR.turn_off!
103
- Hello
104
- """
105
- And the output should contain:
106
- """
107
- After calling VCR.turn_on!
108
- Error: VCR::Errors::UnhandledHTTPRequestError
109
- """
110
-
111
- Scenario: Turning VCR off prevents cassettes from being inserted
112
- Given a file named "turn_off_vcr_and_insert_cassette.rb" with:
113
- """ruby
114
- require 'vcr'
115
-
116
- VCR.configure do |c|
117
- c.hook_into :webmock
118
- end
119
- WebMock.allow_net_connect!
120
-
121
- VCR.turn_off!
122
- VCR.insert_cassette('example')
123
- """
124
- When I run `ruby turn_off_vcr_and_insert_cassette.rb`
125
- Then it should fail with "VCR is turned off. You must turn it on before you can insert a cassette."
126
-
127
- Scenario: Turning VCR off with `:ignore_cassettes => true` ignores cassettes
128
- Given a file named "turn_off_vcr_and_insert_cassette.rb" with:
129
- """ruby
130
- $server = start_sinatra_app do
131
- get('/') { 'Hello' }
132
- end
133
-
134
- require 'vcr'
135
-
136
- VCR.configure do |c|
137
- c.cassette_library_dir = 'cassettes'
138
- c.hook_into :webmock
139
- end
140
- WebMock.allow_net_connect!
141
-
142
- VCR.turn_off!(:ignore_cassettes => true)
143
-
144
- VCR.use_cassette('example') do
145
- response = Net::HTTP.get_response('localhost', '/', $server.port).body
146
- puts "Response: #{response}"
147
- end
148
- """
149
- When I run `ruby turn_off_vcr_and_insert_cassette.rb`
150
- Then it should pass with "Response: Hello"
151
- And the file "cassettes/example.yml" should not exist
152
-
@@ -1,112 +0,0 @@
1
- Feature: Update content_length header
2
-
3
- When the `:update_content_length_header` option is set to a truthy value,
4
- VCR will ensure that the `Content-Length` header will have the correct
5
- value. This is useful in several situations:
6
-
7
- - When you manually edit the cassette file and change the resonse body
8
- length. You can use this option so you don't have to manually calculate
9
- and update the body length.
10
- - When you use ERB, the response body length may vary. This will ensure
11
- it is always correct.
12
- - Syck, the default YAML engine for ruby 1.8 (and 1.9, unless you compile
13
- it to use Psych), has a bug where it sometimes will remove some
14
- whitespace strings when you serialize them. This may cause the
15
- `Content-Length` header to have the wrong value.
16
-
17
- This is especially important when you use a client that checks the
18
- `Content-Length` header. Mechanize, for example, will raise an `EOFError`
19
- when the header value does not match the actual body length.
20
-
21
- Background:
22
- Given a previously recorded cassette file "cassettes/example.yml" with:
23
- """
24
- ---
25
- http_interactions:
26
- - request:
27
- method: get
28
- uri: http://example.com/
29
- body:
30
- encoding: UTF-8
31
- string: ""
32
- headers: {}
33
- response:
34
- status:
35
- code: 200
36
- message: OK
37
- headers:
38
- Content-Type:
39
- - text/html;charset=utf-8
40
- Content-Length:
41
- - "11"
42
- body:
43
- encoding: UTF-8
44
- string: Hello <modified>
45
- http_version: "1.1"
46
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
47
- recorded_with: VCR 2.0.0
48
- """
49
- And a file named "common_stuff.rb" with:
50
- """ruby
51
- require 'vcr'
52
-
53
- VCR.configure do |c|
54
- c.cassette_library_dir = 'cassettes'
55
- c.hook_into :webmock
56
- end
57
-
58
- def make_request_and_print_results
59
- response = Net::HTTP.get_response('example.com', '/')
60
- puts "Body length: #{response.body.length}"
61
- puts "Header value: #{response['Content-Length']}"
62
- end
63
- """
64
-
65
- Scenario: Default :update_content_length_header setting
66
- Given a file named "default.rb" with:
67
- """ruby
68
- require 'common_stuff'
69
-
70
- VCR.use_cassette('example') do
71
- make_request_and_print_results
72
- end
73
- """
74
- When I run `ruby default.rb`
75
- Then the output should contain:
76
- """
77
- Body length: 16
78
- Header value: 11
79
- """
80
-
81
- Scenario: :update_content_length_header => false
82
- Given a file named "false.rb" with:
83
- """ruby
84
- require 'common_stuff'
85
-
86
- VCR.use_cassette('example', :update_content_length_header => false) do
87
- make_request_and_print_results
88
- end
89
- """
90
- When I run `ruby false.rb`
91
- Then the output should contain:
92
- """
93
- Body length: 16
94
- Header value: 11
95
- """
96
-
97
- Scenario: :update_content_length_header => true
98
- Given a file named "true.rb" with:
99
- """ruby
100
- require 'common_stuff'
101
-
102
- VCR.use_cassette('example', :update_content_length_header => true) do
103
- make_request_and_print_results
104
- end
105
- """
106
- When I run `ruby true.rb`
107
- Then the output should contain:
108
- """
109
- Body length: 16
110
- Header value: 16
111
- """
112
-
@@ -1,55 +0,0 @@
1
- Feature: Allow HTTP connections when no cassette
2
-
3
- Usually, HTTP requests made when no cassette is inserted will [result in an
4
- error](../cassettes/error-for-http-request-made-when-no-cassette-is-in-use).
5
- You can set the `allow_http_connections_when_no_cassette` configuration option
6
- to true to allow requests, if you do not want to use VCR for everything.
7
-
8
- Background:
9
- Given a file named "vcr_setup.rb" with:
10
- """ruby
11
- if ARGV.include?('--with-server')
12
- $server = start_sinatra_app do
13
- get('/') { "Hello" }
14
- end
15
- end
16
-
17
- require 'vcr'
18
-
19
- VCR.configure do |c|
20
- c.allow_http_connections_when_no_cassette = true
21
- c.hook_into :webmock
22
- c.cassette_library_dir = 'cassettes'
23
- c.default_cassette_options = {
24
- :match_requests_on => [:method, :host, :path]
25
- }
26
- end
27
- """
28
- And the directory "vcr/cassettes" does not exist
29
-
30
- Scenario: Allow HTTP connections when no cassette
31
- Given a file named "no_cassette.rb" with:
32
- """ruby
33
- require 'vcr_setup.rb'
34
-
35
- puts "Response: " + Net::HTTP.get_response('localhost', '/', $server ? $server.port : 0).body
36
- """
37
- When I run `ruby no_cassette.rb --with-server`
38
- Then the output should contain "Response: Hello"
39
-
40
- Scenario: Cassettes record and replay as normal
41
- Given a file named "record_replay_cassette.rb" with:
42
- """ruby
43
- require 'vcr_setup.rb'
44
-
45
- VCR.use_cassette('localhost') do
46
- puts "Response: " + Net::HTTP.get_response('localhost', '/', $server ? $server.port : 0).body
47
- end
48
- """
49
- When I run `ruby record_replay_cassette.rb --with-server`
50
- Then the output should contain "Response: Hello"
51
- And the file "cassettes/localhost.yml" should contain "Hello"
52
-
53
- When I run `ruby record_replay_cassette.rb`
54
- Then the output should contain "Response: Hello"
55
-
@@ -1,31 +0,0 @@
1
- Feature: cassette_library_dir
2
-
3
- The `cassette_library_dir` configuration option sets a directory
4
- where VCR saves each cassette.
5
-
6
- Note: When using Rails, avoid using the `test/fixtures` directory
7
- to store the cassettes. Rails treats any YAML file in the fixtures
8
- directory as an ActiveRecord fixture.
9
- This will cause an `ActiveRecord::Fixture::FormatError` to be raised.
10
-
11
- Scenario: cassette_library_dir
12
- Given a file named "cassette_library_dir.rb" with:
13
- """ruby
14
- $server = start_sinatra_app do
15
- get('/') { "Hello" }
16
- end
17
-
18
- require 'vcr'
19
-
20
- VCR.configure do |c|
21
- c.cassette_library_dir = 'vcr/cassettes'
22
- c.hook_into :webmock
23
- end
24
-
25
- VCR.use_cassette('localhost') do
26
- Net::HTTP.get_response('localhost', '/', $server.port)
27
- end
28
- """
29
- And the directory "vcr/cassettes" does not exist
30
- When I run `ruby cassette_library_dir.rb`
31
- Then the file "vcr/cassettes/localhost.yml" should exist
@@ -1,58 +0,0 @@
1
- Feature: Debug Logging
2
-
3
- Use the `debug_logger` option to set an IO-like object that VCR will log
4
- debug output to. This is a useful way to troubleshoot what VCR is doing.
5
-
6
- The debug logger must respond to `#puts`.
7
-
8
- Scenario: Use the debug logger for troubleshooting
9
- Given a file named "debug_logger.rb" with:
10
- """ruby
11
- if ARGV.include?('--with-server')
12
- $server = start_sinatra_app do
13
- get('/') { "Hello World" }
14
- end
15
- end
16
-
17
- require 'vcr'
18
-
19
- VCR.configure do |c|
20
- c.hook_into :webmock
21
- c.cassette_library_dir = 'cassettes'
22
- c.debug_logger = File.open(ARGV.first, 'w')
23
- c.default_cassette_options = {
24
- :match_requests_on => [:method, :host, :path]
25
- }
26
- end
27
-
28
- VCR.use_cassette('example') do
29
- port = $server ? $server.port : 7777
30
- Net::HTTP.get_response(URI("http://localhost:#{port}/"))
31
- end
32
- """
33
- When I run `ruby debug_logger.rb record.log --with-server`
34
- Given that port numbers in "record.log" are normalized to "7777"
35
- Then the file "record.log" should contain exactly:
36
- """
37
- [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}
38
- [webmock] Handling request: [get http://localhost:7777/] (disabled: false)
39
- [Cassette: 'example'] Initialized HTTPInteractionList with request matchers [:method, :host, :path] and 0 interaction(s): { }
40
- [webmock] Identified request type (recordable) for [get http://localhost:7777/]
41
- [Cassette: 'example'] Recorded HTTP interaction [get http://localhost:7777/] => [200 "Hello World"]
42
-
43
- """
44
- When I run `ruby debug_logger.rb playback.log`
45
- Given that port numbers in "playback.log" are normalized to "7777"
46
- Then the file "playback.log" should contain exactly:
47
- """
48
- [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}
49
- [webmock] Handling request: [get http://localhost:7777/] (disabled: false)
50
- [Cassette: 'example'] Initialized HTTPInteractionList with request matchers [:method, :host, :path] and 1 interaction(s): { [get http://localhost:7777/] => [200 "Hello World"] }
51
- [Cassette: 'example'] Checking if [get http://localhost:7777/] matches [get http://localhost:7777/] using [:method, :host, :path]
52
- [Cassette: 'example'] method (matched): current request [get http://localhost:7777/] vs [get http://localhost:7777/]
53
- [Cassette: 'example'] host (matched): current request [get http://localhost:7777/] vs [get http://localhost:7777/]
54
- [Cassette: 'example'] path (matched): current request [get http://localhost:7777/] vs [get http://localhost:7777/]
55
- [Cassette: 'example'] Found matching interaction for [get http://localhost:7777/] at index 0: [200 "Hello World"]
56
- [webmock] Identified request type (stubbed_by_vcr) for [get http://localhost:7777/]
57
-
58
- """
@@ -1,100 +0,0 @@
1
- Feature: default_cassette_options
2
-
3
- The `default_cassette_options` configuration option takes a hash
4
- that provides defaults for each cassette you use. Any cassette
5
- can override the defaults as well as set additional options.
6
-
7
- The `:match_requests_on` option defaults to `[:method, :uri]` when
8
- it has not been set.
9
-
10
- The `:record` option defaults to `:once` when it has not been set.
11
-
12
- Background:
13
- Given a file named "vcr_setup.rb" with:
14
- """ruby
15
- require 'vcr'
16
-
17
- VCR.configure do |c|
18
- c.default_cassette_options = { :record => :new_episodes, :erb => true }
19
-
20
- # not important for this example, but must be set to something
21
- c.hook_into :webmock
22
- c.cassette_library_dir = 'cassettes'
23
- end
24
- """
25
-
26
- Scenario: cassettes get default values from configured `default_cassette_options`
27
- Given a file named "default_cassette_options.rb" with:
28
- """ruby
29
- require 'vcr_setup.rb'
30
-
31
- VCR.use_cassette('example') do
32
- puts "Record Mode: #{VCR.current_cassette.record_mode}"
33
- puts "ERB: #{VCR.current_cassette.erb}"
34
- end
35
- """
36
- When I run `ruby default_cassette_options.rb`
37
- Then the output should contain:
38
- """
39
- Record Mode: new_episodes
40
- ERB: true
41
- """
42
-
43
- Scenario: `:match_requests_on` defaults to `[:method, :uri]` when it has not been set
44
- Given a file named "default_cassette_options.rb" with:
45
- """ruby
46
- require 'vcr_setup.rb'
47
-
48
- VCR.use_cassette('example') do
49
- puts "Match Requests On: #{VCR.current_cassette.match_requests_on.inspect}"
50
- end
51
- """
52
- When I run `ruby default_cassette_options.rb`
53
- Then the output should contain "Match Requests On: [:method, :uri]"
54
-
55
- Scenario: `:record` defaults to `:once` when it has not been set
56
- Given a file named "default_record_mode.rb" with:
57
- """ruby
58
- require 'vcr'
59
-
60
- VCR.configure do |c|
61
- # not important for this example, but must be set to something
62
- c.hook_into :webmock
63
- c.cassette_library_dir = 'cassettes'
64
- end
65
-
66
- VCR.use_cassette('example') do
67
- puts "Record mode: #{VCR.current_cassette.record_mode.inspect}"
68
- end
69
- """
70
- When I run `ruby default_record_mode.rb`
71
- Then the output should contain "Record mode: :once"
72
-
73
- Scenario: cassettes can set their own options
74
- Given a file named "default_cassette_options.rb" with:
75
- """ruby
76
- require 'vcr_setup.rb'
77
-
78
- VCR.use_cassette('example', :re_record_interval => 10000) do
79
- puts "Re-record Interval: #{VCR.current_cassette.re_record_interval}"
80
- end
81
- """
82
- When I run `ruby default_cassette_options.rb`
83
- Then the output should contain "Re-record Interval: 10000"
84
-
85
- Scenario: cassettes can override default options
86
- Given a file named "default_cassette_options.rb" with:
87
- """ruby
88
- require 'vcr_setup.rb'
89
-
90
- VCR.use_cassette('example', :record => :none, :erb => false) do
91
- puts "Record Mode: #{VCR.current_cassette.record_mode}"
92
- puts "ERB: #{VCR.current_cassette.erb}"
93
- end
94
- """
95
- When I run `ruby default_cassette_options.rb`
96
- Then the output should contain:
97
- """
98
- Record Mode: none
99
- ERB: false
100
- """
@@ -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"