mustwin-vcr 2.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/features/about_these_examples.md +18 -0
- data/features/cassettes/allow_unused_http_interactions.feature +100 -0
- data/features/cassettes/automatic_re_recording.feature +72 -0
- data/features/cassettes/decompress.feature +74 -0
- data/features/cassettes/dynamic_erb.feature +100 -0
- data/features/cassettes/exclusive.feature +126 -0
- data/features/cassettes/format.feature +323 -0
- data/features/cassettes/freezing_time.feature +68 -0
- data/features/cassettes/naming.feature +28 -0
- data/features/cassettes/no_cassette.feature +152 -0
- data/features/cassettes/update_content_length_header.feature +112 -0
- data/features/configuration/allow_http_connections_when_no_cassette.feature +55 -0
- data/features/configuration/cassette_library_dir.feature +31 -0
- data/features/configuration/debug_logging.feature +59 -0
- data/features/configuration/default_cassette_options.feature +100 -0
- data/features/configuration/filter_sensitive_data.feature +153 -0
- data/features/configuration/hook_into.feature +172 -0
- data/features/configuration/ignore_request.feature +192 -0
- data/features/configuration/preserve_exact_body_bytes.feature +108 -0
- data/features/configuration/query_parser.feature +84 -0
- data/features/configuration/uri_parser.feature +89 -0
- data/features/getting_started.md +82 -0
- data/features/hooks/after_http_request.feature +58 -0
- data/features/hooks/around_http_request.feature +57 -0
- data/features/hooks/before_http_request.feature +63 -0
- data/features/hooks/before_playback.feature +184 -0
- data/features/hooks/before_record.feature +172 -0
- data/features/http_libraries/em_http_request.feature +250 -0
- data/features/http_libraries/net_http.feature +179 -0
- data/features/middleware/faraday.feature +56 -0
- data/features/middleware/rack.feature +92 -0
- data/features/record_modes/all.feature +82 -0
- data/features/record_modes/new_episodes.feature +79 -0
- data/features/record_modes/none.feature +72 -0
- data/features/record_modes/once.feature +95 -0
- data/features/request_matching/README.md +30 -0
- data/features/request_matching/body.feature +91 -0
- data/features/request_matching/body_as_json.feature +90 -0
- data/features/request_matching/custom_matcher.feature +135 -0
- data/features/request_matching/headers.feature +85 -0
- data/features/request_matching/host.feature +95 -0
- data/features/request_matching/identical_request_sequence.feature +89 -0
- data/features/request_matching/method.feature +96 -0
- data/features/request_matching/path.feature +96 -0
- data/features/request_matching/playback_repeats.feature +98 -0
- data/features/request_matching/query.feature +97 -0
- data/features/request_matching/uri.feature +94 -0
- data/features/request_matching/uri_without_param.feature +101 -0
- data/features/step_definitions/cli_steps.rb +193 -0
- data/features/support/env.rb +44 -0
- data/features/support/http_lib_filters.rb +53 -0
- data/features/test_frameworks/cucumber.feature +211 -0
- data/features/test_frameworks/rspec_macro.feature +81 -0
- data/features/test_frameworks/rspec_metadata.feature +150 -0
- data/features/test_frameworks/test_unit.feature +49 -0
- data/lib/vcr.rb +347 -0
- data/lib/vcr/cassette.rb +291 -0
- data/lib/vcr/cassette/erb_renderer.rb +55 -0
- data/lib/vcr/cassette/http_interaction_list.rb +108 -0
- data/lib/vcr/cassette/migrator.rb +118 -0
- data/lib/vcr/cassette/persisters.rb +42 -0
- data/lib/vcr/cassette/persisters/file_system.rb +64 -0
- data/lib/vcr/cassette/serializers.rb +57 -0
- data/lib/vcr/cassette/serializers/json.rb +48 -0
- data/lib/vcr/cassette/serializers/psych.rb +48 -0
- data/lib/vcr/cassette/serializers/syck.rb +61 -0
- data/lib/vcr/cassette/serializers/yaml.rb +50 -0
- data/lib/vcr/configuration.rb +555 -0
- data/lib/vcr/deprecations.rb +109 -0
- data/lib/vcr/errors.rb +266 -0
- data/lib/vcr/extensions/net_http_response.rb +36 -0
- data/lib/vcr/library_hooks.rb +18 -0
- data/lib/vcr/library_hooks/excon.rb +27 -0
- data/lib/vcr/library_hooks/fakeweb.rb +196 -0
- data/lib/vcr/library_hooks/faraday.rb +51 -0
- data/lib/vcr/library_hooks/typhoeus.rb +120 -0
- data/lib/vcr/library_hooks/typhoeus_0.4.rb +103 -0
- data/lib/vcr/library_hooks/webmock.rb +164 -0
- data/lib/vcr/middleware/excon.rb +221 -0
- data/lib/vcr/middleware/excon/legacy_methods.rb +33 -0
- data/lib/vcr/middleware/faraday.rb +118 -0
- data/lib/vcr/middleware/rack.rb +79 -0
- data/lib/vcr/request_handler.rb +114 -0
- data/lib/vcr/request_ignorer.rb +43 -0
- data/lib/vcr/request_matcher_registry.rb +149 -0
- data/lib/vcr/structs.rb +578 -0
- data/lib/vcr/tasks/vcr.rake +9 -0
- data/lib/vcr/test_frameworks/cucumber.rb +64 -0
- data/lib/vcr/test_frameworks/rspec.rb +47 -0
- data/lib/vcr/util/hooks.rb +61 -0
- data/lib/vcr/util/internet_connection.rb +43 -0
- data/lib/vcr/util/logger.rb +59 -0
- data/lib/vcr/util/variable_args_block_caller.rb +13 -0
- data/lib/vcr/util/version_checker.rb +48 -0
- data/lib/vcr/version.rb +34 -0
- data/spec/acceptance/threading_spec.rb +34 -0
- data/spec/fixtures/cassette_spec/1_x_cassette.yml +110 -0
- data/spec/fixtures/cassette_spec/empty.yml +0 -0
- data/spec/fixtures/cassette_spec/example.yml +111 -0
- data/spec/fixtures/cassette_spec/with_localhost_requests.yml +111 -0
- data/spec/fixtures/fake_example_responses.yml +110 -0
- data/spec/fixtures/match_requests_on.yml +187 -0
- data/spec/lib/vcr/cassette/erb_renderer_spec.rb +53 -0
- data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +295 -0
- data/spec/lib/vcr/cassette/migrator_spec.rb +195 -0
- data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +69 -0
- data/spec/lib/vcr/cassette/persisters_spec.rb +39 -0
- data/spec/lib/vcr/cassette/serializers_spec.rb +176 -0
- data/spec/lib/vcr/cassette_spec.rb +618 -0
- data/spec/lib/vcr/configuration_spec.rb +326 -0
- data/spec/lib/vcr/deprecations_spec.rb +85 -0
- data/spec/lib/vcr/errors_spec.rb +162 -0
- data/spec/lib/vcr/extensions/net_http_response_spec.rb +86 -0
- data/spec/lib/vcr/library_hooks/excon_spec.rb +104 -0
- data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +169 -0
- data/spec/lib/vcr/library_hooks/faraday_spec.rb +68 -0
- data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +36 -0
- data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +162 -0
- data/spec/lib/vcr/library_hooks/webmock_spec.rb +118 -0
- data/spec/lib/vcr/library_hooks_spec.rb +51 -0
- data/spec/lib/vcr/middleware/faraday_spec.rb +182 -0
- data/spec/lib/vcr/middleware/rack_spec.rb +115 -0
- data/spec/lib/vcr/request_ignorer_spec.rb +70 -0
- data/spec/lib/vcr/request_matcher_registry_spec.rb +345 -0
- data/spec/lib/vcr/structs_spec.rb +732 -0
- data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +107 -0
- data/spec/lib/vcr/test_frameworks/rspec_spec.rb +83 -0
- data/spec/lib/vcr/util/hooks_spec.rb +158 -0
- data/spec/lib/vcr/util/internet_connection_spec.rb +37 -0
- data/spec/lib/vcr/util/version_checker_spec.rb +31 -0
- data/spec/lib/vcr/version_spec.rb +27 -0
- data/spec/lib/vcr_spec.rb +349 -0
- data/spec/monkey_patches.rb +182 -0
- data/spec/spec_helper.rb +62 -0
- data/spec/support/configuration_stubbing.rb +8 -0
- data/spec/support/cucumber_helpers.rb +35 -0
- data/spec/support/fixnum_extension.rb +10 -0
- data/spec/support/http_library_adapters.rb +289 -0
- data/spec/support/limited_uri.rb +21 -0
- data/spec/support/ruby_interpreter.rb +7 -0
- data/spec/support/shared_example_groups/excon.rb +63 -0
- data/spec/support/shared_example_groups/hook_into_http_library.rb +594 -0
- data/spec/support/shared_example_groups/request_hooks.rb +59 -0
- data/spec/support/sinatra_app.rb +86 -0
- data/spec/support/vcr_localhost_server.rb +76 -0
- data/spec/support/vcr_stub_helpers.rb +17 -0
- metadata +677 -0
@@ -0,0 +1,211 @@
|
|
1
|
+
@with-bundler
|
2
|
+
Feature: Usage with Cucumber
|
3
|
+
|
4
|
+
VCR can be used with cucumber in two basic ways:
|
5
|
+
|
6
|
+
- Use `VCR.use_cassette` in a step definition.
|
7
|
+
- Use a `VCR.cucumber_tags` block to tell VCR to use a
|
8
|
+
cassette for a tagged scenario.
|
9
|
+
|
10
|
+
In a cucumber support file (e.g. features/support/vcr.rb), put code like this:
|
11
|
+
|
12
|
+
``` ruby
|
13
|
+
VCR.cucumber_tags do |t|
|
14
|
+
t.tag '@tag1'
|
15
|
+
t.tags '@tag2', '@tag3'
|
16
|
+
|
17
|
+
t.tag '@tag3', :cassette => :options
|
18
|
+
t.tags '@tag4', '@tag5', :cassette => :options
|
19
|
+
t.tag '@vcr', :use_scenario_name => true
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
VCR will use a cassette named `cucumber_tags/<tag_name>` for scenarios
|
24
|
+
with each of these tags (Unless the `:use_scenario_name` option is provided. See below).
|
25
|
+
The configured `default_cassette_options` will be used, or you can override specific
|
26
|
+
options by passing a hash as the last argument to `#tag` or `#tags`.
|
27
|
+
|
28
|
+
You can also have VCR name your cassettes automatically according to the feature
|
29
|
+
and scenario name by providing `:use_scenario_name => true` to `#tag` or `#tags`.
|
30
|
+
In this case, the cassette will be named `<feature_name>/<scenario_name>`.
|
31
|
+
For scenario outlines, VCR will record one cassette per row, and the cassettes
|
32
|
+
will be named `<feature_name>/<scenario_name>/<row_name>`.
|
33
|
+
|
34
|
+
@exclude-jruby
|
35
|
+
Scenario: Record HTTP interactions in a scenario by tagging it
|
36
|
+
Given a file named "lib/server.rb" with:
|
37
|
+
"""ruby
|
38
|
+
if ENV['WITH_SERVER'] == 'true'
|
39
|
+
$server = start_sinatra_app do
|
40
|
+
get('/:path') { "Hello #{params[:path]}" }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
"""
|
44
|
+
|
45
|
+
Given a file named "features/support/vcr.rb" with:
|
46
|
+
"""ruby
|
47
|
+
require "lib/server"
|
48
|
+
require 'vcr'
|
49
|
+
|
50
|
+
VCR.configure do |c|
|
51
|
+
c.hook_into :webmock
|
52
|
+
c.cassette_library_dir = 'features/cassettes'
|
53
|
+
c.default_cassette_options = {
|
54
|
+
:match_requests_on => [:method, :host, :path]
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
VCR.cucumber_tags do |t|
|
59
|
+
t.tag '@localhost_request' # uses default record mode since no options are given
|
60
|
+
t.tags '@disallowed_1', '@disallowed_2', :record => :none
|
61
|
+
t.tag '@vcr', :use_scenario_name => true
|
62
|
+
end
|
63
|
+
"""
|
64
|
+
And a file named "features/step_definitions/steps.rb" with:
|
65
|
+
"""ruby
|
66
|
+
require 'net/http'
|
67
|
+
|
68
|
+
When /^a request is made to "([^"]*)"$/ do |url|
|
69
|
+
uri = URI.parse(url)
|
70
|
+
uri.port = $server.port if $server
|
71
|
+
@response = Net::HTTP.get_response(uri)
|
72
|
+
end
|
73
|
+
|
74
|
+
When /^(.*) within a cassette named "([^"]*)"$/ do |step_name, cassette_name|
|
75
|
+
VCR.use_cassette(cassette_name) { step(step_name) }
|
76
|
+
end
|
77
|
+
|
78
|
+
Then /^the response should be "([^"]*)"$/ do |expected_response|
|
79
|
+
@response.body.should == expected_response
|
80
|
+
end
|
81
|
+
"""
|
82
|
+
And a file named "features/vcr_example.feature" with:
|
83
|
+
"""
|
84
|
+
Feature: VCR example
|
85
|
+
|
86
|
+
Note: Cucumber treats the pre-amble as part of the feature name. When
|
87
|
+
using the :use_scenario_name option, VCR will only use the first line
|
88
|
+
of the feature name as the directory for the cassette.
|
89
|
+
|
90
|
+
@localhost_request
|
91
|
+
Scenario: tagged scenario
|
92
|
+
When a request is made to "http://localhost:7777/localhost_request_1"
|
93
|
+
Then the response should be "Hello localhost_request_1"
|
94
|
+
When a request is made to "http://localhost:7777/nested_cassette" within a cassette named "nested_cassette"
|
95
|
+
Then the response should be "Hello nested_cassette"
|
96
|
+
When a request is made to "http://localhost:7777/localhost_request_2"
|
97
|
+
Then the response should be "Hello localhost_request_2"
|
98
|
+
|
99
|
+
@vcr
|
100
|
+
Scenario: tagged scenario
|
101
|
+
|
102
|
+
Note: Like the feature pre-amble, Cucumber treats the scenario pre-amble
|
103
|
+
as part of the scenario name. When using the :use_scenario_name option,
|
104
|
+
VCR will only use the first line of the feature name as the directory
|
105
|
+
for the cassette.
|
106
|
+
|
107
|
+
When a request is made to "http://localhost:7777/localhost_request_1"
|
108
|
+
Then the response should be "Hello localhost_request_1"
|
109
|
+
|
110
|
+
@vcr
|
111
|
+
Scenario Outline: tagged scenario outline
|
112
|
+
When a request is made to "http://localhost:7777/localhost_request_1"
|
113
|
+
Then the response should be "Hello localhost_request_1"
|
114
|
+
Examples:
|
115
|
+
| key | value |
|
116
|
+
| foo | bar |
|
117
|
+
|
118
|
+
@disallowed_1
|
119
|
+
Scenario: tagged scenario
|
120
|
+
When a request is made to "http://localhost:7777/allowed" within a cassette named "allowed"
|
121
|
+
Then the response should be "Hello allowed"
|
122
|
+
When a request is made to "http://localhost:7777/disallowed_1"
|
123
|
+
|
124
|
+
@disallowed_2
|
125
|
+
Scenario: tagged scenario
|
126
|
+
When a request is made to "http://localhost:7777/disallowed_2"
|
127
|
+
"""
|
128
|
+
And the directory "features/cassettes" does not exist
|
129
|
+
When I run `cucumber WITH_SERVER=true features/vcr_example.feature`
|
130
|
+
Then it should fail with "5 scenarios (2 failed, 3 passed)"
|
131
|
+
And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "Hello localhost_request_1"
|
132
|
+
And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "Hello localhost_request_2"
|
133
|
+
And the file "features/cassettes/nested_cassette.yml" should contain "Hello nested_cassette"
|
134
|
+
And the file "features/cassettes/allowed.yml" should contain "Hello allowed"
|
135
|
+
And the file "features/cassettes/VCR_example/tagged_scenario.yml" should contain "Hello localhost_request_1"
|
136
|
+
And the file "features/cassettes/VCR_example/tagged_scenario_outline/_foo_bar_.yml" should contain "Hello localhost_request_1"
|
137
|
+
|
138
|
+
# Run again without the server; we'll get the same responses because VCR
|
139
|
+
# will replay the recorded responses.
|
140
|
+
When I run `cucumber features/vcr_example.feature`
|
141
|
+
Then it should fail with "5 scenarios (2 failed, 3 passed)"
|
142
|
+
And the output should contain each of the following:
|
143
|
+
| An HTTP request has been made that VCR does not know how to handle: |
|
144
|
+
| GET http://localhost:7777/disallowed_1 |
|
145
|
+
| An HTTP request has been made that VCR does not know how to handle: |
|
146
|
+
| GET http://localhost:7777/disallowed_2 |
|
147
|
+
And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "Hello localhost_request_1"
|
148
|
+
And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "Hello localhost_request_2"
|
149
|
+
And the file "features/cassettes/nested_cassette.yml" should contain "Hello nested_cassette"
|
150
|
+
And the file "features/cassettes/allowed.yml" should contain "Hello allowed"
|
151
|
+
And the file "features/cassettes/VCR_example/tagged_scenario.yml" should contain "Hello localhost_request_1"
|
152
|
+
And the file "features/cassettes/VCR_example/tagged_scenario_outline/_foo_bar_.yml" should contain "Hello localhost_request_1"
|
153
|
+
|
154
|
+
Scenario: `:allow_unused_http_interactions => false` does not raise if the scenario already failed
|
155
|
+
Given a previously recorded cassette file "features/cassettes/cucumber_tags/example.yml" with:
|
156
|
+
"""
|
157
|
+
---
|
158
|
+
http_interactions:
|
159
|
+
- request:
|
160
|
+
method: get
|
161
|
+
uri: http://example.com/foo
|
162
|
+
body:
|
163
|
+
encoding: UTF-8
|
164
|
+
string: ""
|
165
|
+
headers: {}
|
166
|
+
response:
|
167
|
+
status:
|
168
|
+
code: 200
|
169
|
+
message: OK
|
170
|
+
headers:
|
171
|
+
Content-Length:
|
172
|
+
- "5"
|
173
|
+
body:
|
174
|
+
encoding: UTF-8
|
175
|
+
string: Hello
|
176
|
+
http_version: "1.1"
|
177
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
178
|
+
recorded_with: VCR 2.0.0
|
179
|
+
"""
|
180
|
+
And a file named "features/support/vcr.rb" with:
|
181
|
+
"""ruby
|
182
|
+
require 'vcr'
|
183
|
+
|
184
|
+
VCR.configure do |c|
|
185
|
+
c.hook_into :webmock
|
186
|
+
c.cassette_library_dir = 'features/cassettes'
|
187
|
+
end
|
188
|
+
|
189
|
+
VCR.cucumber_tags do |t|
|
190
|
+
t.tag '@example', :allow_unused_http_interactions => false
|
191
|
+
end
|
192
|
+
"""
|
193
|
+
And a file named "features/step_definitions/steps.rb" with:
|
194
|
+
"""ruby
|
195
|
+
When /^the scenario fails$/ do
|
196
|
+
raise "boom"
|
197
|
+
end
|
198
|
+
"""
|
199
|
+
And a file named "features/vcr_example.feature" with:
|
200
|
+
"""
|
201
|
+
Feature:
|
202
|
+
|
203
|
+
@example
|
204
|
+
Scenario: tagged scenario
|
205
|
+
When the scenario fails
|
206
|
+
"""
|
207
|
+
When I run `cucumber features/vcr_example.feature`
|
208
|
+
Then it should fail with "1 scenario (1 failed)"
|
209
|
+
And the output should contain "boom"
|
210
|
+
And the output should not contain "There are unused HTTP interactions"
|
211
|
+
|
@@ -0,0 +1,81 @@
|
|
1
|
+
@with-bundler
|
2
|
+
Feature: Usage with RSpec macro
|
3
|
+
|
4
|
+
VCR provides a macro that makes it easy to use a VCR cassette for an RSpec
|
5
|
+
example group. To use it, simply add `config.extend VCR::RSpec::Macros`
|
6
|
+
to your RSpec configuration block.
|
7
|
+
|
8
|
+
In any example group, add a `use_vcr_cassette` declaration to use a cassette
|
9
|
+
for that example group. You can use this in a few different ways:
|
10
|
+
|
11
|
+
- `use_vcr_cassette`
|
12
|
+
- Infers a cassette name from the example group description (and parent
|
13
|
+
example group descriptions).
|
14
|
+
- Uses the `default_cassette_options` you have configured.
|
15
|
+
- `use_vcr_cassette "Cassette Name"`
|
16
|
+
- Uses the given cassette name.
|
17
|
+
- Uses the `default_cassette_options` you have configured.
|
18
|
+
- `use_vcr_cassette :cassette => :options`
|
19
|
+
- Infers a cassette name from the example group description (and parent
|
20
|
+
example group descriptions).
|
21
|
+
- Uses the provided cassette options (merged with the defaults).
|
22
|
+
- `use_vcr_cassette "Cassette Name", :cassette => :options`
|
23
|
+
- Uses the given cassette name.
|
24
|
+
- Uses the provided cassette options (merged with the defaults).
|
25
|
+
|
26
|
+
Background:
|
27
|
+
Given the following files do not exist:
|
28
|
+
| spec/cassettes/VCR-RSpec_integration/without_an_explicit_cassette_name.yml |
|
29
|
+
| spec/cassettes/net_http_example.yml |
|
30
|
+
And a file named "spec/sinatra_app.rb" with:
|
31
|
+
"""ruby
|
32
|
+
$server = start_sinatra_app do
|
33
|
+
get('/') { "Hello" }
|
34
|
+
end
|
35
|
+
"""
|
36
|
+
And a file named "spec/vcr_example_spec.rb" with:
|
37
|
+
"""ruby
|
38
|
+
require 'spec_helper'
|
39
|
+
|
40
|
+
describe "VCR-RSpec integration" do
|
41
|
+
def make_http_request
|
42
|
+
Net::HTTP.get_response('localhost', '/', $server.port).body
|
43
|
+
end
|
44
|
+
|
45
|
+
context "without an explicit cassette name" do
|
46
|
+
use_vcr_cassette
|
47
|
+
|
48
|
+
it 'records an http request' do
|
49
|
+
make_http_request.should == 'Hello'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with an explicit cassette name" do
|
54
|
+
use_vcr_cassette "net_http_example"
|
55
|
+
|
56
|
+
it 'records an http request' do
|
57
|
+
make_http_request.should == 'Hello'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
"""
|
62
|
+
|
63
|
+
Scenario: Use `use_vcr_cassette` macro with RSpec 2
|
64
|
+
Given a file named "spec/spec_helper.rb" with:
|
65
|
+
"""ruby
|
66
|
+
require 'sinatra_app'
|
67
|
+
require 'vcr'
|
68
|
+
|
69
|
+
VCR.configure do |c|
|
70
|
+
c.cassette_library_dir = 'spec/cassettes'
|
71
|
+
c.hook_into :webmock
|
72
|
+
end
|
73
|
+
|
74
|
+
RSpec.configure do |c|
|
75
|
+
c.extend VCR::RSpec::Macros
|
76
|
+
end
|
77
|
+
"""
|
78
|
+
When I run `rspec spec/vcr_example_spec.rb`
|
79
|
+
Then the output should contain "2 examples, 0 failures"
|
80
|
+
And the file "spec/cassettes/VCR-RSpec_integration/without_an_explicit_cassette_name.yml" should contain "Hello"
|
81
|
+
And the file "spec/cassettes/net_http_example.yml" should contain "Hello"
|
@@ -0,0 +1,150 @@
|
|
1
|
+
@with-bundler
|
2
|
+
Feature: Usage with RSpec metadata
|
3
|
+
|
4
|
+
VCR provides easy integration with RSpec using metadata. To set this
|
5
|
+
up, call `configure_rspec_metadata!` in your `VCR.configure` block.
|
6
|
+
|
7
|
+
Once you've done that, you can have an example group or example use
|
8
|
+
VCR by passing `:vcr` as an additional argument after the description
|
9
|
+
string. It will set the cassette name based on the example's
|
10
|
+
full description.
|
11
|
+
|
12
|
+
If you need to override the cassette name or options, you can pass a
|
13
|
+
hash (`:vcr => { ... }`).
|
14
|
+
|
15
|
+
Background:
|
16
|
+
Given a file named "spec/spec_helper.rb" with:
|
17
|
+
"""ruby
|
18
|
+
require 'vcr'
|
19
|
+
|
20
|
+
VCR.configure do |c|
|
21
|
+
c.cassette_library_dir = 'spec/cassettes'
|
22
|
+
c.hook_into :webmock
|
23
|
+
c.configure_rspec_metadata!
|
24
|
+
end
|
25
|
+
|
26
|
+
RSpec.configure do |c|
|
27
|
+
# so we can use `:vcr` rather than `:vcr => true`;
|
28
|
+
# in RSpec 3 this will no longer be necessary.
|
29
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
30
|
+
end
|
31
|
+
"""
|
32
|
+
And a previously recorded cassette file "spec/cassettes/Group/optionally_raises_an_error.yml" with:
|
33
|
+
"""
|
34
|
+
---
|
35
|
+
http_interactions:
|
36
|
+
- request:
|
37
|
+
method: get
|
38
|
+
uri: http://example.com/foo
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: ""
|
42
|
+
headers: {}
|
43
|
+
response:
|
44
|
+
status:
|
45
|
+
code: 200
|
46
|
+
message: OK
|
47
|
+
headers:
|
48
|
+
Content-Length:
|
49
|
+
- "5"
|
50
|
+
body:
|
51
|
+
encoding: UTF-8
|
52
|
+
string: Hello
|
53
|
+
http_version: "1.1"
|
54
|
+
recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
|
55
|
+
recorded_with: VCR 2.0.0
|
56
|
+
"""
|
57
|
+
|
58
|
+
Scenario: Use `:vcr` metadata
|
59
|
+
Given a file named "spec/vcr_example_spec.rb" with:
|
60
|
+
"""ruby
|
61
|
+
$server = start_sinatra_app do
|
62
|
+
get('/') { "Hello" }
|
63
|
+
end
|
64
|
+
|
65
|
+
def make_http_request
|
66
|
+
Net::HTTP.get_response('localhost', '/', $server.port).body
|
67
|
+
end
|
68
|
+
|
69
|
+
require 'spec_helper'
|
70
|
+
|
71
|
+
describe "VCR example group metadata", :vcr do
|
72
|
+
it 'records an http request' do
|
73
|
+
make_http_request.should == 'Hello'
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'records another http request' do
|
77
|
+
make_http_request.should == 'Hello'
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'in a nested example group' do
|
81
|
+
it 'records another one' do
|
82
|
+
make_http_request.should == 'Hello'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "VCR example metadata" do
|
88
|
+
it 'records an http request', :vcr do
|
89
|
+
make_http_request.should == 'Hello'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
"""
|
93
|
+
When I run `rspec spec/vcr_example_spec.rb`
|
94
|
+
Then it should pass with "4 examples, 0 failures"
|
95
|
+
And the file "spec/cassettes/VCR_example_group_metadata/records_an_http_request.yml" should contain "Hello"
|
96
|
+
And the file "spec/cassettes/VCR_example_group_metadata/records_another_http_request.yml" should contain "Hello"
|
97
|
+
And the file "spec/cassettes/VCR_example_group_metadata/in_a_nested_example_group/records_another_one.yml" should contain "Hello"
|
98
|
+
And the file "spec/cassettes/VCR_example_metadata/records_an_http_request.yml" should contain "Hello"
|
99
|
+
|
100
|
+
Scenario: `:allow_unused_http_interactions => false` causes a failure if there are unused interactions
|
101
|
+
And a file named "spec/vcr_example_spec.rb" with:
|
102
|
+
"""ruby
|
103
|
+
require 'spec_helper'
|
104
|
+
|
105
|
+
describe "Group", :vcr => { :allow_unused_http_interactions => false } do
|
106
|
+
it 'optionally raises an error' do
|
107
|
+
# don't fail
|
108
|
+
end
|
109
|
+
end
|
110
|
+
"""
|
111
|
+
When I run `rspec spec/vcr_example_spec.rb`
|
112
|
+
Then it should fail with an error like:
|
113
|
+
"""
|
114
|
+
There are unused HTTP interactions left in the cassette:
|
115
|
+
- [get http://example.com/foo] => [200 "Hello"]
|
116
|
+
"""
|
117
|
+
|
118
|
+
Scenario: `:allow_unused_http_interactions => false` does not raise if the example already failed
|
119
|
+
And a file named "spec/vcr_example_spec.rb" with:
|
120
|
+
"""ruby
|
121
|
+
require 'spec_helper'
|
122
|
+
|
123
|
+
describe "Group", :vcr => { :allow_unused_http_interactions => false } do
|
124
|
+
it 'optionally raises an error' do
|
125
|
+
raise "boom"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
"""
|
129
|
+
When I run `rspec spec/vcr_example_spec.rb`
|
130
|
+
Then it should fail with "boom"
|
131
|
+
And the output should not contain "There are unused HTTP interactions"
|
132
|
+
|
133
|
+
Scenario: Pass a hash to set the cassette options
|
134
|
+
Given a file named "spec/vcr_example_spec.rb" with:
|
135
|
+
"""ruby
|
136
|
+
require 'spec_helper'
|
137
|
+
|
138
|
+
vcr_options = { :cassette_name => "example", :record => :new_episodes }
|
139
|
+
describe "Using an options hash", :vcr => vcr_options do
|
140
|
+
it 'uses the provided cassette name' do
|
141
|
+
VCR.current_cassette.name.should == "example"
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'sets the given options' do
|
145
|
+
VCR.current_cassette.record_mode.should == :new_episodes
|
146
|
+
end
|
147
|
+
end
|
148
|
+
"""
|
149
|
+
When I run `rspec spec/vcr_example_spec.rb`
|
150
|
+
Then it should pass with "2 examples, 0 failures"
|
@@ -0,0 +1,49 @@
|
|
1
|
+
Feature: Usage with Test::Unit
|
2
|
+
|
3
|
+
To use VCR with Test::Unit, wrap the body of any test method in
|
4
|
+
`VCR.use_cassette`.
|
5
|
+
|
6
|
+
Scenario: Use `VCR.use_cassette` in a test
|
7
|
+
Given a file named "test/test_server.rb" with:
|
8
|
+
"""ruby
|
9
|
+
$server = start_sinatra_app do
|
10
|
+
get('/') { "Hello" }
|
11
|
+
end
|
12
|
+
"""
|
13
|
+
Given a file named "test/test_helper.rb" with:
|
14
|
+
"""ruby
|
15
|
+
require 'test/test_server' if ENV['SERVER'] == 'true'
|
16
|
+
require 'test/unit'
|
17
|
+
require 'vcr'
|
18
|
+
|
19
|
+
VCR.configure do |c|
|
20
|
+
c.hook_into :webmock
|
21
|
+
c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
|
22
|
+
c.default_cassette_options = {
|
23
|
+
:match_requests_on => [:method, :host, :path]
|
24
|
+
}
|
25
|
+
end
|
26
|
+
"""
|
27
|
+
And a file named "test/vcr_example_test.rb" with:
|
28
|
+
"""ruby
|
29
|
+
require 'test_helper'
|
30
|
+
|
31
|
+
class VCRExampleTest < Test::Unit::TestCase
|
32
|
+
def test_use_vcr
|
33
|
+
VCR.use_cassette('test_unit_example') do
|
34
|
+
response = Net::HTTP.get_response('localhost', '/', $server ? $server.port : 0)
|
35
|
+
assert_equal "Hello", response.body
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
"""
|
40
|
+
And the directory "test/fixtures/vcr_cassettes" does not exist
|
41
|
+
When I set the "SERVER" environment variable to "true"
|
42
|
+
And I run `ruby -Itest test/vcr_example_test.rb`
|
43
|
+
Then it should pass with "1 tests, 1 assertions, 0 failures, 0 errors"
|
44
|
+
And the file "test/fixtures/vcr_cassettes/test_unit_example.yml" should contain "Hello"
|
45
|
+
|
46
|
+
# Run again without starting the sinatra server so the response will be replayed
|
47
|
+
When I set the "SERVER" environment variable to "false"
|
48
|
+
And I run `ruby -Itest test/vcr_example_test.rb`
|
49
|
+
Then it should pass with "1 tests, 1 assertions, 0 failures, 0 errors"
|