vcr 3.0.2 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +5 -5
  2. data/lib/vcr.rb +33 -1
  3. data/lib/vcr/cassette.rb +47 -12
  4. data/lib/vcr/cassette/http_interaction_list.rb +14 -9
  5. data/lib/vcr/cassette/migrator.rb +0 -5
  6. data/lib/vcr/cassette/persisters/file_system.rb +9 -1
  7. data/lib/vcr/cassette/serializers/compressed.rb +2 -2
  8. data/lib/vcr/cassette/serializers/json.rb +7 -7
  9. data/lib/vcr/cassette/serializers/psych.rb +3 -1
  10. data/lib/vcr/cassette/serializers/yaml.rb +3 -1
  11. data/lib/vcr/configuration.rb +20 -8
  12. data/lib/vcr/deprecations.rb +0 -62
  13. data/lib/vcr/errors.rb +17 -12
  14. data/lib/vcr/library_hooks/excon.rb +8 -0
  15. data/lib/vcr/library_hooks/typhoeus.rb +37 -8
  16. data/lib/vcr/linked_cassette.rb +4 -4
  17. data/lib/vcr/middleware/faraday.rb +10 -1
  18. data/lib/vcr/request_ignorer.rb +4 -1
  19. data/lib/vcr/request_matcher_registry.rb +1 -1
  20. data/lib/vcr/structs.rb +48 -32
  21. data/lib/vcr/test_frameworks/cucumber.rb +4 -4
  22. data/lib/vcr/test_frameworks/rspec.rb +12 -3
  23. data/lib/vcr/util/hooks.rb +1 -0
  24. data/lib/vcr/util/internet_connection.rb +15 -21
  25. data/lib/vcr/version.rb +1 -1
  26. metadata +36 -263
  27. data/features/CHANGELOG.md +0 -1
  28. data/features/CONTRIBUTING.md +0 -1
  29. data/features/LICENSE.md +0 -1
  30. data/features/README.md +0 -1
  31. data/features/Upgrade.md +0 -1
  32. data/features/about_these_examples.md +0 -18
  33. data/features/cassettes/allow_unused_http_interactions.feature +0 -100
  34. data/features/cassettes/automatic_re_recording.feature +0 -72
  35. data/features/cassettes/decompress.feature +0 -74
  36. data/features/cassettes/dynamic_erb.feature +0 -100
  37. data/features/cassettes/exclusive.feature +0 -126
  38. data/features/cassettes/format.feature +0 -411
  39. data/features/cassettes/freezing_time.feature +0 -68
  40. data/features/cassettes/naming.feature +0 -28
  41. data/features/cassettes/no_cassette.feature +0 -152
  42. data/features/cassettes/update_content_length_header.feature +0 -112
  43. data/features/configuration/allow_http_connections_when_no_cassette.feature +0 -55
  44. data/features/configuration/cassette_library_dir.feature +0 -31
  45. data/features/configuration/debug_logging.feature +0 -58
  46. data/features/configuration/default_cassette_options.feature +0 -100
  47. data/features/configuration/filter_sensitive_data.feature +0 -153
  48. data/features/configuration/hook_into.feature +0 -172
  49. data/features/configuration/ignore_request.feature +0 -192
  50. data/features/configuration/preserve_exact_body_bytes.feature +0 -108
  51. data/features/configuration/query_parser.feature +0 -84
  52. data/features/configuration/uri_parser.feature +0 -93
  53. data/features/getting_started.md +0 -82
  54. data/features/hooks/after_http_request.feature +0 -58
  55. data/features/hooks/around_http_request.feature +0 -57
  56. data/features/hooks/before_http_request.feature +0 -63
  57. data/features/hooks/before_playback.feature +0 -184
  58. data/features/hooks/before_record.feature +0 -172
  59. data/features/http_libraries/em_http_request.feature +0 -250
  60. data/features/http_libraries/net_http.feature +0 -179
  61. data/features/middleware/faraday.feature +0 -56
  62. data/features/middleware/rack.feature +0 -92
  63. data/features/record_modes/all.feature +0 -82
  64. data/features/record_modes/new_episodes.feature +0 -79
  65. data/features/record_modes/none.feature +0 -72
  66. data/features/record_modes/once.feature +0 -95
  67. data/features/request_matching/README.md +0 -30
  68. data/features/request_matching/body.feature +0 -91
  69. data/features/request_matching/body_as_json.feature +0 -90
  70. data/features/request_matching/custom_matcher.feature +0 -135
  71. data/features/request_matching/headers.feature +0 -85
  72. data/features/request_matching/host.feature +0 -95
  73. data/features/request_matching/identical_request_sequence.feature +0 -89
  74. data/features/request_matching/method.feature +0 -96
  75. data/features/request_matching/path.feature +0 -96
  76. data/features/request_matching/playback_repeats.feature +0 -98
  77. data/features/request_matching/query.feature +0 -97
  78. data/features/request_matching/uri.feature +0 -94
  79. data/features/request_matching/uri_without_param.feature +0 -101
  80. data/features/step_definitions/cli_steps.rb +0 -199
  81. data/features/support/env.rb +0 -46
  82. data/features/support/http_lib_filters.rb +0 -46
  83. data/features/test_frameworks/cucumber.feature +0 -211
  84. data/features/test_frameworks/rspec_macro.feature +0 -81
  85. data/features/test_frameworks/rspec_metadata.feature +0 -150
  86. data/features/test_frameworks/test_unit.feature +0 -49
  87. data/lib/vcr/extensions/net_http_response.rb +0 -36
  88. data/lib/vcr/library_hooks/fakeweb.rb +0 -197
  89. data/spec/acceptance/concurrency_spec.rb +0 -51
  90. data/spec/acceptance/threading_spec.rb +0 -34
  91. data/spec/fixtures/cassette_spec/1_x_cassette.yml +0 -110
  92. data/spec/fixtures/cassette_spec/empty.yml +0 -0
  93. data/spec/fixtures/cassette_spec/example.yml +0 -111
  94. data/spec/fixtures/cassette_spec/with_localhost_requests.yml +0 -111
  95. data/spec/fixtures/fake_example_responses.yml +0 -110
  96. data/spec/fixtures/match_requests_on.yml +0 -187
  97. data/spec/lib/vcr/cassette/erb_renderer_spec.rb +0 -53
  98. data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +0 -295
  99. data/spec/lib/vcr/cassette/migrator_spec.rb +0 -196
  100. data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +0 -75
  101. data/spec/lib/vcr/cassette/persisters_spec.rb +0 -39
  102. data/spec/lib/vcr/cassette/serializers_spec.rb +0 -182
  103. data/spec/lib/vcr/cassette_spec.rb +0 -618
  104. data/spec/lib/vcr/configuration_spec.rb +0 -326
  105. data/spec/lib/vcr/deprecations_spec.rb +0 -85
  106. data/spec/lib/vcr/errors_spec.rb +0 -178
  107. data/spec/lib/vcr/extensions/net_http_response_spec.rb +0 -86
  108. data/spec/lib/vcr/library_hooks/excon_spec.rb +0 -104
  109. data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +0 -169
  110. data/spec/lib/vcr/library_hooks/faraday_spec.rb +0 -68
  111. data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +0 -36
  112. data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +0 -162
  113. data/spec/lib/vcr/library_hooks/webmock_spec.rb +0 -117
  114. data/spec/lib/vcr/library_hooks_spec.rb +0 -51
  115. data/spec/lib/vcr/middleware/faraday_spec.rb +0 -181
  116. data/spec/lib/vcr/middleware/rack_spec.rb +0 -115
  117. data/spec/lib/vcr/request_ignorer_spec.rb +0 -70
  118. data/spec/lib/vcr/request_matcher_registry_spec.rb +0 -345
  119. data/spec/lib/vcr/structs_spec.rb +0 -732
  120. data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +0 -107
  121. data/spec/lib/vcr/test_frameworks/rspec_spec.rb +0 -94
  122. data/spec/lib/vcr/util/hooks_spec.rb +0 -158
  123. data/spec/lib/vcr/util/internet_connection_spec.rb +0 -37
  124. data/spec/lib/vcr/util/version_checker_spec.rb +0 -31
  125. data/spec/lib/vcr/version_spec.rb +0 -27
  126. data/spec/lib/vcr_spec.rb +0 -354
  127. data/spec/monkey_patches.rb +0 -186
  128. data/spec/spec_helper.rb +0 -63
  129. data/spec/support/configuration_stubbing.rb +0 -8
  130. data/spec/support/cucumber_helpers.rb +0 -39
  131. data/spec/support/fixnum_extension.rb +0 -10
  132. data/spec/support/http_library_adapters.rb +0 -289
  133. data/spec/support/limited_uri.rb +0 -21
  134. data/spec/support/ruby_interpreter.rb +0 -7
  135. data/spec/support/shared_example_groups/excon.rb +0 -63
  136. data/spec/support/shared_example_groups/hook_into_http_library.rb +0 -594
  137. data/spec/support/shared_example_groups/request_hooks.rb +0 -59
  138. data/spec/support/sinatra_app.rb +0 -86
  139. data/spec/support/vcr_localhost_server.rb +0 -76
  140. data/spec/support/vcr_stub_helpers.rb +0 -17
