mustwin-vcr 2.9.3

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 (148) hide show
  1. checksums.yaml +7 -0
  2. data/features/about_these_examples.md +18 -0
  3. data/features/cassettes/allow_unused_http_interactions.feature +100 -0
  4. data/features/cassettes/automatic_re_recording.feature +72 -0
  5. data/features/cassettes/decompress.feature +74 -0
  6. data/features/cassettes/dynamic_erb.feature +100 -0
  7. data/features/cassettes/exclusive.feature +126 -0
  8. data/features/cassettes/format.feature +323 -0
  9. data/features/cassettes/freezing_time.feature +68 -0
  10. data/features/cassettes/naming.feature +28 -0
  11. data/features/cassettes/no_cassette.feature +152 -0
  12. data/features/cassettes/update_content_length_header.feature +112 -0
  13. data/features/configuration/allow_http_connections_when_no_cassette.feature +55 -0
  14. data/features/configuration/cassette_library_dir.feature +31 -0
  15. data/features/configuration/debug_logging.feature +59 -0
  16. data/features/configuration/default_cassette_options.feature +100 -0
  17. data/features/configuration/filter_sensitive_data.feature +153 -0
  18. data/features/configuration/hook_into.feature +172 -0
  19. data/features/configuration/ignore_request.feature +192 -0
  20. data/features/configuration/preserve_exact_body_bytes.feature +108 -0
  21. data/features/configuration/query_parser.feature +84 -0
  22. data/features/configuration/uri_parser.feature +89 -0
  23. data/features/getting_started.md +82 -0
  24. data/features/hooks/after_http_request.feature +58 -0
  25. data/features/hooks/around_http_request.feature +57 -0
  26. data/features/hooks/before_http_request.feature +63 -0
  27. data/features/hooks/before_playback.feature +184 -0
  28. data/features/hooks/before_record.feature +172 -0
  29. data/features/http_libraries/em_http_request.feature +250 -0
  30. data/features/http_libraries/net_http.feature +179 -0
  31. data/features/middleware/faraday.feature +56 -0
  32. data/features/middleware/rack.feature +92 -0
  33. data/features/record_modes/all.feature +82 -0
  34. data/features/record_modes/new_episodes.feature +79 -0
  35. data/features/record_modes/none.feature +72 -0
  36. data/features/record_modes/once.feature +95 -0
  37. data/features/request_matching/README.md +30 -0
  38. data/features/request_matching/body.feature +91 -0
  39. data/features/request_matching/body_as_json.feature +90 -0
  40. data/features/request_matching/custom_matcher.feature +135 -0
  41. data/features/request_matching/headers.feature +85 -0
  42. data/features/request_matching/host.feature +95 -0
  43. data/features/request_matching/identical_request_sequence.feature +89 -0
  44. data/features/request_matching/method.feature +96 -0
  45. data/features/request_matching/path.feature +96 -0
  46. data/features/request_matching/playback_repeats.feature +98 -0
  47. data/features/request_matching/query.feature +97 -0
  48. data/features/request_matching/uri.feature +94 -0
  49. data/features/request_matching/uri_without_param.feature +101 -0
  50. data/features/step_definitions/cli_steps.rb +193 -0
  51. data/features/support/env.rb +44 -0
  52. data/features/support/http_lib_filters.rb +53 -0
  53. data/features/test_frameworks/cucumber.feature +211 -0
  54. data/features/test_frameworks/rspec_macro.feature +81 -0
  55. data/features/test_frameworks/rspec_metadata.feature +150 -0
  56. data/features/test_frameworks/test_unit.feature +49 -0
  57. data/lib/vcr.rb +347 -0
  58. data/lib/vcr/cassette.rb +291 -0
  59. data/lib/vcr/cassette/erb_renderer.rb +55 -0
  60. data/lib/vcr/cassette/http_interaction_list.rb +108 -0
  61. data/lib/vcr/cassette/migrator.rb +118 -0
  62. data/lib/vcr/cassette/persisters.rb +42 -0
  63. data/lib/vcr/cassette/persisters/file_system.rb +64 -0
  64. data/lib/vcr/cassette/serializers.rb +57 -0
  65. data/lib/vcr/cassette/serializers/json.rb +48 -0
  66. data/lib/vcr/cassette/serializers/psych.rb +48 -0
  67. data/lib/vcr/cassette/serializers/syck.rb +61 -0
  68. data/lib/vcr/cassette/serializers/yaml.rb +50 -0
  69. data/lib/vcr/configuration.rb +555 -0
  70. data/lib/vcr/deprecations.rb +109 -0
  71. data/lib/vcr/errors.rb +266 -0
  72. data/lib/vcr/extensions/net_http_response.rb +36 -0
  73. data/lib/vcr/library_hooks.rb +18 -0
  74. data/lib/vcr/library_hooks/excon.rb +27 -0
  75. data/lib/vcr/library_hooks/fakeweb.rb +196 -0
  76. data/lib/vcr/library_hooks/faraday.rb +51 -0
  77. data/lib/vcr/library_hooks/typhoeus.rb +120 -0
  78. data/lib/vcr/library_hooks/typhoeus_0.4.rb +103 -0
  79. data/lib/vcr/library_hooks/webmock.rb +164 -0
  80. data/lib/vcr/middleware/excon.rb +221 -0
  81. data/lib/vcr/middleware/excon/legacy_methods.rb +33 -0
  82. data/lib/vcr/middleware/faraday.rb +118 -0
  83. data/lib/vcr/middleware/rack.rb +79 -0
  84. data/lib/vcr/request_handler.rb +114 -0
  85. data/lib/vcr/request_ignorer.rb +43 -0
  86. data/lib/vcr/request_matcher_registry.rb +149 -0
  87. data/lib/vcr/structs.rb +578 -0
  88. data/lib/vcr/tasks/vcr.rake +9 -0
  89. data/lib/vcr/test_frameworks/cucumber.rb +64 -0
  90. data/lib/vcr/test_frameworks/rspec.rb +47 -0
  91. data/lib/vcr/util/hooks.rb +61 -0
  92. data/lib/vcr/util/internet_connection.rb +43 -0
  93. data/lib/vcr/util/logger.rb +59 -0
  94. data/lib/vcr/util/variable_args_block_caller.rb +13 -0
  95. data/lib/vcr/util/version_checker.rb +48 -0
  96. data/lib/vcr/version.rb +34 -0
  97. data/spec/acceptance/threading_spec.rb +34 -0
  98. data/spec/fixtures/cassette_spec/1_x_cassette.yml +110 -0
  99. data/spec/fixtures/cassette_spec/empty.yml +0 -0
  100. data/spec/fixtures/cassette_spec/example.yml +111 -0
  101. data/spec/fixtures/cassette_spec/with_localhost_requests.yml +111 -0
  102. data/spec/fixtures/fake_example_responses.yml +110 -0
  103. data/spec/fixtures/match_requests_on.yml +187 -0
  104. data/spec/lib/vcr/cassette/erb_renderer_spec.rb +53 -0
  105. data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +295 -0
  106. data/spec/lib/vcr/cassette/migrator_spec.rb +195 -0
  107. data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +69 -0
  108. data/spec/lib/vcr/cassette/persisters_spec.rb +39 -0
  109. data/spec/lib/vcr/cassette/serializers_spec.rb +176 -0
  110. data/spec/lib/vcr/cassette_spec.rb +618 -0
  111. data/spec/lib/vcr/configuration_spec.rb +326 -0
  112. data/spec/lib/vcr/deprecations_spec.rb +85 -0
  113. data/spec/lib/vcr/errors_spec.rb +162 -0
  114. data/spec/lib/vcr/extensions/net_http_response_spec.rb +86 -0
  115. data/spec/lib/vcr/library_hooks/excon_spec.rb +104 -0
  116. data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +169 -0
  117. data/spec/lib/vcr/library_hooks/faraday_spec.rb +68 -0
  118. data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +36 -0
  119. data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +162 -0
  120. data/spec/lib/vcr/library_hooks/webmock_spec.rb +118 -0
  121. data/spec/lib/vcr/library_hooks_spec.rb +51 -0
  122. data/spec/lib/vcr/middleware/faraday_spec.rb +182 -0
  123. data/spec/lib/vcr/middleware/rack_spec.rb +115 -0
  124. data/spec/lib/vcr/request_ignorer_spec.rb +70 -0
  125. data/spec/lib/vcr/request_matcher_registry_spec.rb +345 -0
  126. data/spec/lib/vcr/structs_spec.rb +732 -0
  127. data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +107 -0
  128. data/spec/lib/vcr/test_frameworks/rspec_spec.rb +83 -0
  129. data/spec/lib/vcr/util/hooks_spec.rb +158 -0
  130. data/spec/lib/vcr/util/internet_connection_spec.rb +37 -0
  131. data/spec/lib/vcr/util/version_checker_spec.rb +31 -0
  132. data/spec/lib/vcr/version_spec.rb +27 -0
  133. data/spec/lib/vcr_spec.rb +349 -0
  134. data/spec/monkey_patches.rb +182 -0
  135. data/spec/spec_helper.rb +62 -0
  136. data/spec/support/configuration_stubbing.rb +8 -0
  137. data/spec/support/cucumber_helpers.rb +35 -0
  138. data/spec/support/fixnum_extension.rb +10 -0
  139. data/spec/support/http_library_adapters.rb +289 -0
  140. data/spec/support/limited_uri.rb +21 -0
  141. data/spec/support/ruby_interpreter.rb +7 -0
  142. data/spec/support/shared_example_groups/excon.rb +63 -0
  143. data/spec/support/shared_example_groups/hook_into_http_library.rb +594 -0
  144. data/spec/support/shared_example_groups/request_hooks.rb +59 -0
  145. data/spec/support/sinatra_app.rb +86 -0
  146. data/spec/support/vcr_localhost_server.rb +76 -0
  147. data/spec/support/vcr_stub_helpers.rb +17 -0
  148. metadata +677 -0
