vcr 1.11.3 → 2.0.0.beta1

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 (166) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +6 -2
  3. data/CHANGELOG.md +49 -1
  4. data/Gemfile +1 -5
  5. data/Guardfile +0 -5
  6. data/README.md +3 -2
  7. data/Rakefile +11 -16
  8. data/cucumber.yml +0 -4
  9. data/features/.nav +14 -2
  10. data/features/cassettes/automatic_re_recording.feature +4 -6
  11. data/features/cassettes/dynamic_erb.feature +6 -8
  12. data/features/cassettes/exclusive.feature +111 -0
  13. data/features/cassettes/format.feature +16 -14
  14. data/features/cassettes/naming.feature +4 -6
  15. data/features/cassettes/no_cassette.feature +25 -28
  16. data/features/cassettes/update_content_length_header.feature +9 -9
  17. data/features/configuration/allow_http_connections_when_no_cassette.feature +6 -8
  18. data/features/configuration/cassette_library_dir.feature +4 -6
  19. data/features/configuration/default_cassette_options.feature +12 -10
  20. data/features/configuration/filter_sensitive_data.feature +12 -17
  21. data/features/configuration/{stub_with.feature → hook_into.feature} +63 -62
  22. data/features/configuration/hooks.feature +23 -33
  23. data/features/configuration/ignore_hosts.feature +16 -17
  24. data/features/configuration/ignore_localhost.feature +33 -42
  25. data/features/http_libraries/em_http_request.feature +7 -8
  26. data/features/http_libraries/net_http.feature +26 -28
  27. data/features/middleware/faraday.feature +17 -56
  28. data/features/middleware/rack.feature +8 -11
  29. data/features/record_modes/all.feature +5 -7
  30. data/features/record_modes/new_episodes.feature +5 -7
  31. data/features/record_modes/none.feature +6 -6
  32. data/features/record_modes/once.feature +6 -8
  33. data/features/request_matching/README.md +28 -0
  34. data/features/request_matching/body.feature +81 -0
  35. data/features/request_matching/custom_matcher.feature +125 -0
  36. data/features/request_matching/headers.feature +85 -0
  37. data/features/request_matching/host.feature +85 -0
  38. data/features/request_matching/identical_request_sequence.feature +79 -0
  39. data/features/request_matching/method.feature +86 -0
  40. data/features/request_matching/path.feature +86 -0
  41. data/features/request_matching/playback_repeats.feature +87 -0
  42. data/features/request_matching/uri.feature +84 -0
  43. data/features/request_matching/uri_without_param.feature +85 -0
  44. data/features/step_definitions/cli_steps.rb +4 -28
  45. data/features/support/env.rb +11 -9
  46. data/features/support/http_lib_filters.rb +2 -11
  47. data/features/support/vcr_cucumber_helpers.rb +4 -5
  48. data/features/test_frameworks/cucumber.feature +17 -18
  49. data/features/test_frameworks/rspec.feature +8 -12
  50. data/features/test_frameworks/shoulda.feature +5 -8
  51. data/features/test_frameworks/test_unit.feature +5 -8
  52. data/lib/vcr.rb +38 -58
  53. data/lib/vcr/cassette.rb +41 -60
  54. data/lib/vcr/cassette/http_interaction_list.rb +56 -0
  55. data/lib/vcr/cassette/reader.rb +29 -31
  56. data/lib/vcr/configuration.rb +76 -0
  57. data/lib/vcr/deprecations.rb +39 -0
  58. data/lib/vcr/errors.rb +22 -0
  59. data/lib/vcr/library_hooks.rb +19 -0
  60. data/lib/vcr/library_hooks/excon.rb +136 -0
  61. data/lib/vcr/library_hooks/fakeweb.rb +110 -0
  62. data/lib/vcr/library_hooks/faraday.rb +3 -0
  63. data/lib/vcr/library_hooks/typhoeus.rb +98 -0
  64. data/lib/vcr/library_hooks/webmock.rb +100 -0
  65. data/lib/vcr/middleware/faraday.rb +43 -36
  66. data/lib/vcr/middleware/rack.rb +28 -4
  67. data/lib/vcr/request_handler.rb +43 -0
  68. data/lib/vcr/request_ignorer.rb +31 -0
  69. data/lib/vcr/request_matcher_registry.rb +86 -0
  70. data/lib/vcr/structs/http_interaction.rb +24 -18
  71. data/lib/vcr/structs/normalizers/body.rb +1 -1
  72. data/lib/vcr/structs/normalizers/header.rb +1 -1
  73. data/lib/vcr/structs/normalizers/status_message.rb +1 -1
  74. data/lib/vcr/structs/normalizers/uri.rb +1 -1
  75. data/lib/vcr/structs/request.rb +0 -13
  76. data/lib/vcr/structs/response.rb +2 -9
  77. data/lib/vcr/structs/response_status.rb +0 -4
  78. data/lib/vcr/test_frameworks/cucumber.rb +1 -1
  79. data/lib/vcr/test_frameworks/rspec.rb +1 -1
  80. data/lib/vcr/util/hooks.rb +28 -19
  81. data/lib/vcr/util/internet_connection.rb +29 -2
  82. data/lib/vcr/util/version_checker.rb +60 -0
  83. data/lib/vcr/version.rb +1 -1
  84. data/script/FullBuildRakeFile +0 -7
  85. data/script/full_build +1 -1
  86. data/spec/capture_warnings.rb +36 -31
  87. data/spec/fixtures/{1.9.1/cassette_spec → cassette_spec}/empty.yml +0 -0
  88. data/spec/fixtures/{not_1.9.1/cassette_spec → cassette_spec}/example.yml +0 -0
  89. data/spec/fixtures/{not_1.9.1/cassette_spec → cassette_spec}/with_localhost_requests.yml +0 -0
  90. data/spec/fixtures/{not_1.9.1/fake_example.com_responses.yml → fake_example.com_responses.yml} +0 -0
  91. data/spec/fixtures/{not_1.9.1/match_requests_on.yml → match_requests_on.yml} +0 -0
  92. data/spec/monkey_patches.rb +40 -11
  93. data/spec/spec_helper.rb +7 -43
  94. data/spec/support/http_library_adapters.rb +3 -13
  95. data/spec/support/shared_example_groups/{http_library.rb → hook_into_http_library.rb} +39 -111
  96. data/spec/support/shared_example_groups/version_checking.rb +9 -9
  97. data/spec/vcr/cassette/http_interaction_list_spec.rb +178 -0
  98. data/spec/vcr/cassette/reader_spec.rb +2 -2
  99. data/spec/vcr/cassette_spec.rb +121 -156
  100. data/spec/vcr/configuration_spec.rb +143 -0
  101. data/spec/vcr/deprecations_spec.rb +91 -0
  102. data/spec/vcr/{http_stubbing_adapters → library_hooks}/excon_spec.rb +6 -9
  103. data/spec/vcr/library_hooks/fakeweb_spec.rb +83 -0
  104. data/spec/vcr/{http_stubbing_adapters → library_hooks}/typhoeus_spec.rb +7 -11
  105. data/spec/vcr/library_hooks/webmock_spec.rb +17 -0
  106. data/spec/vcr/library_hooks_spec.rb +51 -0
  107. data/spec/vcr/middleware/faraday_spec.rb +17 -44
  108. data/spec/vcr/middleware/rack_spec.rb +94 -58
  109. data/spec/vcr/request_ignorer_spec.rb +54 -0
  110. data/spec/vcr/request_matcher_registry_spec.rb +223 -0
  111. data/spec/vcr/structs/request_spec.rb +0 -33
  112. data/spec/vcr/structs/response_spec.rb +0 -24
  113. data/spec/vcr/structs/response_status_spec.rb +0 -9
  114. data/spec/vcr/util/hooks_spec.rb +3 -5
  115. data/spec/vcr/version_spec.rb +1 -1
  116. data/spec/vcr_spec.rb +79 -91
  117. data/vcr.gemspec +1 -1
  118. metadata +83 -103
  119. data/features/cassettes/request_matching.feature +0 -383
  120. data/lib/vcr/config.rb +0 -84
  121. data/lib/vcr/deprecations/cassette.rb +0 -29
  122. data/lib/vcr/deprecations/config.rb +0 -18
  123. data/lib/vcr/deprecations/http_stubbing_adapters/common.rb +0 -9
  124. data/lib/vcr/deprecations/http_stubbing_adapters/fakeweb.rb +0 -11
  125. data/lib/vcr/extensions/net_http.rb +0 -32
  126. data/lib/vcr/http_stubbing_adapters/common.rb +0 -202
  127. data/lib/vcr/http_stubbing_adapters/excon.rb +0 -178
  128. data/lib/vcr/http_stubbing_adapters/fakeweb.rb +0 -107
  129. data/lib/vcr/http_stubbing_adapters/faraday.rb +0 -26
  130. data/lib/vcr/http_stubbing_adapters/multi_object_proxy.rb +0 -43
  131. data/lib/vcr/http_stubbing_adapters/typhoeus.rb +0 -115
  132. data/lib/vcr/http_stubbing_adapters/webmock.rb +0 -120
  133. data/lib/vcr/middleware/cassette_arguments.rb +0 -19
  134. data/lib/vcr/middleware/common.rb +0 -20
  135. data/lib/vcr/request_matcher.rb +0 -94
  136. data/lib/vcr/rspec.rb +0 -2
  137. data/lib/vcr/util/basic_object.rb +0 -43
  138. data/lib/vcr/util/ping.rb +0 -30
  139. data/lib/vcr/util/regexes.rb +0 -37
  140. data/spec/fixtures/1.9.1/0_3_1_cassette.yml +0 -29
  141. data/spec/fixtures/1.9.1/cassette_spec/example.yml +0 -110
  142. data/spec/fixtures/1.9.1/cassette_spec/with_localhost_requests.yml +0 -109
  143. data/spec/fixtures/1.9.1/example_net_http.yml +0 -14
  144. data/spec/fixtures/1.9.1/example_net_http_request.yml +0 -12
  145. data/spec/fixtures/1.9.1/example_net_http_response.yml +0 -25
  146. data/spec/fixtures/1.9.1/fake_example.com_responses.yml +0 -108
  147. data/spec/fixtures/1.9.1/match_requests_on.yml +0 -185
  148. data/spec/fixtures/not_1.9.1/0_3_1_cassette.yml +0 -29
  149. data/spec/fixtures/not_1.9.1/cassette_spec/empty.yml +0 -0
  150. data/spec/fixtures/not_1.9.1/example_net_http.yml +0 -14
  151. data/spec/fixtures/not_1.9.1/example_net_http_request.yml +0 -12
  152. data/spec/fixtures/not_1.9.1/example_net_http_response.yml +0 -25
  153. data/spec/support/shared_example_groups/http_stubbing_adapter.rb +0 -133
  154. data/spec/support/shared_example_groups/ignore_localhost_deprecation.rb +0 -28
  155. data/spec/vcr/config_spec.rb +0 -181
  156. data/spec/vcr/deprecations/cassette_spec.rb +0 -57
  157. data/spec/vcr/deprecations/config_spec.rb +0 -30
  158. data/spec/vcr/deprecations/http_stubbing_adapters/common_spec.rb +0 -7
  159. data/spec/vcr/deprecations/http_stubbing_adapters/fakeweb_spec.rb +0 -16
  160. data/spec/vcr/extensions/net_http_spec.rb +0 -80
  161. data/spec/vcr/http_stubbing_adapters/fakeweb_spec.rb +0 -19
  162. data/spec/vcr/http_stubbing_adapters/faraday_spec.rb +0 -76
  163. data/spec/vcr/http_stubbing_adapters/multi_object_proxy_spec.rb +0 -101
  164. data/spec/vcr/http_stubbing_adapters/webmock_spec.rb +0 -17
  165. data/spec/vcr/middleware/cassette_arguments_spec.rb +0 -32
  166. data/spec/vcr/request_matcher_spec.rb +0 -230
