mustwin-vcr 2.9.3

Sign up to get free protection for your applications and to get access to all the features.
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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5b144a01a758a27441ff9dc981d618fd557a4c89
4
+ data.tar.gz: e6d176c3f3914df9ebf8e717ca15fb64434fff33
5
+ SHA512:
6
+ metadata.gz: 83fa8d42a298514334b709f54730c7c25afb1767872fd2823d0506a59c309ba667437c8fe490b7071bd6ea77f90c7a5c64d6752bdb0a54f1ec9f06da8708e8ec
7
+ data.tar.gz: 6b5237e7020d77003dcc88639fc4325a603334eb353b91171755f2d035c976aeeb461484ae6c6b18dba63b94534fbe218ddd3ba416ec62e485cc3189226f5699
@@ -0,0 +1,18 @@
1
+ The cucumber features provided here demonstrate all of the major features of
2
+ VCR. These features are executable documentation for VCR.
3
+
4
+ Many of the examples use one (or both) of these helper functions
5
+ provided by `vcr_cucumber_helpers.rb`:
6
+
7
+ * `start_sinatra_app`: starts a sinatra application on the given port.
8
+ The server automatically shuts down when the ruby script ends. Many
9
+ examples re-run the script without the sinatra server to demonstrate
10
+ the replaying of a recorded HTTP response.
11
+ * `include_http_adapter_for`: includes a module that implements a common
12
+ HTTP interface for the given HTTP library. The `response_body_for`
13
+ method will make an HTTP request using the given library. This
14
+ allows scenarios to be run against each different supported HTTP
15
+ library.
16
+
17
+ If you have ideas to clarify or improve any of these cucumber features,
18
+ please submit an [issue](https://github.com/vcr/vcr/issues) or pull request.
@@ -0,0 +1,100 @@
1
+ Feature: Allow Unused HTTP Interactions
2
+
3
+ If set to false, this cassette option will cause VCR to raise an error
4
+ when a cassette is ejected and there are unused HTTP interactions remaining,
5
+ unless there is already an exception unwinding the callstack.
6
+
7
+ It verifies that all requests included in the cassette were made, and allows
8
+ VCR to function a bit like a mock object at the HTTP layer.
9
+
10
+ The option defaults to true (mostly for backwards compatibility).
11
+
12
+ Background:
13
+ Given a file named "vcr_config.rb" with:
14
+ """ruby
15
+ require 'vcr'
16
+
17
+ VCR.configure do |c|
18
+ c.hook_into :webmock
19
+ c.cassette_library_dir = 'cassettes'
20
+ end
21
+ """
22
+ And a previously recorded cassette file "cassettes/example.yml" with:
23
+ """
24
+ ---
25
+ http_interactions:
26
+ - request:
27
+ method: get
28
+ uri: http://example.com/foo
29
+ body:
30
+ encoding: UTF-8
31
+ string: ""
32
+ headers: {}
33
+ response:
34
+ status:
35
+ code: 200
36
+ message: OK
37
+ headers:
38
+ Content-Length:
39
+ - "5"
40
+ body:
41
+ encoding: UTF-8
42
+ string: Hello
43
+ http_version: "1.1"
44
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
45
+ recorded_with: VCR 2.0.0
46
+ """
47
+
48
+ Scenario: Unused HTTP interactions are allowed by default
49
+ Given a file named "allowed_by_default.rb" with:
50
+ """ruby
51
+ require 'vcr_config'
52
+
53
+ VCR.use_cassette("example") do
54
+ # no requests
55
+ end
56
+ """
57
+ When I run `ruby allowed_by_default.rb`
58
+ Then it should pass
59
+
60
+ Scenario: Error raised if option is false and there are unused interactions
61
+ Given a file named "disallowed_with_no_requests.rb" with:
62
+ """ruby
63
+ require 'vcr_config'
64
+
65
+ VCR.use_cassette("example", :allow_unused_http_interactions => false) do
66
+ # no requests
67
+ end
68
+ """
69
+ When I run `ruby disallowed_with_no_requests.rb`
70
+ Then it should fail with an error like:
71
+ """
72
+ There are unused HTTP interactions left in the cassette:
73
+ - [get http://example.com/foo] => [200 "Hello"]
74
+ """
75
+
76
+ Scenario: No error raised if option is false and all interactions are used
77
+ Given a file named "disallowed_with_all_requests.rb" with:
78
+ """ruby
79
+ require 'vcr_config'
80
+
81
+ VCR.use_cassette("example", :allow_unused_http_interactions => false) do
82
+ Net::HTTP.get_response(URI("http://example.com/foo"))
83
+ end
84
+ """
85
+ When I run `ruby disallowed_with_all_requests.rb`
86
+ Then it should pass
87
+
88
+ Scenario: Does not silence other errors raised in `use_cassette` block
89
+ Given a file named "does_not_silence_other_errors.rb" with:
90
+ """ruby
91
+ require 'vcr_config'
92
+
93
+ VCR.use_cassette("example", :allow_unused_http_interactions => false) do
94
+ raise "boom"
95
+ end
96
+ """
97
+ When I run `ruby does_not_silence_other_errors.rb`
98
+ Then it should fail with "boom"
99
+ And the output should not contain "There are unused HTTP interactions"
100
+
@@ -0,0 +1,72 @@
1
+ Feature: Automatic Re-recording
2
+
3
+ Over time, your cassettes may get out-of-date. APIs change and sites you
4
+ scrape get updated. VCR provides a facility to automatically re-record your
5
+ cassettes. Enable re-recording using the `:re_record_interval` option.
6
+
7
+ The value provided should be an interval (expressed in seconds) that
8
+ determines how often VCR will re-record the cassette. When a cassette
9
+ is used, VCR checks the earliest `recorded_at` timestamp in the cassette;
10
+ if more time than the interval has passed since that timestamp,
11
+ VCR will use the `:all` record mode to cause it be re-recorded.
12
+
13
+ Background:
14
+ Given a previously recorded cassette file "cassettes/example.yml" with:
15
+ """
16
+ ---
17
+ http_interactions:
18
+ - request:
19
+ method: get
20
+ uri: http://localhost/
21
+ body:
22
+ encoding: UTF-8
23
+ string: ""
24
+ headers: {}
25
+ response:
26
+ status:
27
+ code: 200
28
+ message: OK
29
+ headers:
30
+ Content-Length:
31
+ - "12"
32
+ body:
33
+ encoding: UTF-8
34
+ string: Old Response
35
+ http_version: "1.1"
36
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
37
+ recorded_with: VCR 2.0.0
38
+ """
39
+ And a file named "re_record.rb" with:
40
+ """ruby
41
+ $server = start_sinatra_app do
42
+ get('/') { 'New Response' }
43
+ end
44
+
45
+ require 'vcr'
46
+
47
+ VCR.configure do |c|
48
+ c.hook_into :webmock
49
+ c.cassette_library_dir = 'cassettes'
50
+ end
51
+
52
+ VCR.use_cassette('example', :re_record_interval => 7.days, :match_requests_on => [:method, :host, :path]) do
53
+ puts Net::HTTP.get_response('localhost', '/', $server.port).body
54
+ end
55
+ """
56
+
57
+ Scenario: Cassette is not re-recorded when not enough time has passed
58
+ Given it is Tue, 07 Nov 2011
59
+ When I run `ruby re_record.rb`
60
+ Then the output should contain "Old Response"
61
+ But the output should not contain "New Response"
62
+ And the file "cassettes/example.yml" should contain "Old Response"
63
+ But the file "cassettes/example.yml" should not contain "New Response"
64
+
65
+ Scenario: Cassette is re-recorded when enough time has passed
66
+ Given it is Tue, 09 Nov 2011
67
+ When I run `ruby re_record.rb`
68
+ Then the output should contain "New Response"
69
+ But the output should not contain "Old Response"
70
+ And the file "cassettes/example.yml" should contain "New Response"
71
+ But the file "cassettes/example.yml" should not contain "Old Response"
72
+
@@ -0,0 +1,74 @@
1
+ Feature: Decode compressed response
2
+
3
+ When the `:decode_compressed_response` option is set to a truthy value, VCR
4
+ will decompress "gzip" and "deflate" response bodies before recording. This
5
+ ensures that these interactions become readable and editable after being
6
+ serialized.
7
+
8
+ This option should be avoided if the actual decompression of response bodies
9
+ is part of the functionality of the library or app being tested.
10
+
11
+ Background:
12
+ Given a file named "decompress.rb" with:
13
+ """ruby
14
+ require 'zlib'
15
+ require 'stringio'
16
+
17
+ $server = start_sinatra_app do
18
+ get('/') {
19
+ content = 'The quick brown fox jumps over the lazy dog'
20
+ io = StringIO.new
21
+
22
+ writer = Zlib::GzipWriter.new(io)
23
+ writer << content
24
+ writer.close
25
+
26
+ headers['Content-Encoding'] = 'gzip'
27
+ io.string
28
+ }
29
+ end
30
+
31
+ require 'vcr'
32
+
33
+ VCR.configure do |c|
34
+ c.cassette_library_dir = 'cassettes'
35
+ c.hook_into :webmock
36
+ c.default_cassette_options = { :serialize_with => :syck }
37
+ end
38
+ """
39
+
40
+ Scenario: The option is not set by default
41
+ When I append to file "decompress.rb":
42
+ """ruby
43
+ VCR.use_cassette(:decompress) do
44
+ Net::HTTP.start('localhost', $server.port) do |http|
45
+ http.get('/', 'accept-encoding' => 'identity')
46
+ end
47
+ end
48
+ """
49
+ And I run `ruby decompress.rb`
50
+ Then the file "cassettes/decompress.yml" should contain a YAML fragment like:
51
+ """
52
+ Content-Encoding:
53
+ - gzip
54
+ """
55
+
56
+ Scenario: The option is enabled
57
+ When I append to file "decompress.rb":
58
+ """ruby
59
+ VCR.use_cassette(:decompress, :decode_compressed_response => true) do
60
+ Net::HTTP.start('localhost', $server.port) do |http|
61
+ http.get('/', 'accept-encoding' => 'identity')
62
+ end
63
+ end
64
+ """
65
+ And I run `ruby decompress.rb`
66
+ Then the file "cassettes/decompress.yml" should contain a YAML fragment like:
67
+ """
68
+ Content-Length:
69
+ - '43'
70
+ """
71
+ And the file "cassettes/decompress.yml" should contain:
72
+ """
73
+ string: The quick brown fox jumps over the lazy dog
74
+ """
@@ -0,0 +1,100 @@
1
+ Feature: Dynamic ERB cassettes
2
+
3
+ By default, cassettes are static: the exact response that was received
4
+ when the cassette was recorded will be replayed for all future requests.
5
+ Usually, this is fine, but in some cases you need something more dynamic.
6
+ You can use ERB for this.
7
+
8
+ To enable ERB evaluation of a cassette, pass the `:erb => true` option
9
+ to a cassette. If you want to pass variables to the cassette, you can
10
+ pass the names and values of the variables in a hash (`:erb => { ... }`).
11
+
12
+ Scenario: Enable dynamic ERB cassette evalutation using :erb => true
13
+ Given a previously recorded cassette file "cassettes/dynamic.yml" with:
14
+ """
15
+ ---
16
+ http_interactions:
17
+ - request:
18
+ method: get
19
+ uri: http://example.com/foo?a=<%= 'b' * 3 %>
20
+ body:
21
+ encoding: UTF-8
22
+ string: ''
23
+ headers: {}
24
+ response:
25
+ status:
26
+ code: 200
27
+ message: OK
28
+ headers:
29
+ Content-Type:
30
+ - text/html;charset=utf-8
31
+ Content-Length:
32
+ - '9'
33
+ body:
34
+ encoding: UTF-8
35
+ string: Hello <%= 'bar'.next %>
36
+ http_version: '1.1'
37
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
38
+ recorded_with: VCR 2.0.0
39
+ """
40
+ And a file named "dynamic_erb_example.rb" with:
41
+ """ruby
42
+ require 'vcr'
43
+
44
+ VCR.configure do |c|
45
+ c.hook_into :webmock
46
+ c.cassette_library_dir = 'cassettes'
47
+ end
48
+
49
+ VCR.use_cassette('dynamic', :erb => true) do
50
+ response = Net::HTTP.get_response('example.com', '/foo?a=bbb')
51
+ puts "Response: #{response.body}"
52
+ end
53
+ """
54
+ When I run `ruby dynamic_erb_example.rb`
55
+ Then it should pass with "Response: Hello bas"
56
+
57
+ Scenario: Pass arguments to the ERB using :erb => { ... }
58
+ Given a previously recorded cassette file "cassettes/dynamic.yml" with:
59
+ """
60
+ ---
61
+ http_interactions:
62
+ - request:
63
+ method: get
64
+ uri: http://example.com/foo?a=<%= arg1 %>
65
+ body:
66
+ encoding: UTF-8
67
+ string: ''
68
+ headers: {}
69
+ response:
70
+ status:
71
+ code: 200
72
+ message: OK
73
+ headers:
74
+ Content-Type:
75
+ - text/html;charset=utf-8
76
+ Content-Length:
77
+ - '9'
78
+ body:
79
+ encoding: UTF-8
80
+ string: Hello <%= arg2 %>
81
+ http_version: '1.1'
82
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
83
+ recorded_with: VCR 2.0.0
84
+ """
85
+ And a file named "dynamic_erb_example.rb" with:
86
+ """ruby
87
+ require 'vcr'
88
+
89
+ VCR.configure do |c|
90
+ c.hook_into :webmock
91
+ c.cassette_library_dir = 'cassettes'
92
+ end
93
+
94
+ VCR.use_cassette('dynamic', :erb => { :arg1 => 7, :arg2 => 'baz' }) do
95
+ response = Net::HTTP.get_response('example.com', '/foo?a=7')
96
+ puts "Response: #{response.body}"
97
+ end
98
+ """
99
+ When I run `ruby dynamic_erb_example.rb`
100
+ Then it should pass with "Response: Hello baz"
@@ -0,0 +1,126 @@
1
+ Feature: exclusive cassette
2
+
3
+ VCR allows cassettes to be nested. This is particularly useful in
4
+ a context like cucumber, where you may be using a cassette for an
5
+ entire scenario, and also using a cassette within a particular step
6
+ definition.
7
+
8
+ By default, both the inner and outer cassettes are active. On each
9
+ request, VCR will look for a matching HTTP interaction in the inner
10
+ cassette, and it will use the outer cassette as a fall back if none
11
+ can be found.
12
+
13
+ If you do not want the HTTP interactions of the outer cassette considered,
14
+ you can pass the `:exclusive` option, so that the inner cassette is
15
+ used exclusively.
16
+
17
+ Background:
18
+ Given a previously recorded cassette file "cassettes/outer.yml" with:
19
+ """
20
+ ---
21
+ http_interactions:
22
+ - request:
23
+ method: get
24
+ uri: http://localhost/outer
25
+ body:
26
+ encoding: UTF-8
27
+ string: ""
28
+ headers: {}
29
+ response:
30
+ status:
31
+ code: 200
32
+ message: OK
33
+ headers:
34
+ Content-Length:
35
+ - "18"
36
+ body:
37
+ encoding: UTF-8
38
+ string: Old outer response
39
+ http_version: "1.1"
40
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
41
+ recorded_with: VCR 2.0.0
42
+ """
43
+ And a previously recorded cassette file "cassettes/inner.yml" with:
44
+ """
45
+ ---
46
+ http_interactions:
47
+ - request:
48
+ method: get
49
+ uri: http://localhost/inner
50
+ body:
51
+ encoding: UTF-8
52
+ string: ""
53
+ headers: {}
54
+ response:
55
+ status:
56
+ code: 200
57
+ message: OK
58
+ headers:
59
+ Content-Length:
60
+ - "18"
61
+ body:
62
+ encoding: UTF-8
63
+ string: Old inner response
64
+ http_version: "1.1"
65
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
66
+ recorded_with: VCR 2.0.0
67
+ """
68
+ And a file named "setup.rb" with:
69
+ """ruby
70
+ include_http_adapter_for("net/http")
71
+
72
+ $server = start_sinatra_app do
73
+ get('/:path') { "New #{params[:path]} response" }
74
+ end
75
+
76
+ require 'vcr'
77
+
78
+ VCR.configure do |c|
79
+ c.hook_into :webmock
80
+ c.cassette_library_dir = 'cassettes'
81
+ c.default_cassette_options = {
82
+ :record => :new_episodes,
83
+ :match_requests_on => [:method, :host, :path]
84
+ }
85
+ end
86
+ """
87
+
88
+ Scenario: Cassettes are not exclusive by default
89
+ Given a file named "not_exclusive.rb" with:
90
+ """ruby
91
+ require 'setup'
92
+
93
+ VCR.use_cassette('outer') do
94
+ VCR.use_cassette('inner') do
95
+ puts response_body_for(:get, "http://localhost:#{$server.port}/outer")
96
+ puts response_body_for(:get, "http://localhost:#{$server.port}/inner")
97
+ end
98
+ end
99
+ """
100
+ When I run `ruby not_exclusive.rb`
101
+ Then it should pass with:
102
+ """
103
+ Old outer response
104
+ Old inner response
105
+ """
106
+
107
+ Scenario: Use an exclusive cassette
108
+ Given a file named "exclusive.rb" with:
109
+ """ruby
110
+ require 'setup'
111
+
112
+ VCR.use_cassette('outer') do
113
+ VCR.use_cassette('inner', :exclusive => true) do
114
+ puts response_body_for(:get, "http://localhost:#{$server.port}/outer")
115
+ puts response_body_for(:get, "http://localhost:#{$server.port}/inner")
116
+ end
117
+ end
118
+ """
119
+ When I run `ruby exclusive.rb`
120
+ Then it should pass with:
121
+ """
122
+ New outer response
123
+ Old inner response
124
+ """
125
+ And the file "cassettes/inner.yml" should contain "New outer response"
126
+