vcr 3.0.3 → 4.0.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 (127) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vcr.rb +18 -1
  3. data/lib/vcr/cassette.rb +11 -3
  4. data/lib/vcr/cassette/persisters/file_system.rb +1 -1
  5. data/lib/vcr/configuration.rb +3 -5
  6. data/lib/vcr/deprecations.rb +0 -62
  7. data/lib/vcr/errors.rb +16 -0
  8. data/lib/vcr/library_hooks/typhoeus.rb +37 -8
  9. data/lib/vcr/middleware/faraday.rb +5 -1
  10. data/lib/vcr/structs.rb +1 -1
  11. data/lib/vcr/util/hooks.rb +1 -0
  12. data/lib/vcr/version.rb +1 -1
  13. metadata +9 -249
  14. data/features/CHANGELOG.md +0 -710
  15. data/features/CONTRIBUTING.md +0 -26
  16. data/features/LICENSE.md +0 -20
  17. data/features/README.md +0 -339
  18. data/features/Upgrade.md +0 -289
  19. data/features/about_these_examples.md +0 -18
  20. data/features/cassettes/allow_unused_http_interactions.feature +0 -100
  21. data/features/cassettes/automatic_re_recording.feature +0 -72
  22. data/features/cassettes/decompress.feature +0 -74
  23. data/features/cassettes/dynamic_erb.feature +0 -100
  24. data/features/cassettes/exclusive.feature +0 -126
  25. data/features/cassettes/format.feature +0 -411
  26. data/features/cassettes/freezing_time.feature +0 -68
  27. data/features/cassettes/naming.feature +0 -28
  28. data/features/cassettes/no_cassette.feature +0 -152
  29. data/features/cassettes/update_content_length_header.feature +0 -112
  30. data/features/configuration/allow_http_connections_when_no_cassette.feature +0 -55
  31. data/features/configuration/cassette_library_dir.feature +0 -31
  32. data/features/configuration/debug_logging.feature +0 -58
  33. data/features/configuration/default_cassette_options.feature +0 -100
  34. data/features/configuration/filter_sensitive_data.feature +0 -153
  35. data/features/configuration/hook_into.feature +0 -172
  36. data/features/configuration/ignore_request.feature +0 -192
  37. data/features/configuration/preserve_exact_body_bytes.feature +0 -108
  38. data/features/configuration/query_parser.feature +0 -84
  39. data/features/configuration/uri_parser.feature +0 -93
  40. data/features/getting_started.md +0 -82
  41. data/features/hooks/after_http_request.feature +0 -58
  42. data/features/hooks/around_http_request.feature +0 -57
  43. data/features/hooks/before_http_request.feature +0 -63
  44. data/features/hooks/before_playback.feature +0 -184
  45. data/features/hooks/before_record.feature +0 -172
  46. data/features/http_libraries/em_http_request.feature +0 -250
  47. data/features/http_libraries/net_http.feature +0 -179
  48. data/features/middleware/faraday.feature +0 -56
  49. data/features/middleware/rack.feature +0 -92
  50. data/features/record_modes/all.feature +0 -82
  51. data/features/record_modes/new_episodes.feature +0 -79
  52. data/features/record_modes/none.feature +0 -72
  53. data/features/record_modes/once.feature +0 -95
  54. data/features/request_matching/README.md +0 -30
  55. data/features/request_matching/body.feature +0 -91
  56. data/features/request_matching/body_as_json.feature +0 -90
  57. data/features/request_matching/custom_matcher.feature +0 -135
  58. data/features/request_matching/headers.feature +0 -85
  59. data/features/request_matching/host.feature +0 -95
  60. data/features/request_matching/identical_request_sequence.feature +0 -89
  61. data/features/request_matching/method.feature +0 -96
  62. data/features/request_matching/path.feature +0 -96
  63. data/features/request_matching/playback_repeats.feature +0 -98
  64. data/features/request_matching/query.feature +0 -97
  65. data/features/request_matching/uri.feature +0 -94
  66. data/features/request_matching/uri_without_param.feature +0 -101
  67. data/features/step_definitions/cli_steps.rb +0 -199
  68. data/features/support/env.rb +0 -46
  69. data/features/support/http_lib_filters.rb +0 -46
  70. data/features/test_frameworks/cucumber.feature +0 -211
  71. data/features/test_frameworks/rspec_macro.feature +0 -81
  72. data/features/test_frameworks/rspec_metadata.feature +0 -150
  73. data/features/test_frameworks/test_unit.feature +0 -49
  74. data/lib/vcr/extensions/net_http_response.rb +0 -36
  75. data/lib/vcr/library_hooks/fakeweb.rb +0 -197
  76. data/spec/acceptance/concurrency_spec.rb +0 -51
  77. data/spec/acceptance/threading_spec.rb +0 -34
  78. data/spec/fixtures/cassette_spec/1_x_cassette.yml +0 -110
  79. data/spec/fixtures/cassette_spec/empty.yml +0 -0
  80. data/spec/fixtures/cassette_spec/example.yml +0 -111
  81. data/spec/fixtures/cassette_spec/with_localhost_requests.yml +0 -111
  82. data/spec/fixtures/fake_example_responses.yml +0 -110
  83. data/spec/fixtures/match_requests_on.yml +0 -187
  84. data/spec/lib/vcr/cassette/erb_renderer_spec.rb +0 -53
  85. data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +0 -295
  86. data/spec/lib/vcr/cassette/migrator_spec.rb +0 -196
  87. data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +0 -75
  88. data/spec/lib/vcr/cassette/persisters_spec.rb +0 -39
  89. data/spec/lib/vcr/cassette/serializers_spec.rb +0 -182
  90. data/spec/lib/vcr/cassette_spec.rb +0 -618
  91. data/spec/lib/vcr/configuration_spec.rb +0 -326
  92. data/spec/lib/vcr/deprecations_spec.rb +0 -85
  93. data/spec/lib/vcr/errors_spec.rb +0 -178
  94. data/spec/lib/vcr/extensions/net_http_response_spec.rb +0 -86
  95. data/spec/lib/vcr/library_hooks/excon_spec.rb +0 -104
  96. data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +0 -169
  97. data/spec/lib/vcr/library_hooks/faraday_spec.rb +0 -68
  98. data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +0 -36
  99. data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +0 -162
  100. data/spec/lib/vcr/library_hooks/webmock_spec.rb +0 -117
  101. data/spec/lib/vcr/library_hooks_spec.rb +0 -51
  102. data/spec/lib/vcr/middleware/faraday_spec.rb +0 -181
  103. data/spec/lib/vcr/middleware/rack_spec.rb +0 -115
  104. data/spec/lib/vcr/request_ignorer_spec.rb +0 -70
  105. data/spec/lib/vcr/request_matcher_registry_spec.rb +0 -345
  106. data/spec/lib/vcr/structs_spec.rb +0 -732
  107. data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +0 -107
  108. data/spec/lib/vcr/test_frameworks/rspec_spec.rb +0 -94
  109. data/spec/lib/vcr/util/hooks_spec.rb +0 -158
  110. data/spec/lib/vcr/util/internet_connection_spec.rb +0 -37
  111. data/spec/lib/vcr/util/version_checker_spec.rb +0 -31
  112. data/spec/lib/vcr/version_spec.rb +0 -27
  113. data/spec/lib/vcr_spec.rb +0 -354
  114. data/spec/monkey_patches.rb +0 -186
  115. data/spec/spec_helper.rb +0 -63
  116. data/spec/support/configuration_stubbing.rb +0 -8
  117. data/spec/support/cucumber_helpers.rb +0 -39
  118. data/spec/support/fixnum_extension.rb +0 -10
  119. data/spec/support/http_library_adapters.rb +0 -289
  120. data/spec/support/limited_uri.rb +0 -21
  121. data/spec/support/ruby_interpreter.rb +0 -7
  122. data/spec/support/shared_example_groups/excon.rb +0 -63
  123. data/spec/support/shared_example_groups/hook_into_http_library.rb +0 -594
  124. data/spec/support/shared_example_groups/request_hooks.rb +0 -59
  125. data/spec/support/sinatra_app.rb +0 -86
  126. data/spec/support/vcr_localhost_server.rb +0 -76
  127. data/spec/support/vcr_stub_helpers.rb +0 -17