data/.gitignore CHANGED
@@ -31,3 +31,5 @@ Gemfile.lock
31
31
  features/README.md
32
32
  features/CHANGELOG.md
33
33
  features/LICENSE.md
34
+
35
+ .rvmrc
data/.travis.yml CHANGED
@@ -1,10 +1,14 @@
1
1
  env: CUCUMBER_FORMAT=progress
2
2
  bundler_args: --without extras
3
- script: "bundle exec rake ci:build"
3
+ script: "bundle exec rake ci:build --trace"
4
4
  rvm:
5
- - 1.8.6
6
5
  - 1.8.7
7
6
  - 1.9.2
8
7
  - 1.9.3
9
8
  - ree
10
9
  - jruby
10
+ branches:
11
+ only:
12
+ - master
13
+ - 1-x-stable
14
+
data/CHANGELOG.md CHANGED
@@ -1,6 +1,54 @@
1
1
  ## In git
2
2
 
3
- [Full Changelog](http://github.com/myronmarston/vcr/compare/v1.11.3...master)
3
+ [Full Changelog](http://github.com/myronmarston/vcr/compare/v2.0.0.beta1...master)
4
+
5
+ ## 2.0.0 Beta 1 (October 8, 2011)
6
+
7
+ [Full Changelog](http://github.com/myronmarston/vcr/compare/v1.11.3...v2.0.0.beta1)
8
+
9
+ ### Changes
10
+
11
+ * Previously, the last matching response in a cassette would
12
+ repeatedly playback if the same request kept being made. This is
13
+ no longer the case.
14
+ * The Faraday middleware has been rewritten.
15
+ * You no longer need to configure `stub_with :faraday` to use it.
16
+ * It has been updated to work in parallel mode.
17
+ * It no longer accepts a block and uses that to determine the
18
+ cassette. Instead, use `VCR.use_cassette` just like you would
19
+ with FakeWeb or WebMock.
20
+
21
+ ### Added
22
+
23
+ * Allow any callable (an object that responds to #call, such as a
24
+ lambda) to be used as a request matcher. Thanks to [Avdi Grimm](https://github.com/avdi)
25
+ for the idea.
26
+ * Add ability to register custom request matchers.
27
+ * Add `VCR.request_matchers.uri_without_param(:some_param)` to generate
28
+ a request matcher that matches on URI but ignores the named parameter.
29
+ * New `:allow_playback_repeats` cassette option preserves the old
30
+ playback repeat behavior. Thanks to [Avdi Grimm](https://github.com/avdi)
31
+ for the idea.
32
+ * New `:exclusive` cassette option allows a cassette to be exclusively
33
+ used rather than keeping the existing one active as a fallback. Thanks
34
+ to [Avdi Grimm](https://github.com/avdi) for the idea.
35
+
36
+ ### Removed
37
+
38
+ * Removed support for Ruby 1.8.6 and 1.9.1.
39
+ * Removed lots of old deprecated APIs.
40
+ * Removed support for manually changing the URI in a cassette to a regex.
41
+
42
+ ### Deprecated
43
+
44
+ * Deprecated `VCR.config` in favor of `VCR.configure`.
45
+ * Deprecated `VCR::Config` singleton module in favor of
46
+ `VCR::Configuration` class. The current configuration instance
47
+ can be accessed via `VCR.configuration`.
48
+ * Deprecated `stub_with` in favor of `hook_into`. The stubbing
49
+ adapters have been completely rewritten and are no longer an
50
+ implementation of the adapter design pattern. Instead they simply
51
+ use the named library to globally hook into every HTTP request.
4
52
 
5
53
  ## 1.11.3 (August 31, 2011)
6
54
 
data/Gemfile CHANGED
@@ -18,9 +18,8 @@ end
18
18
  # Additional gems that are useful, but not required for development.
19
19
  group :extras do
20
20
  gem 'guard-rspec'
21
- gem 'guard-cucumber'
22
21
  gem 'growl'
23
- gem 'relish'
22
+ gem 'relish', '~> 0.5.0'
24
23
  gem 'fuubar'
25
24
  gem 'fuubar-cucumber'
26
25
 
@@ -31,13 +30,10 @@ group :extras do
31
30
 
32
31
  platforms :mri_18 do
33
32
  gem 'ruby-debug'
34
- gem 'linecache', '0.43' # later versions do not work on 1.8.6
35
33
  end
36
34
 
37
35
  platforms :mri_19 do
38
- gem 'linecache19', '0.5.11' # 0.5.12 cannot install on 1.9.1, and 0.5.11 appears to work with both 1.9.1 & 1.9.2
39
36
  gem 'ruby-debug19'
40
- gem 'ruby-debug-base19', RUBY_VERSION == '1.9.1' ? '0.11.23' : '~> 0.11.24'
41
37
  end unless RUBY_VERSION == '1.9.3'
42
38
  end
43
39
 
data/Guardfile CHANGED
@@ -7,8 +7,3 @@ guard 'rspec', :version => 2 do
7
7
  watch(%r|^spec/spec_helper.rb|) { "spec" }
8
8
  end
9
9
 
10
- guard 'cucumber' do
11
- watch(%r|^features/(.*).feature|)
12
- watch(%r|^features/support|) { 'features' }
13
- watch(%r|^features/step_definitions|) { 'features' }
14
- end
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.
4
4
 
5
+ [![Build Status](https://secure.travis-ci.org/myronmarston/vcr.png?branch=master)](http://travis-ci.org/myronmarston/vcr)
6
+
5
7
  ## Synopsis
6
8
 
7
9
  ``` ruby
@@ -82,9 +84,7 @@ contain backwards-incompatible changes to the public API.
82
84
 
83
85
  VCR has been tested on the following ruby interpreters:
84
86
 
85
- * MRI 1.8.6
86
87
  * MRI 1.8.7
87
- * MRI 1.9.1
88
88
  * MRI 1.9.2
89
89
  * REE 1.8.7
90
90
  * JRuby 1.5.6
@@ -144,6 +144,7 @@ Thanks also to the following people who have contributed patches or helpful sugg
144
144
  * [Nathaniel Bibler](https://github.com/nbibler)
145
145
  * [Oliver Searle-Barnes](https://github.com/opsb)
146
146
  * [Wesley Beary](https://github.com/geemus)
147
+ * [Avdi Grimm](https://github.com/avdi)
147
148
 
148
149
  ## Copyright
149
150
 
data/Rakefile CHANGED
@@ -11,7 +11,10 @@ require "rspec/core/rake_task"
11
11
 
12
12
  RSpec::Core::RakeTask.new(:spec) do |t|
13
13
  t.verbose = false
14
- t.ruby_opts = "-w -r./spec/capture_warnings"
14
+
15
+ # we require spec_helper so we don't get an RSpec warning about
16
+ # examples being defined before configuration.
17
+ t.ruby_opts = "-w -I./spec -r./spec/capture_warnings -rspec_helper"
15
18
 
16
19
  # I'm not sure why, but bundler seems to silence warnings...
17
20
  t.skip_bundler = true
@@ -29,10 +32,8 @@ task :cleanup_rcov_files do
29
32
  rm_rf 'coverage.data'
30
33
  end
31
34
 
32
- unless RUBY_VERSION == '1.8.6'
33
- require 'cucumber/rake/task'
34
- Cucumber::Rake::Task.new
35
- end
35
+ require 'cucumber/rake/task'
36
+ Cucumber::Rake::Task.new
36
37
 
37
38
  task :default => [:spec, :cucumber]
38
39
 
@@ -46,16 +47,17 @@ namespace :ci do
46
47
 
47
48
  RSpec::Core::RakeTask.new(:spec) do |t|
48
49
  t.verbose = true
49
- t.ruby_opts = "-w -r./spec/capture_warnings"
50
+
51
+ # we require spec_helper so we don't get an RSpec warning about
52
+ # examples being defined before configuration.
53
+ t.ruby_opts = "-w -I./spec -r./spec/capture_warnings -rspec_helper"
50
54
  # I'm not sure why, but bundler seems to silence warnings...
51
55
  t.skip_bundler = true
52
56
  t.rspec_opts = %w[--format progress --backtrace]
53
57
  end
54
58
 
55
- ci_tasks = [:setup, :spec]
56
- ci_tasks << :cucumber if %w[ 1.8.7 1.9.2 1.9.3 ].include?(RUBY_VERSION) && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby')
57
59
  desc "Run a ci build"
58
- task :build => ci_tasks
60
+ task :build => [:setup, :spec, :cucumber]
59
61
  end
60
62
 
61
63
  def ensure_relish_doc_symlinked(filename)
@@ -98,10 +100,3 @@ task :release => [:require_ruby_18, :prep_relish_release, :relish]
98
100
  # For gem-test: http://gem-testers.org/
99
101
  task :test => :spec
100
102
 
101
- task :fix_should_eq do
102
- Dir["spec/**/*.rb"].each do |spec_file|
103
- contents = File.read(spec_file)
104
- contents.gsub!(/should == (.*)$/, 'should eq(\1)')
105
- File.open(spec_file, 'w') { |f| f.write(contents) }
106
- end
107
- end
data/cucumber.yml CHANGED
@@ -7,10 +7,6 @@ interp_opts = if defined?(RUBY_ENGINE)
7
7
  else
8
8
  ''
9
9
  end
10
-
11
- if ENV['TRAVIS'] && RUBY_VERSION == '1.8.6'
12
- interp_opts << ' --tags ~@exclude-travis-186'
13
- end
14
10
  %>
15
11
  default: <%= std_opts %><%= interp_opts %> features
16
12
  wip: --tags @wip:30 --wip features<%= interp_opts %>
data/features/.nav CHANGED
@@ -6,9 +6,9 @@
6
6
  - format.feature
7
7
  - naming.feature
8
8
  - no_cassette.feature
9
- - request_matching.feature
10
9
  - dynamic_erb.feature
11
10
  - automatic_re_recording.feature
11
+ - exclusive.feature
12
12
  - update_content_length_header.feature
13
13
  - record_modes:
14
14
  - once.feature
@@ -17,12 +17,24 @@
17
17
  - all.feature
18
18
  - configuration:
19
19
  - cassette_library_dir.feature
20
- - stub_with.feature
20
+ - hook_into.feature
21
21
  - default_cassette_options.feature
22
22
  - ignore_hosts.feature
23
23
  - ignore_localhost.feature
24
24
  - hooks.feature
25
+ - filter_sensitive_data.feature
25
26
  - allow_http_connections_when_no_cassette.feature
27
+ - request_matching:
28
+ - method.feature
29
+ - uri.feature
30
+ - host.feature
31
+ - path.feature
32
+ - body.feature
33
+ - headers.feature
34
+ - identical_request_sequence.feature
35
+ - custom_matcher.feature
36
+ - uri_without_param.feature
37
+ - playback_repeats.feature
26
38
  - test_frameworks:
27
39
  - test_unit.feature
28
40
  - shoulda.feature
@@ -31,21 +31,19 @@ Feature: Automatic Re-recording
31
31
  http_version: "1.1"
32
32
  """
33
33
  And a file named "re_record.rb" with:
34
- """
35
- require 'vcr_cucumber_helpers'
36
-
34
+ """ruby
37
35
  start_sinatra_app(:port => 7777) do
38
36
  get('/') { 'New Response' }
39
37
  end
40
38
 
41
39
  require 'vcr'
42
40
 
43
- VCR.config do |c|
44
- c.stub_with :fakeweb
41
+ VCR.configure do |c|
42
+ c.hook_into :fakeweb
45
43
  c.cassette_library_dir = 'cassettes'
46
44
  end
47
45
 
48
- VCR.use_cassette('example', :record => :new_episodes, :re_record_interval => 7.days) do
46
+ VCR.use_cassette('example', :re_record_interval => 7.days) do
49
47
  puts Net::HTTP.get_response('localhost', '/', 7777).body
50
48
  end
51
49
  """
@@ -32,13 +32,12 @@ Feature: Dynamic ERB cassettes
32
32
  http_version: "1.1"
33
33
  """
34
34
  And a file named "dynamic_erb_example.rb" with:
35
- """
35
+ """ruby
36
36
  require 'vcr'
37
37
 
38
- VCR.config do |c|
39
- c.stub_with :fakeweb
38
+ VCR.configure do |c|
39
+ c.hook_into :fakeweb
40
40
  c.cassette_library_dir = 'cassettes'
41
- c.default_cassette_options = { :record => :none }
42
41
  end
43
42
 
44
43
  VCR.use_cassette('dynamic', :erb => true) do
@@ -72,13 +71,12 @@ Feature: Dynamic ERB cassettes
72
71
  http_version: "1.1"
73
72
  """
74
73
  And a file named "dynamic_erb_example.rb" with:
75
- """
74
+ """ruby
76
75
  require 'vcr'
77
76
 
78
- VCR.config do |c|
79
- c.stub_with :fakeweb
77
+ VCR.configure do |c|
78
+ c.hook_into :fakeweb
80
79
  c.cassette_library_dir = 'cassettes'
81
- c.default_cassette_options = { :record => :none }
82
80
  end
83
81
 
84
82
  VCR.use_cassette('dynamic', :erb => { :arg1 => 7, :arg2 => 'baz' }) do
@@ -0,0 +1,111 @@
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
+ - !ruby/struct:VCR::HTTPInteraction
22
+ request: !ruby/struct:VCR::Request
23
+ method: :get
24
+ uri: http://localhost:7777/outer
25
+ body:
26
+ headers:
27
+ response: !ruby/struct:VCR::Response
28
+ status: !ruby/struct:VCR::ResponseStatus
29
+ code: 200
30
+ message: OK
31
+ headers:
32
+ content-length:
33
+ - "18"
34
+ body: Old outer response
35
+ http_version: "1.1"
36
+ """
37
+ And a previously recorded cassette file "cassettes/inner.yml" with:
38
+ """
39
+ ---
40
+ - !ruby/struct:VCR::HTTPInteraction
41
+ request: !ruby/struct:VCR::Request
42
+ method: :get
43
+ uri: http://localhost:7777/inner
44
+ body:
45
+ headers:
46
+ response: !ruby/struct:VCR::Response
47
+ status: !ruby/struct:VCR::ResponseStatus
48
+ code: 200
49
+ message: OK
50
+ headers:
51
+ content-length:
52
+ - "18"
53
+ body: Old inner response
54
+ http_version: "1.1"
55
+ """
56
+ And a file named "setup.rb" with:
57
+ """ruby
58
+ include_http_adapter_for("net/http")
59
+
60
+ start_sinatra_app(:port => 7777) do
61
+ get('/:path') { "New #{params[:path]} response" }
62
+ end
63
+
64
+ require 'vcr'
65
+
66
+ VCR.configure do |c|
67
+ c.hook_into :fakeweb
68
+ c.cassette_library_dir = 'cassettes'
69
+ c.default_cassette_options = { :record => :new_episodes }
70
+ end
71
+ """
72
+
73
+ Scenario: Cassettes are not exclusive by default
74
+ Given a file named "not_exclusive.rb" with:
75
+ """ruby
76
+ require 'setup'
77
+
78
+ VCR.use_cassette('outer') do
79
+ VCR.use_cassette('inner') do
80
+ puts response_body_for(:get, "http://localhost:7777/outer")
81
+ puts response_body_for(:get, "http://localhost:7777/inner")
82
+ end
83
+ end
84
+ """
85
+ When I run `ruby not_exclusive.rb`
86
+ Then it should pass with:
87
+ """
88
+ Old outer response
89
+ Old inner response
90
+ """
91
+
92
+ Scenario: Use an exclusive cassette
93
+ Given a file named "exclusive.rb" with:
94
+ """ruby
95
+ require 'setup'
96
+
97
+ VCR.use_cassette('outer') do
98
+ VCR.use_cassette('inner', :exclusive => true) do
99
+ puts response_body_for(:get, "http://localhost:7777/outer")
100
+ puts response_body_for(:get, "http://localhost:7777/inner")
101
+ end
102
+ end
103
+ """
104
+ When I run `ruby exclusive.rb`
105
+ Then it should pass with:
106
+ """
107
+ New outer response
108
+ Old inner response
109
+ """
110
+ And the file "cassettes/inner.yml" should contain "body: New outer response"
111
+
@@ -20,8 +20,7 @@ Feature: Cassette format
20
20
 
21
21
  Scenario Outline: Request/Response data is saved to disk as YAML
22
22
  Given a file named "cassette_format.rb" with:
23
- """
24
- require 'vcr_cucumber_helpers'
23
+ """ruby
25
24
  include_http_adapter_for("<http_lib>")
26
25
 
27
26
  start_sinatra_app(:port => 7777) do
@@ -30,12 +29,12 @@ Feature: Cassette format
30
29
 
31
30
  require 'vcr'
32
31
 
33
- VCR.config do |c|
34
- c.stub_with <stub_with>
32
+ VCR.configure do |c|
33
+ <configuration>
35
34
  c.cassette_library_dir = 'cassettes'
36
35
  end
37
36
 
38
- VCR.use_cassette('example', :record => :new_episodes) do
37
+ VCR.use_cassette('example') do
39
38
  make_http_request(:get, "http://localhost:7777/foo")
40
39
  make_http_request(:get, "http://localhost:7777/bar")
41
40
  end
@@ -81,12 +80,15 @@ Feature: Cassette format
81
80
  """
82
81
 
83
82
  Examples:
84
- | stub_with | http_lib |
85
- | :fakeweb | net/http |
86
- | :webmock | net/http |
87
- | :webmock | httpclient |
88
- | :webmock | patron |
89
- | :webmock | curb |
90
- | :webmock | em-http-request |
91
- | :typhoeus | typhoeus |
92
- | :excon | excon |
83
+ | configuration | http_lib |
84
+ | c.hook_into :fakeweb | net/http |
85
+ | c.hook_into :webmock | net/http |
86
+ | c.hook_into :webmock | httpclient |
87
+ | c.hook_into :webmock | patron |
88
+ | c.hook_into :webmock | curb |
89
+ | c.hook_into :webmock | em-http-request |
90
+ | c.hook_into :webmock | typhoeus |
91
+ | c.hook_into :typhoeus | typhoeus |
92
+ | c.hook_into :excon | excon |
93
+ | | faraday (w/ net_http) |
94
+