@@ -0,0 +1,172 @@
1
+ Feature: before_record hook
2
+
3
+ The `before_record` hook is called before a cassette is written to disk.
4
+ This can be used to modify the HTTP interaction before it is recorded.
5
+
6
+ Your block should accept up to 2 arguments. The first argument will be
7
+ the HTTP interaction that is about to be written to disk. The second
8
+ argument will be the current cassette.
9
+
10
+ If you wish to prevent VCR from recording the HTTP interaction you can call
11
+ `#ignore!` on the interaction.
12
+
13
+ If you don't want your hook to apply to all cassettes, you can use tags to
14
+ select which cassettes a given hook applies to. Consider this code:
15
+
16
+ VCR.configure do |c|
17
+ c.before_record(:twitter) { ... } # modify the interactions somehow
18
+ end
19
+
20
+ VCR.use_cassette('cassette_1', :tag => :twitter) { ... }
21
+ VCR.use_cassette('cassette_2') { ... }
22
+
23
+ In this example, the hook would apply to the first cassette but not the
24
+ second cassette.
25
+
26
+ Scenario: Modify recorded response
27
+ Given a file named "before_record_example.rb" with:
28
+ """ruby
29
+ $server = start_sinatra_app do
30
+ get('/') { "Hello Earth" }
31
+ end
32
+
33
+ require 'vcr'
34
+
35
+ VCR.configure do |c|
36
+ c.hook_into :webmock
37
+ c.cassette_library_dir = 'cassettes'
38
+
39
+ c.before_record do |i|
40
+ i.response.body.sub!('Earth', 'World')
41
+ end
42
+ end
43
+
44
+ VCR.use_cassette('recording_example') do
45
+ Net::HTTP.get_response('localhost', '/', $server.port)
46
+ end
47
+ """
48
+ When I run `ruby before_record_example.rb`
49
+ Then the file "cassettes/recording_example.yml" should contain "Hello World"
50
+ And the file "cassettes/recording_example.yml" should not contain "Earth"
51
+
52
+ Scenario: Modify recorded response based on the cassette
53
+ Given a file named "before_record_example.rb" with:
54
+ """ruby
55
+ $server = start_sinatra_app do
56
+ get('/') { "Hello Earth" }
57
+ end
58
+
59
+ require 'vcr'
60
+
61
+ VCR.configure do |c|
62
+ c.hook_into :webmock
63
+ c.cassette_library_dir = 'cassettes'
64
+
65
+ c.before_record do |interaction, cassette|
66
+ interaction.response.body << " (#{cassette.name})"
67
+ end
68
+ end
69
+
70
+ VCR.use_cassette('recording_example') do
71
+ Net::HTTP.get_response('localhost', '/', $server.port)
72
+ end
73
+ """
74
+ When I run `ruby before_record_example.rb`
75
+ Then the file "cassettes/recording_example.yml" should contain "Hello Earth (recording_example)"
76
+
77
+ Scenario: Prevent recording by ignoring interaction in before_record hook
78
+ Given a file named "before_record_ignore.rb" with:
79
+ """ruby
80
+ $server = start_sinatra_app do
81
+ get('/') { "Hello World" }
82
+ end
83
+
84
+ require 'vcr'
85
+
86
+ VCR.configure do |c|
87
+ c.hook_into :webmock
88
+ c.cassette_library_dir = 'cassettes'
89
+ c.before_record { |i| i.ignore! }
90
+ end
91
+
92
+ VCR.use_cassette('recording_example') do
93
+ response = Net::HTTP.get_response('localhost', '/', $server.port)
94
+ puts "Response: #{response.body}"
95
+ end
96
+ """
97
+ When I run `ruby before_record_ignore.rb`
98
+ Then it should pass with "Response: Hello World"
99
+ And the file "cassettes/recording_example.yml" should not exist
100
+
101
+ Scenario: Multiple hooks are run in order
102
+ Given a file named "multiple_hooks.rb" with:
103
+ """ruby
104
+ $server = start_sinatra_app do
105
+ get('/') { "Hello World" }
106
+ end
107
+
108
+ require 'vcr'
109
+
110
+ VCR.configure do |c|
111
+ c.hook_into :webmock
112
+ c.cassette_library_dir = 'cassettes'
113
+
114
+ c.before_record { puts "In before_record hook 1" }
115
+ c.before_record { puts "In before_record hook 2" }
116
+ end
117
+
118
+ VCR.use_cassette('example', :record => :new_episodes) do
119
+ response = Net::HTTP.get_response('localhost', '/', $server.port)
120
+ puts "Response: #{response.body}"
121
+ end
122
+ """
123
+ When I run `ruby multiple_hooks.rb`
124
+ Then it should pass with:
125
+ """
126
+ Response: Hello World
127
+ In before_record hook 1
128
+ In before_record hook 2
129
+ """
130
+
131
+ Scenario: Use tagging to apply hook to only certain cassettes
132
+ Given a file named "tagged_hooks.rb" with:
133
+ """ruby
134
+ $server = start_sinatra_app do
135
+ get('/') { "Hello World" }
136
+ end
137
+
138
+ require 'vcr'
139
+
140
+ VCR.configure do |c|
141
+ c.hook_into :webmock
142
+ c.cassette_library_dir = 'cassettes'
143
+
144
+ c.before_record(:tag_1) do
145
+ puts "In before_record hook for tag_1"
146
+ end
147
+ end
148
+
149
+ [:tag_1, :tag_2, nil].each do |tag|
150
+ puts
151
+ puts "Using tag: #{tag.inspect}"
152
+
153
+ VCR.use_cassette('example', :record => :new_episodes, :tag => tag) do
154
+ response = Net::HTTP.get_response('localhost', '/', $server.port)
155
+ puts "Response: #{response.body}"
156
+ end
157
+ end
158
+ """
159
+ When I run `ruby tagged_hooks.rb`
160
+ Then it should pass with:
161
+ """
162
+ Using tag: :tag_1
163
+ Response: Hello World
164
+ In before_record hook for tag_1
165
+
166
+ Using tag: :tag_2
167
+ Response: Hello World
168
+
169
+ Using tag: nil
170
+ Response: Hello World
171
+ """
172
+
@@ -0,0 +1,250 @@
1
+ @exclude-jruby @exclude-rbx
2
+ Feature: EM HTTP Request
3
+
4
+ EM HTTP Request allows multiple simultaneous asynchronous requests.
5
+ (The other HTTP libraries are synchronous). The scenarios below
6
+ demonstrate how VCR can be used with asynchronous em-http requests.
7
+
8
+ Background:
9
+ Given a file named "vcr_setup.rb" with:
10
+ """ruby
11
+ require 'em-http-request'
12
+
13
+ $server = start_sinatra_app do
14
+ %w[ foo bar bazz ].each_with_index do |path, index|
15
+ get "/#{path}" do
16
+ sleep index * 0.1 # ensure the async callbacks are invoked in order
17
+ ARGV[0] + ' ' + path
18
+ end
19
+ end
20
+ end
21
+
22
+ require 'vcr'
23
+
24
+ VCR.configure do |c|
25
+ c.hook_into :webmock
26
+ c.cassette_library_dir = 'cassettes'
27
+ c.before_record do |i|
28
+ i.request.uri.sub!(/:\d+/, ':7777')
29
+ end
30
+ end
31
+ """
32
+
33
+ Scenario: multiple simultaneous HttpRequest objects
34
+ Given a file named "make_requests.rb" with:
35
+ """ruby
36
+ require 'vcr_setup'
37
+
38
+ VCR.use_cassette('em_http') do
39
+ EventMachine.run do
40
+ http_array = %w[ foo bar bazz ].map do |p|
41
+ EventMachine::HttpRequest.new("http://localhost:#{$server.port}/#{p}").get
42
+ end
43
+
44
+ http_array.each do |http|
45
+ http.callback do
46
+ puts http.response
47
+
48
+ if http_array.all? { |h| h.response.to_s != '' }
49
+ EventMachine.stop
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ """
56
+ When I run `ruby make_requests.rb Hello`
57
+ Then the output should contain:
58
+ """
59
+ Hello foo
60
+ Hello bar
61
+ Hello bazz
62
+ """
63
+ And the file "cassettes/em_http.yml" should contain YAML like:
64
+ """
65
+ ---
66
+ http_interactions:
67
+ - request:
68
+ method: get
69
+ uri: http://localhost:7777/foo
70
+ body:
71
+ encoding: UTF-8
72
+ string: ""
73
+ headers: {}
74
+ response:
75
+ status:
76
+ code: 200
77
+ message: OK
78
+ headers:
79
+ Content-Type:
80
+ - text/html;charset=utf-8
81
+ Content-Length:
82
+ - "9"
83
+ body:
84
+ encoding: UTF-8
85
+ string: Hello foo
86
+ http_version:
87
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
88
+ - request:
89
+ method: get
90
+ uri: http://localhost:7777/bar
91
+ body:
92
+ encoding: UTF-8
93
+ string: ""
94
+ headers: {}
95
+ response:
96
+ status:
97
+ code: 200
98
+ message: OK
99
+ headers:
100
+ Content-Type:
101
+ - text/html;charset=utf-8
102
+ Content-Length:
103
+ - "9"
104
+ body:
105
+ encoding: UTF-8
106
+ string: Hello bar
107
+ http_version:
108
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
109
+ - request:
110
+ method: get
111
+ uri: http://localhost:7777/bazz
112
+ body:
113
+ encoding: UTF-8
114
+ string: ""
115
+ headers: {}
116
+ response:
117
+ status:
118
+ code: 200
119
+ message: OK
120
+ headers:
121
+ Content-Type:
122
+ - text/html;charset=utf-8
123
+ Content-Length:
124
+ - "10"
125
+ body:
126
+ encoding: UTF-8
127
+ string: Hello bazz
128
+ http_version:
129
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
130
+ recorded_with: VCR 2.0.0
131
+ """
132
+
133
+ When I run `ruby make_requests.rb Goodbye`
134
+ Then the output should contain:
135
+ """
136
+ Hello foo
137
+ Hello bar
138
+ Hello bazz
139
+ """
140
+
141
+ Scenario: MultiRequest
142
+ Given a file named "make_requests.rb" with:
143
+ """ruby
144
+ require 'vcr_setup'
145
+
146
+ VCR.use_cassette('em_http') do
147
+ EventMachine.run do
148
+ multi = EventMachine::MultiRequest.new
149
+
150
+ %w[ foo bar bazz ].each do |path|
151
+ multi.add(path, EventMachine::HttpRequest.new("http://localhost:#{$server.port}/#{path}").get)
152
+ end
153
+
154
+ multi.callback do
155
+ responses = Hash[multi.responses[:callback]]
156
+
157
+ %w[ foo bar bazz ].each do |path|
158
+ puts responses[path].response
159
+ end
160
+
161
+ EventMachine.stop
162
+ end
163
+ end
164
+ end
165
+ """
166
+ When I run `ruby make_requests.rb Hello`
167
+ Then the output should contain:
168
+ """
169
+ Hello foo
170
+ Hello bar
171
+ Hello bazz
172
+ """
173
+ And the file "cassettes/em_http.yml" should contain YAML like:
174
+ """
175
+ ---
176
+ http_interactions:
177
+ - request:
178
+ method: get
179
+ uri: http://localhost:7777/foo
180
+ body:
181
+ encoding: UTF-8
182
+ string: ""
183
+ headers: {}
184
+ response:
185
+ status:
186
+ code: 200
187
+ message: OK
188
+ headers:
189
+ Content-Type:
190
+ - text/html;charset=utf-8
191
+ Content-Length:
192
+ - "9"
193
+ body:
194
+ encoding: UTF-8
195
+ string: Hello foo
196
+ http_version:
197
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
198
+ - request:
199
+ method: get
200
+ uri: http://localhost:7777/bar
201
+ body:
202
+ encoding: UTF-8
203
+ string: ""
204
+ headers: {}
205
+ response:
206
+ status:
207
+ code: 200
208
+ message: OK
209
+ headers:
210
+ Content-Type:
211
+ - text/html;charset=utf-8
212
+ Content-Length:
213
+ - "9"
214
+ body:
215
+ encoding: UTF-8
216
+ string: Hello bar
217
+ http_version:
218
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
219
+ - request:
220
+ method: get
221
+ uri: http://localhost:7777/bazz
222
+ body:
223
+ encoding: UTF-8
224
+ string: ""
225
+ headers: {}
226
+ response:
227
+ status:
228
+ code: 200
229
+ message: OK
230
+ headers:
231
+ Content-Type:
232
+ - text/html;charset=utf-8
233
+ Content-Length:
234
+ - "10"
235
+ body:
236
+ encoding: UTF-8
237
+ string: Hello bazz
238
+ http_version:
239
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
240
+ recorded_with: VCR 2.0.0
241
+ """
242
+
243
+ When I run `ruby make_requests.rb Goodbye`
244
+ Then the output should contain:
245
+ """
246
+ Hello foo
247
+ Hello bar
248
+ Hello bazz
249
+ """
250
+
@@ -0,0 +1,179 @@
1
+ Feature: Net::HTTP
2
+
3
+ There are many ways to use Net::HTTP. The scenarios below provide regression
4
+ tests for some Net::HTTP APIs that have not worked properly with VCR and
5
+ FakeWeb or WebMock in the past (but have since been fixed).
6
+
7
+ Background:
8
+ Given a file named "vcr_setup.rb" with:
9
+ """ruby
10
+ require 'ostruct'
11
+
12
+ if ARGV[0] == '--with-server'
13
+ $server = start_sinatra_app do
14
+ get('/') { 'VCR works with Net::HTTP gets!' }
15
+ post('/') { 'VCR works with Net::HTTP posts!' }
16
+ end
17
+ else
18
+ $server = OpenStruct(:port => 0)
19
+ end
20
+
21
+ require 'vcr'
22
+
23
+ VCR.configure do |c|
24
+ c.default_cassette_options = {
25
+ :match_requests_on => [:method, :host, :path]
26
+ }
27
+ end
28
+ """
29
+
30
+ Scenario Outline: Calling #post on new Net::HTTP instance
31
+ Given a file named "vcr_net_http.rb" with:
32
+ """ruby
33
+ require 'vcr_setup.rb'
34
+
35
+ VCR.configure do |c|
36
+ c.hook_into <hook_into>
37
+ c.cassette_library_dir = 'cassettes'
38
+ end
39
+
40
+ VCR.use_cassette('net_http') do
41
+ puts Net::HTTP.new('localhost', $server.port).post('/', '').body
42
+ end
43
+ """
44
+ When I run `ruby vcr_net_http.rb --with-server`
45
+ Then the output should contain "VCR works with Net::HTTP posts!"
46
+ And the file "cassettes/net_http.yml" should contain "VCR works with Net::HTTP posts!"
47
+
48
+ When I run `ruby vcr_net_http.rb`
49
+ Then the output should contain "VCR works with Net::HTTP posts!"
50
+
51
+ Examples:
52
+ | hook_into |
53
+ | :fakeweb |
54
+ | :webmock |
55
+
56
+ Scenario Outline: Return from yielded block
57
+ Given a file named "vcr_net_http.rb" with:
58
+ """ruby
59
+ require 'vcr_setup.rb'
60
+
61
+ VCR.configure do |c|
62
+ c.hook_into <hook_into>
63
+ c.cassette_library_dir = 'cassettes'
64
+ end
65
+
66
+ def perform_request
67
+ Net::HTTP.new('localhost', $server.port).request(Net::HTTP::Get.new('/', {})) do |response|
68
+ return response
69
+ end
70
+ end
71
+
72
+ VCR.use_cassette('net_http') do
73
+ puts perform_request.body
74
+ end
75
+ """
76
+ When I run `ruby vcr_net_http.rb --with-server`
77
+ Then the output should contain "VCR works with Net::HTTP gets!"
78
+ And the file "cassettes/net_http.yml" should contain "VCR works with Net::HTTP gets!"
79
+
80
+ When I run `ruby vcr_net_http.rb`
81
+ Then the output should contain "VCR works with Net::HTTP gets!"
82
+
83
+ Examples:
84
+ | hook_into |
85
+ | :fakeweb |
86
+ | :webmock |
87
+
88
+ Scenario Outline: Use Net::ReadAdapter to read body in fragments
89
+ Given a file named "vcr_net_http.rb" with:
90
+ """ruby
91
+ require 'vcr_setup.rb'
92
+
93
+ VCR.configure do |c|
94
+ c.hook_into <hook_into>
95
+ c.cassette_library_dir = 'cassettes'
96
+ end
97
+
98
+ VCR.use_cassette('net_http') do
99
+ body = ''
100
+
101
+ Net::HTTP.new('localhost', $server.port).request_get('/') do |response|
102
+ response.read_body { |frag| body << frag }
103
+ end
104
+
105
+ puts body
106
+ end
107
+ """
108
+ When I run `ruby vcr_net_http.rb --with-server`
109
+ Then the output should contain "VCR works with Net::HTTP gets!"
110
+ And the file "cassettes/net_http.yml" should contain "VCR works with Net::HTTP gets!"
111
+
112
+ When I run `ruby vcr_net_http.rb`
113
+ Then the output should contain "VCR works with Net::HTTP gets!"
114
+
115
+ Examples:
116
+ | hook_into |
117
+ | :fakeweb |
118
+ | :webmock |
119
+
120
+ Scenario Outline: Use open-uri (which is built on top of Net::HTTP and uses a seldom-used Net::HTTP API)
121
+ Given a file named "vcr_net_http.rb" with:
122
+ """ruby
123
+ require 'open-uri'
124
+ require 'vcr_setup.rb'
125
+
126
+ VCR.configure do |c|
127
+ c.hook_into <hook_into>
128
+ c.cassette_library_dir = 'cassettes'
129
+ end
130
+
131
+ VCR.use_cassette('net_http') do
132
+ puts open("http://localhost:#{$server.port}/").read
133
+ end
134
+ """
135
+ When I run `ruby vcr_net_http.rb --with-server`
136
+ Then the output should contain "VCR works with Net::HTTP gets!"
137
+ And the file "cassettes/net_http.yml" should contain "VCR works with Net::HTTP gets!"
138
+
139
+ When I run `ruby vcr_net_http.rb`
140
+ Then the output should contain "VCR works with Net::HTTP gets!"
141
+
142
+ Examples:
143
+ | hook_into |
144
+ | :fakeweb |
145
+ | :webmock |
146
+
147
+ Scenario Outline: Make an HTTPS request
148
+ Given a file named "vcr_https.rb" with:
149
+ """ruby
150
+ require 'vcr'
151
+
152
+ VCR.configure do |c|
153
+ c.hook_into <hook_into>
154
+ c.cassette_library_dir = 'cassettes'
155
+ end
156
+
157
+ uri = URI("https://gist.githubusercontent.com/myronmarston/fb555cb593f3349d53af/raw/6921dd638337d3f6a51b0e02e7f30e3c414f70d6/vcr_gist")
158
+
159
+ VCR.use_cassette('https') do
160
+ http = Net::HTTP.new(uri.host, uri.port)
161
+ http.use_ssl = true
162
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
163
+ response = http.request_get(uri.path)
164
+
165
+ puts response.body
166
+ end
167
+ """
168
+ When I run `ruby vcr_https.rb`
169
+ Then the output should contain "VCR gist"
170
+ And the file "cassettes/https.yml" should contain "VCR gist"
171
+
172
+ When I modify the file "cassettes/https.yml" to replace "VCR gist" with "HTTPS replaying works"
173
+ And I run `ruby vcr_https.rb`
174
+ Then the output should contain "HTTPS replaying works"
175
+
176
+ Examples:
177
+ | hook_into |
178
+ | :fakeweb |
179
+ | :webmock |