@@ -1,63 +0,0 @@
1
- Feature: before_http_request hook
2
-
3
- The `before_http_request` hook gets called with each request
4
- just before it proceeds. It can be used for many things:
5
-
6
- * globally logging requests
7
- * inserting a particular cassette based on the request URI host
8
- * raising a timeout error
9
-
10
- You can also pass one or more "filters" to `before_http_request`, to make
11
- the hook only be called for some requests. Any object that responds to `#to_proc`
12
- can be a filter. Here are some simple examples:
13
-
14
- * `:real?` -- only real requests
15
- * `:stubbed?` -- only stubbed requests
16
- * `:ignored?` -- only ignored requests
17
- * `:recordable?` -- only requests that are being recorded
18
- * `lambda { |r| URI(r.uri).host == 'amazon.com' }` -- only requests to amazon.com.
19
-
20
- Scenario Outline: log all requests using a before_http_request hook
21
- Given a file named "before_http_request.rb" with:
22
- """ruby
23
- include_http_adapter_for("<http_lib>")
24
-
25
- if ARGV.include?('--with-server')
26
- $server = start_sinatra_app do
27
- get('/') { "Hello World" }
28
- end
29
- end
30
-
31
- require 'vcr'
32
-
33
- VCR.configure do |c|
34
- <configuration>
35
- c.cassette_library_dir = 'cassettes'
36
- c.before_http_request(:real?) do |request|
37
- File.open(ARGV.first, 'w') do |f|
38
- f.write("before real request: #{request.method} #{request.uri}")
39
- end
40
- end
41
- end
42
-
43
- VCR.use_cassette('hook_example') do
44
- port = $server ? $server.port : 0
45
- make_http_request(:get, "http://localhost:#{port}/")
46
- end
47
- """
48
- When I run `ruby before_http_request.rb run1.log --with-server`
49
- Given that port numbers in "run1.log" are normalized to "7777"
50
- Then the file "run1.log" should contain "before real request: get http://localhost:7777/"
51
- When I run `ruby before_http_request.rb run2.log`
52
- Then the file "run2.log" should not exist
53
-
54
- Examples:
55
- | configuration | http_lib |
56
- | c.hook_into :fakeweb | net/http |
57
- | c.hook_into :webmock | net/http |
58
- | c.hook_into :webmock | httpclient |
59
- | c.hook_into :webmock | curb |
60
- | c.hook_into :typhoeus | typhoeus |
61
- | c.hook_into :excon | excon |
62
- | c.hook_into :faraday | faraday (w/ net_http) |
63
-
@@ -1,184 +0,0 @@
1
- Feature: before_playback hook
2
-
3
- The `before_playback` hook is called before a cassette sets up its
4
- stubs for playback.
5
-
6
- Your block should accept up to 2 arguments. The first argument will be
7
- the HTTP interaction that is about to be used for play back. The second
8
- argument will be the current cassette.
9
-
10
- You can also call `#ignore!` on the HTTP interaction to prevent VCR
11
- from playing it back.
12
-
13
- You can use tags to specify a cassette, otherwise your hook will apply to all cassettes. Consider this code:
14
-
15
- VCR.configure do |c|
16
- c.before_playback(:twitter) { ... } # modify the interactions somehow
17
- end
18
-
19
- VCR.use_cassette('cassette_1', :tag => :twitter) { ... }
20
- VCR.use_cassette('cassette_2') { ... }
21
-
22
- In this example, the hook would apply to the first cassette but not the
23
- second cassette.
24
-
25
- Background:
26
- Given a previously recorded cassette file "cassettes/example.yml" with:
27
- """
28
- ---
29
- http_interactions:
30
- - request:
31
- method: get
32
- uri: http://localhost:7777/
33
- body:
34
- encoding: UTF-8
35
- string: ""
36
- headers: {}
37
- response:
38
- status:
39
- code: 200
40
- message: OK
41
- headers:
42
- Content-Type:
43
- - text/html;charset=utf-8
44
- Content-Length:
45
- - "20"
46
- body:
47
- encoding: UTF-8
48
- string: previously recorded response
49
- http_version: "1.1"
50
- recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
51
- recorded_with: VCR 2.0.0
52
- """
53
-
54
- Scenario: Modify played back response
55
- Given a file named "before_playback_example.rb" with:
56
- """ruby
57
- require 'vcr'
58
-
59
- VCR.configure do |c|
60
- c.hook_into :webmock
61
- c.cassette_library_dir = 'cassettes'
62
-
63
- c.before_playback do |interaction|
64
- interaction.response.body = 'response from before_playback'
65
- end
66
- end
67
-
68
- VCR.use_cassette('example') do
69
- response = Net::HTTP.get_response('localhost', '/', 7777)
70
- puts "Response: #{response.body}"
71
- end
72
- """
73
- When I run `ruby before_playback_example.rb`
74
- Then it should pass with "Response: response from before_playback"
75
-
76
- Scenario: Modify played back response based on the cassette
77
- Given a file named "before_playback_example.rb" with:
78
- """ruby
79
- require 'vcr'
80
-
81
- VCR.configure do |c|
82
- c.hook_into :webmock
83
- c.cassette_library_dir = 'cassettes'
84
-
85
- c.before_playback do |interaction, cassette|
86
- interaction.response.body = "response for #{cassette.name} cassette"
87
- end
88
- end
89
-
90
- VCR.use_cassette('example') do
91
- response = Net::HTTP.get_response('localhost', '/', 7777)
92
- puts "Response: #{response.body}"
93
- end
94
- """
95
- When I run `ruby before_playback_example.rb`
96
- Then it should pass with "Response: response for example cassette"
97
-
98
- Scenario: Prevent playback by ignoring interaction in before_playback hook
99
- Given a file named "before_playback_ignore.rb" with:
100
- """ruby
101
- $server = start_sinatra_app do
102
- get('/') { "sinatra response" }
103
- end
104
-
105
- require 'vcr'
106
-
107
- VCR.configure do |c|
108
- c.hook_into :webmock
109
- c.cassette_library_dir = 'cassettes'
110
- c.before_playback { |i| i.ignore! }
111
- end
112
-
113
- VCR.use_cassette('localhost', :record => :new_episodes, :match_requests_on => [:method, :host, :path]) do
114
- response = Net::HTTP.get_response('localhost', '/', $server.port)
115
- puts "Response: #{response.body}"
116
- end
117
- """
118
- When I run `ruby before_playback_ignore.rb`
119
- Then it should pass with "Response: sinatra response"
120
-
121
- Scenario: Multiple hooks are run in order
122
- Given a file named "multiple_hooks.rb" with:
123
- """ruby
124
- require 'vcr'
125
-
126
- VCR.configure do |c|
127
- c.hook_into :webmock
128
- c.cassette_library_dir = 'cassettes'
129
-
130
- c.before_playback { puts "In before_playback hook 1" }
131
- c.before_playback { puts "In before_playback hook 2" }
132
- end
133
-
134
- VCR.use_cassette('example', :record => :new_episodes) do
135
- response = Net::HTTP.get_response('localhost', '/', 7777)
136
- puts "Response: #{response.body}"
137
- end
138
- """
139
- When I run `ruby multiple_hooks.rb`
140
- Then it should pass with:
141
- """
142
- In before_playback hook 1
143
- In before_playback hook 2
144
- Response: previously recorded response
145
- """
146
-
147
- Scenario: Use tagging to apply hooks to only certain cassettes
148
- Given a file named "tagged_hooks.rb" with:
149
- """ruby
150
- require 'vcr'
151
-
152
- VCR.configure do |c|
153
- c.hook_into :webmock
154
- c.cassette_library_dir = 'cassettes'
155
-
156
- c.before_playback(:tag_2) do |i|
157
- puts "In before_playback hook for tag_2"
158
- end
159
- end
160
-
161
- [:tag_1, :tag_2, nil].each do |tag|
162
- puts
163
- puts "Using tag: #{tag.inspect}"
164
-
165
- VCR.use_cassette('example', :record => :new_episodes, :tag => tag) do
166
- response = Net::HTTP.get_response('localhost', '/', 7777)
167
- puts "Response: #{response.body}"
168
- end
169
- end
170
- """
171
- When I run `ruby tagged_hooks.rb`
172
- Then it should pass with:
173
- """
174
- Using tag: :tag_1
175
- Response: previously recorded response
176
-
177
- Using tag: :tag_2
178
- In before_playback hook for tag_2
179
- Response: previously recorded response
180
-
181
- Using tag: nil
182
- Response: previously recorded response
183
- """
184
-
@@ -1,172 +0,0 @@
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
-
@@ -1,250 +0,0 @@
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
-