vcr 3.0.3 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,172 +0,0 @@
1
- Feature: hook_into
2
-
3
- The `hook_into` configuration option determines how VCR hooks into the
4
- HTTP requests to record and replay them. There are currently 4 valid
5
- options which support many different HTTP libraries:
6
-
7
- - :webmock can be used to hook into requests from:
8
- - Net::HTTP
9
- - HTTPClient
10
- - Patron
11
- - Curb (Curl::Easy, but not Curl::Multi)
12
- - EM HTTP Request
13
- - Typhoeus (Typhoeus::Hydra, but not Typhoeus::Easy or Typhoeus::Multi)
14
- - Excon
15
- - :typhoeus can be used to hook into itself (as long as you use Typhoeus::Hydra,
16
- but not Typhoeus::Easy or Typhoeus::Multi).
17
- - :excon can be used to hook into itself.
18
- - :faraday can be used to hook into itself.
19
- - :fakeweb (deprecated) can be used to hook into Net::HTTP requests.
20
-
21
- There are some addiitonal trade offs to consider when deciding which
22
- option to use:
23
-
24
- - WebMock uses extensive monkey patching to hook into supported HTTP
25
- libraries. No monkey patching is used for Typhoeus, Excon or Faraday.
26
- - Typhoeus, Excon, Faraday can be used together, and with either FakeWeb or WebMock.
27
- - FakeWeb and WebMock cannot both be used at the same time.
28
-
29
- Regardless of which library you use, VCR takes care of all of the configuration
30
- for you. You should not need to interact directly with FakeWeb, WebMock or the
31
- stubbing facilities of Typhoeus, Excon or Faraday. If/when you decide to change stubbing
32
- libraries (i.e. if you initially use FakeWeb because it's faster but later need the
33
- additional features of WebMock) you can change the `hook_into` configuration
34
- option and it'll work with no other changes required.
35
-
36
- Scenario Outline: Record and replay a request using each supported hook_into/http library combination
37
- Given a file named "hook_into_http_lib_combo.rb" with:
38
- """ruby
39
- include_http_adapter_for("<http_lib>")
40
-
41
- require 'vcr'
42
- VCR.configure { |c| c.ignore_localhost = true }
43
-
44
- $server = start_sinatra_app do
45
- get('/') { ARGV[0] }
46
- end
47
-
48
- puts "The response for request 1 was: #{response_body_for(:get, "http://localhost:#{$server.port}/")}"
49
-
50
- VCR.configure do |c|
51
- <configuration>
52
- c.cassette_library_dir = 'vcr_cassettes'
53
- c.ignore_localhost = false
54
- c.default_cassette_options = { :serialize_with => :syck }
55
- end
56
-
57
- VCR.use_cassette('example') do
58
- puts "The response for request 2 was: #{response_body_for(:get, "http://localhost:#{$server.port}/")}"
59
- end
60
- """
61
- When I run `ruby hook_into_http_lib_combo.rb 'Hello World'`
62
- Then the output should contain each of the following:
63
- | The response for request 1 was: Hello World |
64
- | The response for request 2 was: Hello World |
65
- And the file "vcr_cassettes/example.yml" should contain "Hello World"
66
-
67
- When I run `ruby hook_into_http_lib_combo.rb 'Goodbye World'`
68
- Then the output should contain each of the following:
69
- | The response for request 1 was: Goodbye World |
70
- | The response for request 2 was: Hello World |
71
- And the file "vcr_cassettes/example.yml" should contain "Hello World"
72
-
73
- Examples:
74
- | configuration | http_lib |
75
- | c.hook_into :fakeweb | net/http |
76
- | c.hook_into :webmock | net/http |
77
- | c.hook_into :webmock | httpclient |
78
- | c.hook_into :webmock | curb |
79
- | c.hook_into :webmock | patron |
80
- | c.hook_into :webmock | em-http-request |
81
- | c.hook_into :webmock | typhoeus |
82
- | c.hook_into :webmock | excon |
83
- | c.hook_into :typhoeus | typhoeus |
84
- | c.hook_into :excon | excon |
85
- | c.hook_into :faraday | faraday (w/ net_http) |
86
- | c.hook_into :faraday | faraday (w/ typhoeus) |
87
-
88
- @exclude-jruby @exclude-rbx
89
- Scenario Outline: Use Typhoeus, Excon and Faraday in combination with FakeWeb or WebMock
90
- Given a file named "hook_into_multiple.rb" with:
91
- """ruby
92
- require 'typhoeus'
93
- require 'excon'
94
- require 'faraday'
95
- require 'vcr'
96
- <extra_require>
97
-
98
- VCR.configure { |c| c.ignore_localhost = true }
99
-
100
- $server = start_sinatra_app do
101
- get('/:path') { "#{ARGV[0]} #{params[:path]}" }
102
- end
103
-
104
- def net_http_response
105
- Net::HTTP.get_response('localhost', '/net_http', $server.port).body
106
- end
107
-
108
- def typhoeus_response
109
- Typhoeus::Request.get("http://localhost:#{$server.port}/typhoeus").body
110
- end
111
-
112
- def excon_response
113
- Excon.get("http://localhost:#{$server.port}/excon").body
114
- end
115
-
116
- def faraday_response
117
- Faraday::Connection.new(:url => "http://localhost:#{$server.port}") do |builder|
118
- builder.adapter :<faraday_adapter>
119
- end.get('/faraday').body
120
- end
121
-
122
- puts "Net::HTTP 1: #{net_http_response}"
123
- puts "Typhoeus 1: #{typhoeus_response}"
124
- puts "Excon 1: #{excon_response}"
125
- puts "Faraday 1: #{faraday_response}"
126
-
127
- VCR.configure do |c|
128
- c.hook_into <hook_into>, :typhoeus, :excon, :faraday
129
- c.cassette_library_dir = 'vcr_cassettes'
130
- c.ignore_localhost = false
131
- end
132
-
133
- VCR.use_cassette('example') do
134
- puts "Net::HTTP 2: #{net_http_response}"
135
- puts "Typhoeus 2: #{typhoeus_response}"
136
- puts "Excon 2: #{excon_response}"
137
- puts "Faraday 2: #{faraday_response}"
138
- end
139
- """
140
- When I run `ruby hook_into_multiple.rb 'Hello'`
141
- Then the output should contain each of the following:
142
- | Net::HTTP 1: Hello net_http |
143
- | Typhoeus 1: Hello typhoeus |
144
- | Excon 1: Hello excon |
145
- | Faraday 1: Hello faraday |
146
- | Net::HTTP 2: Hello net_http |
147
- | Typhoeus 2: Hello typhoeus |
148
- | Excon 2: Hello excon |
149
- | Faraday 2: Hello faraday |
150
- And the cassette "vcr_cassettes/example.yml" should have the following response bodies:
151
- | Hello net_http |
152
- | Hello typhoeus |
153
- | Hello excon |
154
- | Hello faraday |
155
-
156
- When I run `ruby hook_into_multiple.rb 'Goodbye'`
157
- Then the output should contain each of the following:
158
- | Net::HTTP 1: Goodbye net_http |
159
- | Typhoeus 1: Goodbye typhoeus |
160
- | Excon 1: Goodbye excon |
161
- | Faraday 1: Goodbye faraday |
162
- | Net::HTTP 2: Hello net_http |
163
- | Typhoeus 2: Hello typhoeus |
164
- | Excon 2: Hello excon |
165
- | Faraday 2: Hello faraday |
166
-
167
- Examples:
168
- | hook_into | faraday_adapter | extra_require |
169
- | :fakeweb | net_http | |
170
- | :webmock | net_http | |
171
- | :fakeweb | typhoeus | require 'typhoeus/adapters/faraday' |
172
- | :webmock | typhoeus | require 'typhoeus/adapters/faraday' |
@@ -1,192 +0,0 @@
1
- Feature: Ignore Request
2
-
3
- By default, VCR hooks into every request, either allowing it and recording
4
- it, or playing back a recorded response, or raising an error to force you
5
- to deal with the new request. In some situations, you may prefer to have
6
- VCR ignore some requests.
7
-
8
- VCR provides 3 configuration options to accomplish this:
9
-
10
- * `ignore_request { |req| ... }` will ignore any request for which the
11
- given block returns true.
12
- * `ignore_hosts 'foo.com', 'bar.com'` allows you to specify particular
13
- hosts to ignore.
14
- * `ignore_localhost = true` is equivalent to `ignore_hosts 'localhost',
15
- '127.0.0.1', '0.0.0.0'`. It is particularly useful for when you use
16
- VCR with a javascript-enabled capybara driver, since capybara boots
17
- your rack app and makes localhost requests to it to check that it has
18
- booted.
19
-
20
- Ignored requests are not recorded and are always allowed, regardless of
21
- the record mode, and even outside of a `VCR.use_cassette` block.
22
-
23
- Background:
24
- Given a file named "sinatra_app.rb" with:
25
- """ruby
26
- response_count = 0
27
- $server = start_sinatra_app do
28
- get('/') { "Port 7777 Response #{response_count += 1}" }
29
- end
30
- """
31
-
32
- @exclude-jruby
33
- Scenario Outline: ignore requests to a specific port
34
- Given a file named "ignore_request.rb" with:
35
- """ruby
36
- include_http_adapter_for("<http_lib>")
37
- require 'sinatra_app.rb'
38
-
39
- response_count = 0
40
- $server_8888 = start_sinatra_app do
41
- get('/') { "Port 8888 Response #{response_count += 1}" }
42
- end
43
-
44
- require 'vcr'
45
-
46
- VCR.configure do |c|
47
- c.ignore_request do |request|
48
- URI(request.uri).port == $server.port
49
- end
50
-
51
- c.default_cassette_options = { :serialize_with => :syck }
52
- c.cassette_library_dir = 'cassettes'
53
- <configuration>
54
- end
55
-
56
- VCR.use_cassette('example') do
57
- puts response_body_for(:get, "http://localhost:#{$server_8888.port}/")
58
- end
59
-
60
- VCR.use_cassette('example') do
61
- puts response_body_for(:get, "http://localhost:#{$server.port}/")
62
- end
63
-
64
- puts response_body_for(:get, "http://localhost:#{$server.port}/")
65
- puts response_body_for(:get, "http://localhost:#{$server_8888.port}/")
66
- """
67
- When I run `ruby ignore_request.rb`
68
- Then it should fail with an error like:
69
- """
70
- An HTTP request has been made that VCR does not know how to handle:
71
- """
72
- And the output should contain:
73
- """
74
- Port 8888 Response 1
75
- Port 7777 Response 1
76
- Port 7777 Response 2
77
- """
78
- And the file "cassettes/example.yml" should contain "Port 8888"
79
- And the file "cassettes/example.yml" should not contain "Port 7777"
80
-
81
- Examples:
82
- | configuration | http_lib |
83
- | c.hook_into :fakeweb | net/http |
84
- | c.hook_into :webmock | net/http |
85
- | c.hook_into :typhoeus | typhoeus |
86
- | c.hook_into :faraday | faraday (w/ net_http) |
87
-
88
- Scenario Outline: ignored host requests are not recorded and are always allowed
89
- Given a file named "ignore_hosts.rb" with:
90
- """ruby
91
- include_http_adapter_for("<http_lib>")
92
- require 'sinatra_app.rb'
93
-
94
- require 'vcr'
95
-
96
- VCR.configure do |c|
97
- c.ignore_hosts '127.0.0.1', 'localhost'
98
- c.cassette_library_dir = 'cassettes'
99
- <configuration>
100
- end
101
-
102
- VCR.use_cassette('example') do
103
- puts response_body_for(:get, "http://localhost:#{$server.port}/")
104
- end
105
-
106
- puts response_body_for(:get, "http://localhost:#{$server.port}/")
107
- """
108
- When I run `ruby ignore_hosts.rb`
109
- Then it should pass with:
110
- """
111
- Port 7777 Response 1
112
- Port 7777 Response 2
113
- """
114
- And the file "cassettes/example.yml" should not exist
115
-
116
- Examples:
117
- | configuration | http_lib |
118
- | c.hook_into :fakeweb | net/http |
119
- | c.hook_into :webmock | net/http |
120
- | c.hook_into :typhoeus | typhoeus |
121
- | c.hook_into :excon | excon |
122
- | c.hook_into :faraday | faraday (w/ net_http) |
123
-
124
- @exclude-jruby
125
- Scenario Outline: localhost requests are not treated differently by default
126
- Given a file named "localhost_not_ignored.rb" with:
127
- """ruby
128
- include_http_adapter_for("<http_lib>")
129
- require 'sinatra_app.rb'
130
-
131
- require 'vcr'
132
-
133
- VCR.configure do |c|
134
- c.cassette_library_dir = 'cassettes'
135
- c.default_cassette_options = { :serialize_with => :syck }
136
- <configuration>
137
- end
138
-
139
- VCR.use_cassette('localhost') do
140
- response_body_for(:get, "http://localhost:#{$server.port}/")
141
- end
142
-
143
- response_body_for(:get, "http://localhost:#{$server.port}/")
144
- """
145
- When I run `ruby localhost_not_ignored.rb`
146
- Then it should fail with "An HTTP request has been made that VCR does not know how to handle"
147
- And the file "cassettes/localhost.yml" should contain "Port 7777 Response 1"
148
-
149
- Examples:
150
- | configuration | http_lib |
151
- | c.hook_into :fakeweb | net/http |
152
- | c.hook_into :webmock | net/http |
153
- | c.hook_into :typhoeus | typhoeus |
154
- | c.hook_into :excon | excon |
155
- | c.hook_into :faraday | faraday (w/ net_http) |
156
-
157
- Scenario Outline: localhost requests are allowed and not recorded when ignore_localhost = true
158
- Given a file named "ignore_localhost_true.rb" with:
159
- """ruby
160
- include_http_adapter_for("<http_lib>")
161
- require 'sinatra_app.rb'
162
-
163
- require 'vcr'
164
-
165
- VCR.configure do |c|
166
- c.ignore_localhost = true
167
- c.cassette_library_dir = 'cassettes'
168
- <configuration>
169
- end
170
-
171
- VCR.use_cassette('localhost') do
172
- puts response_body_for(:get, "http://localhost:#{$server.port}/")
173
- end
174
-
175
- puts response_body_for(:get, "http://localhost:#{$server.port}/")
176
- """
177
- When I run `ruby ignore_localhost_true.rb`
178
- Then it should pass with:
179
- """
180
- Port 7777 Response 1
181
- Port 7777 Response 2
182
- """
183
- And the file "cassettes/localhost.yml" should not exist
184
-
185
- Examples:
186
- | configuration | http_lib |
187
- | c.hook_into :fakeweb | net/http |
188
- | c.hook_into :webmock | net/http |
189
- | c.hook_into :typhoeus | typhoeus |
190
- | c.hook_into :excon | excon |
191
- | c.hook_into :faraday | faraday (w/ net_http) |
192
-
@@ -1,108 +0,0 @@
1
- @exclude-18
2
- Feature: Preserve Exact Body Bytes
3
-
4
- Some HTTP servers are not well-behaved and respond with invalid data: the response body may
5
- not be encoded according to the encoding specified in the HTTP headers, or there may be bytes
6
- that are invalid for the given encoding. The YAML and JSON serializers are not generally
7
- designed to handle these cases gracefully, and you may get errors when the cassette is serialized
8
- or deserialized. Also, the encoding may not be preserved when round-tripped through the
9
- serializer.
10
-
11
- VCR provides a configuration option to deal with cases like these. The `preserve_exact_body_bytes`
12
- method accepts a block that VCR will use to determine if the body of the given request or response object
13
- should be base64 encoded in order to preserve the bytes exactly as-is. VCR does not do this by
14
- default, since base64-encoding the string removes the human readibility of the cassette.
15
-
16
- Alternately, if you want to force an entire cassette to preserve the exact body bytes,
17
- you can pass the `:preserve_exact_body_bytes => true` cassette option when inserting your
18
- cassette.
19
-
20
- Scenario: Preserve exact bytes for response body with invalid encoding
21
- Given a file named "preserve.rb" with:
22
- """ruby
23
- # encoding: utf-8
24
- string = "abc \xFA"
25
- puts "Valid encoding: #{string.valid_encoding?}"
26
-
27
- $server = start_sinatra_app do
28
- get('/') { string }
29
- end
30
-
31
- require 'vcr'
32
-
33
- VCR.configure do |c|
34
- c.cassette_library_dir = 'cassettes'
35
- c.hook_into :webmock
36
- c.preserve_exact_body_bytes do |http_message|
37
- http_message.body.encoding.name == 'ASCII-8BIT' ||
38
- !http_message.body.valid_encoding?
39
- end
40
- end
41
-
42
- def make_request(label)
43
- puts
44
- puts label
45
- VCR.use_cassette('example', :serialize_with => :json) do
46
- body = Net::HTTP.get_response('localhost', '/', $server.port).body
47
- puts "Body: #{body.inspect}"
48
- end
49
- end
50
-
51
- make_request("Recording:")
52
- make_request("Playback:")
53
- """
54
- When I run `ruby preserve.rb`
55
- Then the output should contain exactly:
56
- """
57
- Valid encoding: false
58
-
59
- Recording:
60
- Body: "abc \xFA"
61
-
62
- Playback:
63
- Body: "abc \xFA"
64
-
65
- """
66
- And the file "cassettes/example.json" should contain:
67
- """
68
- "body":{"encoding":"ASCII-8BIT","base64_string":"YWJjIPo=\n"}
69
- """
70
-
71
- Scenario: Preserve exact bytes for cassette with `:preserve_exact_body_bytes` option
72
- Given a file named "preserve.rb" with:
73
- """ruby
74
- $server = start_sinatra_app do
75
- get('/') { "Hello World" }
76
- end
77
-
78
- require 'vcr'
79
-
80
- VCR.configure do |c|
81
- c.cassette_library_dir = 'cassettes'
82
- c.hook_into :webmock
83
- c.default_cassette_options = { :serialize_with => :json }
84
-
85
- c.before_record do |i|
86
- # otherwise Ruby 2.0 will default to UTF-8:
87
- i.response.body.force_encoding('US-ASCII')
88
- end
89
- end
90
-
91
- VCR.use_cassette('preserve_bytes', :preserve_exact_body_bytes => true) do
92
- Net::HTTP.get_response('localhost', '/', $server.port)
93
- end
94
-
95
- VCR.use_cassette('dont_preserve_bytes') do
96
- Net::HTTP.get_response('localhost', '/', $server.port)
97
- end
98
- """
99
- When I run `ruby preserve.rb`
100
- Then the file "cassettes/preserve_bytes.json" should contain:
101
- """
102
- "body":{"encoding":"US-ASCII","base64_string":"SGVsbG8gV29ybGQ=\n"}
103
- """
104
- And the file "cassettes/dont_preserve_bytes.json" should contain:
105
- """
106
- "body":{"encoding":"US-ASCII","string":"Hello World"}
107
- """
108
-
@@ -1,84 +0,0 @@
1
- Feature: query_parser
2
-
3
- By default, VCR will parse query strings using `CGI.parse` from the Ruby
4
- standard library. This may not be the most optimal or performant library
5
- available. You can set the `query_parser` configuration option to use a
6
- different parser (such as `Rack::Utils.method(:parse_query)`) to decode,
7
- normalize, and/or provide a comparison object for query strings.
8
-
9
- The configured query parser needs to expose a `.call` method that returns an
10
- object which is comparable. This instance needs to implement the following
11
- API:
12
-
13
- * `#==` => boolean
14
-
15
- Background:
16
- Given a file named "cassettes/example.yml" with:
17
- """
18
- ---
19
- http_interactions:
20
- - request:
21
- method: get
22
- uri: http://url.example.com/?bravo=2&alpha=1
23
- body:
24
- encoding: UTF-8
25
- string: ""
26
- headers: {}
27
- response:
28
- status:
29
- code: 200
30
- message: OK
31
- headers:
32
- Content-Length:
33
- - "5"
34
- body:
35
- encoding: UTF-8
36
- string: Hello
37
- http_version: "1.1"
38
- recorded_at: Tue, 25 Sep 2012 04:58:44 GMT
39
- recorded_with: VCR 2.2.5
40
- """
41
-
42
- Scenario: the VCR query parser gets its value from `query_parser`
43
- Given a file named "query_parser.rb" with:
44
- """ruby
45
- require 'vcr'
46
- require 'rack'
47
-
48
- VCR.configure do |c|
49
- c.query_parser = lambda { |query| raise query.inspect }
50
- c.default_cassette_options = {:match_requests_on => [:query]}
51
- c.hook_into :webmock
52
- c.cassette_library_dir = 'cassettes'
53
- end
54
-
55
- uri = URI.parse('http://other-url.example.com/?bravo=2&alpha=1')
56
- VCR.use_cassette('example') do
57
- puts Net::HTTP.get_response(uri).body
58
- end
59
- """
60
- When I run `ruby query_parser.rb`
61
- Then it should fail with an error like:
62
- """
63
- "alpha=1&bravo=2"
64
- """
65
-
66
-
67
- Scenario: the `query_parser` defaults to the standard library's `CGI.parse`
68
- Given a file named "query_parser_default.rb" with:
69
- """ruby
70
- require 'vcr'
71
-
72
- VCR.configure do |c|
73
- c.hook_into :webmock
74
- c.default_cassette_options = {:match_requests_on => [:query]}
75
- c.cassette_library_dir = 'cassettes'
76
- end
77
-
78
- uri = URI.parse('http://other-url.example.com/?bravo=2&alpha=1')
79
- VCR.use_cassette('example') do
80
- puts Net::HTTP.get_response(uri).body
81
- end
82
- """
83
- When I run `ruby query_parser_default.rb`
84
- Then it should pass with "Hello"
@@ -1,93 +0,0 @@
1
- Feature: uri_parser
2
-
3
- By default, VCR will parse URIs using `URI` from the Ruby standard
4
- library. There are some URIs seen out in the wild that `URI` cannot
5
- parse properly. You can set the `uri_parser` configuration option
6
- to use a different parser (such as `Addressable::URI`) to work with
7
- these URIs.
8
-
9
- The configured URI parser needs to expose a `.parse` class method
10
- that returns an instance of the uri. This uri instance needs to
11
- implement the following API:
12
-
13
- * `#scheme` => a string
14
- * `#host` => a string
15
- * `#port` => a fixnum
16
- * `#path` => a string
17
- * `#query` => a string
18
- * `#to_s` => a string
19
- * `#port=`
20
- * `#query=`
21
- * `#==` => boolean
22
-
23
- Background:
24
- Given a file named "cassettes/example.yml" with:
25
- """
26
- ---
27
- http_interactions:
28
- - request:
29
- method: get
30
- uri: http://example.com/hello
31
- body:
32
- encoding: UTF-8
33
- string: ""
34
- headers: {}
35
- response:
36
- status:
37
- code: 200
38
- message: OK
39
- headers:
40
- Content-Length:
41
- - "5"
42
- body:
43
- encoding: UTF-8
44
- string: Hello
45
- http_version: "1.1"
46
- recorded_at: Tue, 25 Sep 2012 04:58:44 GMT
47
- recorded_with: VCR 2.2.5
48
- """
49
-
50
- Scenario: the VCR uri parser gets its value from `uri_parser`
51
- Given a file named "uri_parser.rb" with:
52
- """ruby
53
- require 'vcr'
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
64
-
65
- VCR.configure do |c|
66
- c.uri_parser = MyURI
67
- c.hook_into :webmock
68
- c.cassette_library_dir = 'cassettes'
69
- end
70
-
71
- VCR.use_cassette('example') do
72
- puts Net::HTTP.get_response('evil.org', '/projects').body
73
- end
74
- """
75
- When I run `ruby uri_parser.rb`
76
- Then it should pass with "Hello"
77
-
78
- Scenario: the `uri_parser` defaults to the standard library's `URI`
79
- Given a file named "uri_parser_default.rb" with:
80
- """ruby
81
- require 'vcr'
82
-
83
- VCR.configure do |c|
84
- c.hook_into :webmock
85
- c.cassette_library_dir = 'cassettes'
86
- end
87
-
88
- VCR.use_cassette('example') do
89
- puts Net::HTTP.get_response('example.com', '/hello').body
90
- end
91
- """
92
- When I run `ruby uri_parser_default.rb`
93
- Then it should pass with "Hello"