@@ -1,46 +0,0 @@
1
- require 'bundler'
2
- Bundler.setup
3
-
4
- ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
5
-
6
- require 'aruba/cucumber'
7
- require 'aruba/jruby' if RUBY_PLATFORM == 'java'
8
-
9
- gem_specs = Bundler.load.specs
10
- load_paths = Dir.glob(gem_specs.map { |spec|
11
- if spec.respond_to?(:lib_dirs_glob)
12
- spec.lib_dirs_glob
13
- else
14
- spec.load_paths
15
- end
16
- }.flatten)
17
-
18
- load_paths << File.expand_path("../../../spec", __FILE__)
19
- rubyopt = "-rsupport/cucumber_helpers"
20
-
21
- if RUBY_VERSION > '1.9'
22
- load_paths.unshift(".")
23
- rubyopt = "--disable-gems #{rubyopt}" unless "rbx" == ruby_engine
24
- end
25
-
26
- Before do
27
- @aruba_timeout_seconds = 30
28
- if "jruby" == ruby_engine
29
- @aruba_io_wait_seconds = 0.1
30
- else
31
- @aruba_io_wait_seconds = 0.02
32
- end
33
- end
34
-
35
- Before("~@with-bundler") do
36
- set_env("RUBYLIB", load_paths.join(":"))
37
- set_env("RUBYOPT", rubyopt)
38
- set_env("RBXOPT", "--disable-gems #{ENV["RBXOPT"]}") if "rbx" == ruby_engine
39
- set_env("GEM_HOME", nil)
40
- end
41
-
42
- Before("@with-bundler") do
43
- set_env("RUBYLIB", ".:#{ENV["RUBYLIB"]}:#{load_paths.last}")
44
- set_env("RUBYOPT", "#{ENV["RUBYOPT"]} -rsupport/cucumber_helpers")
45
- set_env("BUNDLE_GEMFILE", Bundler.default_gemfile.expand_path.to_s)
46
- end
@@ -1,46 +0,0 @@
1
- if RUBY_VERSION == '1.8.7'
2
- # We get timeouts on 1.8.7 w/ Patron for some reason.
3
- UNSUPPORTED_HTTP_LIBS = %w[ patron ]
4
- elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
5
- # Patron is freezing up the cukes (as it does on 1.9.2)
6
-
7
- # I'm not sure why em-http-request isn't working on rbx,
8
- # but considering the fact that VCR works with all the other
9
- # libs just fine and doesn't do anything for em-http-request,
10
- # it's probably a bug in it or rbx...so ignore it, for now.
11
-
12
- # I'm getting errors in the curb C extension in rbx.
13
-
14
- # Typhoeus should be buildable on rbx, but the travis build times out,
15
- # so we skip them to speed up the build on travis.
16
- UNSUPPORTED_HTTP_LIBS = %w[ patron em-http-request curb typhoeus ]
17
- elsif RUBY_PLATFORM == 'java'
18
- # These gems have C extensions and can't install on JRuby.
19
- c_dependent_libs = %w[ typhoeus patron curb em-http-request ]
20
-
21
- # The latest version of httpclient seems to freeze up the cukes
22
- # on JRuby. I'm not sure why, and there's little benefit to running
23
- # them on JRuby...so we just skip them. Excon seems to have the same issue :(.
24
- UNSUPPORTED_HTTP_LIBS = c_dependent_libs + %w[ httpclient excon ]
25
- end
26
-
27
- if defined?(UNSUPPORTED_HTTP_LIBS)
28
- UNSUPPORTED_HTTP_LIB_REGEX = Regexp.union(*UNSUPPORTED_HTTP_LIBS)
29
-
30
- # Filter out example rows that use libraries that are not supported on the current ruby interpreter
31
- Before do |scenario|
32
- if scenario.respond_to?(:cell_values) && scenario.cell_values.any? { |v| v =~ UNSUPPORTED_HTTP_LIB_REGEX }
33
- scenario.skip_invoke!
34
- end
35
- end
36
- end
37
-
38
- # Set a global based on the current stubbing lib so we can put special-case
39
- # logic in our step definitions based on the http stubbing library.
40
- Before do |scenario|
41
- if scenario.respond_to?(:cell_values)
42
- @scenario_parameters = scenario.cell_values
43
- else
44
- @scenario_parameters = nil
45
- end
46
- end
@@ -1,211 +0,0 @@
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
- expect(@response.body).to eq(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
-
@@ -1,81 +0,0 @@
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
- expect(make_http_request).to eq('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
- expect(make_http_request).to eq('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"
@@ -1,150 +0,0 @@
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
- expect(make_http_request).to eq('Hello')
74
- end
75
-
76
- it 'records another http request' do
77
- expect(make_http_request).to eq('Hello')
78
- end
79
-
80
- context 'in a nested example group' do
81
- it 'records another one' do
82
- expect(make_http_request).to eq('Hello')
83
- end
84
- end
85
- end
86
-
87
- describe "VCR example metadata" do
88
- it 'records an http request', :vcr do
89
- expect(make_http_request).to eq('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
- expect(VCR.current_cassette.name).to eq("example")
142
- end
143
-
144
- it 'sets the given options' do
145
- expect(VCR.current_cassette.record_mode).to eq(: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"