vcr 2.0.0.beta2 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +0 -2
  3. data/CHANGELOG.md +22 -1
  4. data/CONTRIBUTING.md +46 -0
  5. data/Gemfile +1 -9
  6. data/README.md +8 -2
  7. data/Rakefile +12 -1
  8. data/cucumber.yml +8 -9
  9. data/features/.nav +10 -4
  10. data/features/cassettes/format.feature +1 -1
  11. data/features/cassettes/no_cassette.feature +8 -11
  12. data/features/configuration/allow_http_connections_when_no_cassette.feature +4 -4
  13. data/features/configuration/filter_sensitive_data.feature +3 -0
  14. data/features/configuration/hook_into.feature +4 -8
  15. data/features/configuration/ignore_request.feature +191 -0
  16. data/features/getting_started.md +38 -21
  17. data/features/hooks/after_http_request.feature +44 -0
  18. data/features/hooks/around_http_request.feature +56 -0
  19. data/features/hooks/before_http_request.feature +44 -0
  20. data/features/hooks/before_playback.feature +181 -0
  21. data/features/hooks/before_record.feature +172 -0
  22. data/features/middleware/faraday.feature +7 -3
  23. data/features/record_modes/none.feature +2 -1
  24. data/features/record_modes/once.feature +2 -1
  25. data/features/request_matching/body.feature +2 -2
  26. data/features/request_matching/custom_matcher.feature +2 -2
  27. data/features/request_matching/headers.feature +2 -2
  28. data/features/request_matching/host.feature +2 -2
  29. data/features/request_matching/identical_request_sequence.feature +2 -2
  30. data/features/request_matching/method.feature +2 -2
  31. data/features/request_matching/path.feature +2 -2
  32. data/features/request_matching/playback_repeats.feature +2 -1
  33. data/features/request_matching/uri.feature +2 -2
  34. data/features/support/env.rb +21 -12
  35. data/features/test_frameworks/cucumber.feature +9 -4
  36. data/features/test_frameworks/{rspec.feature → rspec_macro.feature} +7 -7
  37. data/features/test_frameworks/rspec_metadata.feature +90 -0
  38. data/lib/vcr.rb +1 -1
  39. data/lib/vcr/cassette.rb +3 -3
  40. data/lib/vcr/cassette/http_interaction_list.rb +13 -9
  41. data/lib/vcr/cassette/migrator.rb +1 -1
  42. data/lib/vcr/configuration.rb +37 -0
  43. data/lib/vcr/errors.rb +172 -6
  44. data/lib/vcr/library_hooks.rb +4 -6
  45. data/lib/vcr/library_hooks/excon.rb +23 -11
  46. data/lib/vcr/library_hooks/fakeweb.rb +85 -24
  47. data/lib/vcr/library_hooks/faraday.rb +30 -2
  48. data/lib/vcr/library_hooks/typhoeus.rb +25 -3
  49. data/lib/vcr/library_hooks/webmock.rb +25 -36
  50. data/lib/vcr/middleware/faraday.rb +23 -5
  51. data/lib/vcr/request_handler.rb +12 -1
  52. data/lib/vcr/request_ignorer.rb +12 -1
  53. data/lib/vcr/request_matcher_registry.rb +1 -9
  54. data/lib/vcr/structs.rb +32 -2
  55. data/lib/vcr/test_frameworks/rspec.rb +28 -0
  56. data/lib/vcr/util/hooks.rb +12 -4
  57. data/lib/vcr/util/version_checker.rb +2 -0
  58. data/lib/vcr/version.rb +1 -1
  59. data/spec/fixtures/cassette_spec/example.yml +1 -1
  60. data/spec/fixtures/{fake_example.com_responses.yml → fake_example_responses.yml} +0 -0
  61. data/spec/monkey_patches.rb +1 -1
  62. data/spec/spec_helper.rb +3 -1
  63. data/spec/support/http_library_adapters.rb +4 -3
  64. data/spec/support/shared_example_groups/hook_into_http_library.rb +194 -12
  65. data/spec/support/shared_example_groups/request_hooks.rb +58 -0
  66. data/spec/support/shared_example_groups/version_checking.rb +5 -0
  67. data/spec/support/sinatra_app.rb +17 -9
  68. data/spec/support/vcr_stub_helpers.rb +17 -0
  69. data/spec/vcr/cassette/http_interaction_list_spec.rb +28 -29
  70. data/spec/vcr/cassette/migrator_spec.rb +6 -7
  71. data/spec/vcr/cassette_spec.rb +5 -5
  72. data/spec/vcr/configuration_spec.rb +51 -32
  73. data/spec/vcr/deprecations_spec.rb +0 -8
  74. data/spec/vcr/errors_spec.rb +129 -0
  75. data/spec/vcr/library_hooks/excon_spec.rb +21 -4
  76. data/spec/vcr/library_hooks/fakeweb_spec.rb +71 -3
  77. data/spec/vcr/library_hooks/faraday_spec.rb +45 -0
  78. data/spec/vcr/library_hooks/typhoeus_spec.rb +31 -1
  79. data/spec/vcr/library_hooks/webmock_spec.rb +26 -3
  80. data/spec/vcr/middleware/faraday_spec.rb +84 -1
  81. data/spec/vcr/request_ignorer_spec.rb +16 -0
  82. data/spec/vcr/request_matcher_registry_spec.rb +0 -26
  83. data/spec/vcr/structs_spec.rb +61 -1
  84. data/spec/vcr/test_frameworks/rspec_spec.rb +32 -0
  85. data/spec/vcr/util/hooks_spec.rb +73 -63
  86. data/spec/vcr_spec.rb +2 -2
  87. data/vcr.gemspec +5 -5
  88. metadata +51 -31
  89. data/features/configuration/hooks.feature +0 -270
  90. data/features/configuration/ignore_hosts.feature +0 -61
  91. data/features/configuration/ignore_localhost.feature +0 -97
@@ -3,9 +3,13 @@ Feature: Faraday middleware
3
3
  VCR provides middleware that can be used with Faraday. You can use this as
4
4
  an alternative to Faraday's built-in test adapter.
5
5
 
6
- To use VCR with Faraday, simply add the VCR middleware to the Faraday
7
- connection stack. The middleware should come before the Faraday
8
- HTTP adapter.
6
+ VCR will automatically insert this middleware in the Faraday stack
7
+ when you configure `hook_into :faraday`. However, if you want to control
8
+ where the middleware goes in the faraday stack, you can use it yourself.
9
+ The middleware should come before the Faraday HTTP adapter.
10
+
11
+ Note that when you use the middleware directly, you don't need to configure
12
+ `hook_into :faraday`.
9
13
 
10
14
  Scenario Outline: Use Faraday middleware
11
15
  Given a file named "faraday_example.rb" with:
@@ -54,6 +54,7 @@ Feature: :none
54
54
  When I run `ruby replay_recorded_response.rb`
55
55
  Then it should pass with "Response: Hello"
56
56
 
57
+ @exclude-jruby
57
58
  Scenario: New requests are prevented
58
59
  Given a file named "prevent_new_request.rb" with:
59
60
  """ruby
@@ -64,4 +65,4 @@ Feature: :none
64
65
  end
65
66
  """
66
67
  When I run `ruby prevent_new_request.rb`
67
- Then it should fail with "Real HTTP connections are disabled. Request: GET http://example.com:80/bar"
68
+ Then it should fail with "An HTTP request has been made that VCR does not know how to handle"
@@ -61,6 +61,7 @@ Feature: :once
61
61
  When I run `ruby replay_recorded_response.rb`
62
62
  Then it should pass with "Response: example.com response"
63
63
 
64
+ @exclude-jruby
64
65
  Scenario: New requests result in an error when the cassette file exists
65
66
  Given a file named "error_for_new_requests_when_cassette_exists.rb" with:
66
67
  """ruby
@@ -72,7 +73,7 @@ Feature: :once
72
73
  end
73
74
  """
74
75
  When I run `ruby error_for_new_requests_when_cassette_exists.rb`
75
- Then it should fail with "Real HTTP connections are disabled"
76
+ Then it should fail with "An HTTP request has been made that VCR does not know how to handle"
76
77
 
77
78
  Scenario: New requests get recorded when there is no cassette file
78
79
  Given a file named "record_new_requests.rb" with:
@@ -78,6 +78,6 @@ Feature: Matching on Body
78
78
  | c.hook_into :webmock | typhoeus |
79
79
  | c.hook_into :typhoeus | typhoeus |
80
80
  | c.hook_into :excon | excon |
81
- | | faraday (w/ net_http) |
82
- | | faraday (w/ typhoeus) |
81
+ | c.hook_into :faraday | faraday (w/ net_http) |
82
+ | c.hook_into :faraday | faraday (w/ typhoeus) |
83
83
 
@@ -92,8 +92,8 @@ Feature: Register and use a custom matcher
92
92
  | c.hook_into :webmock | typhoeus |
93
93
  | c.hook_into :typhoeus | typhoeus |
94
94
  | c.hook_into :excon | excon |
95
- | | faraday (w/ net_http) |
96
- | | faraday (w/ typhoeus) |
95
+ | c.hook_into :faraday | faraday (w/ net_http) |
96
+ | c.hook_into :faraday | faraday (w/ typhoeus) |
97
97
 
98
98
  Scenario: Register a named custom matcher
99
99
  And a file named "register_custom_matcher.rb" with:
@@ -76,6 +76,6 @@ Feature: Matching on Headers
76
76
  | c.hook_into :webmock | patron |
77
77
  | c.hook_into :webmock | em-http-request |
78
78
  | c.hook_into :excon | excon |
79
- | | faraday (w/ net_http) |
80
- | | faraday (w/ typhoeus) |
79
+ | c.hook_into :faraday | faraday (w/ net_http) |
80
+ | c.hook_into :faraday | faraday (w/ typhoeus) |
81
81
 
@@ -82,6 +82,6 @@ Feature: Matching on Host
82
82
  | c.hook_into :webmock | typhoeus |
83
83
  | c.hook_into :typhoeus | typhoeus |
84
84
  | c.hook_into :excon | excon |
85
- | | faraday (w/ net_http) |
86
- | | faraday (w/ typhoeus) |
85
+ | c.hook_into :faraday | faraday (w/ net_http) |
86
+ | c.hook_into :faraday | faraday (w/ typhoeus) |
87
87
 
@@ -76,6 +76,6 @@ Feature: Identical requests are replayed in sequence
76
76
  | c.hook_into :webmock | typhoeus |
77
77
  | c.hook_into :typhoeus | typhoeus |
78
78
  | c.hook_into :excon | excon |
79
- | | faraday (w/ net_http) |
80
- | | faraday (w/ typhoeus) |
79
+ | c.hook_into :faraday | faraday (w/ net_http) |
80
+ | c.hook_into :faraday | faraday (w/ typhoeus) |
81
81
 
@@ -83,6 +83,6 @@ Feature: Matching on Method
83
83
  | c.hook_into :webmock | typhoeus |
84
84
  | c.hook_into :typhoeus | typhoeus |
85
85
  | c.hook_into :excon | excon |
86
- | | faraday (w/ net_http) |
87
- | | faraday (w/ typhoeus) |
86
+ | c.hook_into :faraday | faraday (w/ net_http) |
87
+ | c.hook_into :faraday | faraday (w/ typhoeus) |
88
88
 
@@ -83,6 +83,6 @@ Feature: Matching on Path
83
83
  | c.hook_into :webmock | typhoeus |
84
84
  | c.hook_into :typhoeus | typhoeus |
85
85
  | c.hook_into :excon | excon |
86
- | | faraday (w/ net_http) |
87
- | | faraday (w/ typhoeus) |
86
+ | c.hook_into :faraday | faraday (w/ net_http) |
87
+ | c.hook_into :faraday | faraday (w/ typhoeus) |
88
88
 
@@ -12,6 +12,7 @@ Feature: Playback repeats
12
12
 
13
13
  :allow_playback_repeats => true
14
14
 
15
+ @exclude-jruby
15
16
  Scenario: Responses do not repeat by default
16
17
  Given a previously recorded cassette file "cassettes/example.yml" with:
17
18
  """
@@ -75,7 +76,7 @@ Feature: Playback repeats
75
76
  end
76
77
  """
77
78
  When I run `ruby playback_repeats.rb`
78
- Then it should fail with "Real HTTP connections are disabled"
79
+ Then it should fail with "An HTTP request has been made that VCR does not know how to handle"
79
80
  And the output should contain:
80
81
  """
81
82
  == With :allow_playback_repeats ==
@@ -81,6 +81,6 @@ Feature: Matching on URI
81
81
  | c.hook_into :webmock | typhoeus |
82
82
  | c.hook_into :typhoeus | typhoeus |
83
83
  | c.hook_into :excon | excon |
84
- | | faraday (w/ net_http) |
85
- | | faraday (w/ typhoeus) |
84
+ | c.hook_into :faraday | faraday (w/ net_http) |
85
+ | c.hook_into :faraday | faraday (w/ typhoeus) |
86
86
 
@@ -6,26 +6,35 @@ require 'ruby-debug' if !defined?(RUBY_ENGINE) && RUBY_VERSION != '1.9.3' && !EN
6
6
 
7
7
  require 'aruba/cucumber'
8
8
 
9
- cucumer_helpers_file = '../../features/support/vcr_cucumber_helpers'
10
- if RUBY_VERSION > '1.9.1'
11
- Before do
12
- set_env('RUBYOPT', "-I.:../../lib -r#{cucumer_helpers_file}")
9
+ additional_paths = []
10
+ Before('@rspec-1') do
11
+ additional_paths << File.join(%w[ .. .. vendor rspec-1 bin ])
12
+ end
13
+
14
+ Before do
15
+ load_paths, requires = ['../../lib'], []
16
+
17
+ if RUBY_VERSION < '1.9'
18
+ requires << "rubygems"
19
+ else
20
+ load_paths << '.'
13
21
  end
14
- elsif RUBY_PLATFORM == 'java'
15
- Before do
16
- set_env('RUBYOPT', "-I../../lib -rubygems -r#{cucumer_helpers_file}")
17
22
 
23
+ requires << '../../features/support/vcr_cucumber_helpers'
24
+ requires.map! { |r| "-r#{r}" }
25
+ set_env('RUBYOPT', "-I#{load_paths.join(':')} #{requires.join(' ')}")
26
+
27
+ if RUBY_PLATFORM == 'java'
18
28
  # ideas taken from: http://blog.headius.com/2010/03/jruby-startup-time-tips.html
19
29
  set_env('JRUBY_OPTS', '-X-C') # disable JIT since these processes are so short lived
20
30
  set_env('JAVA_OPTS', '-d32') # force jRuby to use client JVM for faster startup times
21
31
  end
22
- else
23
- Before do
24
- set_env('RUBYOPT', "-rubygems -r#{cucumer_helpers_file}")
32
+
33
+ if additional_paths.any?
34
+ existing_paths = ENV['PATH'].split(':')
35
+ set_env('PATH', (additional_paths + existing_paths).join(':'))
25
36
  end
26
- end
27
37
 
28
- Before do
29
38
  @aruba_timeout_seconds = RUBY_PLATFORM == 'java' ? 60 : 20
30
39
  end
31
40
 
@@ -23,6 +23,7 @@ Feature: Usage with Cucumber
23
23
  be used, or you can override specific options by passing a hash as the
24
24
  last argument to `#tag` or `#tags`.
25
25
 
26
+ @exclude-jruby
26
27
  Scenario: Record HTTP interactions in a scenario by tagging it
27
28
  Given a file named "lib/server.rb" with:
28
29
  """ruby
@@ -91,8 +92,10 @@ Feature: Usage with Cucumber
91
92
  When I run `cucumber WITH_SERVER=true features/vcr_example.feature`
92
93
  Then it should fail with "3 scenarios (2 failed, 1 passed)"
93
94
  And the output should contain each of the following:
94
- | Real HTTP connections are disabled. Request: GET http://localhost:7777/disallowed_1 |
95
- | Real HTTP connections are disabled. Request: GET http://localhost:7777/disallowed_2 |
95
+ | An HTTP request has been made that VCR does not know how to handle: |
96
+ | GET http://localhost:7777/disallowed_1 |
97
+ | An HTTP request has been made that VCR does not know how to handle: |
98
+ | GET http://localhost:7777/disallowed_2 |
96
99
  And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "body: Hello localhost_request_1"
97
100
  And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "body: Hello localhost_request_2"
98
101
  And the file "features/cassettes/nested_cassette.yml" should contain "body: Hello nested_cassette"
@@ -103,8 +106,10 @@ Feature: Usage with Cucumber
103
106
  When I run `cucumber features/vcr_example.feature`
104
107
  Then it should fail with "3 scenarios (2 failed, 1 passed)"
105
108
  And the output should contain each of the following:
106
- | Real HTTP connections are disabled. Request: GET http://localhost:7777/disallowed_1 |
107
- | Real HTTP connections are disabled. Request: GET http://localhost:7777/disallowed_2 |
109
+ | An HTTP request has been made that VCR does not know how to handle: |
110
+ | GET http://localhost:7777/disallowed_1 |
111
+ | An HTTP request has been made that VCR does not know how to handle: |
112
+ | GET http://localhost:7777/disallowed_2 |
108
113
  And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "body: Hello localhost_request_1"
109
114
  And the file "features/cassettes/cucumber_tags/localhost_request.yml" should contain "body: Hello localhost_request_2"
110
115
  And the file "features/cassettes/nested_cassette.yml" should contain "body: Hello nested_cassette"
@@ -1,4 +1,4 @@
1
- Feature: Usage with RSpec
1
+ Feature: Usage with RSpec macro
2
2
 
3
3
  VCR provides a macro that makes it easy to use a VCR cassette for an RSpec
4
4
  example group. To use it, simply add `config.extend VCR::RSpec::Macros`
@@ -66,8 +66,8 @@ Feature: Usage with RSpec
66
66
  require 'vcr'
67
67
 
68
68
  VCR.configure do |c|
69
- c.cassette_library_dir = 'spec/cassettes'
70
- c.hook_into :fakeweb
69
+ c.cassette_library_dir = 'spec/cassettes'
70
+ c.hook_into :fakeweb
71
71
  end
72
72
 
73
73
  RSpec.configure do |c|
@@ -79,11 +79,11 @@ Feature: Usage with RSpec
79
79
  And the file "spec/cassettes/VCR-RSpec_integration/without_an_explicit_cassette_name.yml" should contain "body: Hello"
80
80
  And the file "spec/cassettes/net_http_example.yml" should contain "body: Hello"
81
81
 
82
+ @rspec-1 @exclude-jruby
82
83
  Scenario: Use `use_vcr_cassette` macro with RSpec 1
83
84
  Given a file named "spec/spec_helper.rb" with:
84
85
  """ruby
85
86
  require 'sinatra_app'
86
- $LOAD_PATH.unshift(File.join(%w[ .. .. vendor rspec-1 lib ]))
87
87
 
88
88
  require 'spec'
89
89
  require 'spec/autorun'
@@ -91,15 +91,15 @@ Feature: Usage with RSpec
91
91
  require 'vcr'
92
92
 
93
93
  VCR.configure do |c|
94
- c.cassette_library_dir = 'spec/cassettes'
95
- c.hook_into :fakeweb
94
+ c.cassette_library_dir = 'spec/cassettes'
95
+ c.hook_into :fakeweb
96
96
  end
97
97
 
98
98
  Spec::Runner.configure do |c|
99
99
  c.extend VCR::RSpec::Macros
100
100
  end
101
101
  """
102
- When I run `ruby -Ispec spec/vcr_example_spec.rb`
102
+ When I run `spec spec/vcr_example_spec.rb`
103
103
  Then the output should contain "2 examples, 0 failures"
104
104
  And the file "spec/cassettes/VCR-RSpec_integration/without_an_explicit_cassette_name.yml" should contain "body: Hello"
105
105
  And the file "spec/cassettes/net_http_example.yml" should contain "body: Hello"
@@ -0,0 +1,90 @@
1
+ Feature: Usage with RSpec metadata
2
+
3
+ VCR provides easy integration with RSpec using metadata. To set this
4
+ up, call `configure_rspec_metadata!` in your `VCR.configure` block.
5
+
6
+ Once you've done that, you can have an example group or example use
7
+ VCR by passing `:vcr` as an additional argument after the description
8
+ string. It will use set the cassette name based on the example's
9
+ full description.
10
+
11
+ If you need to override the cassette name or options, you can pass a
12
+ hash (`:vcr => { ... }`).
13
+
14
+ Background:
15
+ Given a file named "spec/spec_helper.rb" with:
16
+ """ruby
17
+ require 'vcr'
18
+
19
+ VCR.configure do |c|
20
+ c.cassette_library_dir = 'spec/cassettes'
21
+ c.hook_into :fakeweb
22
+ c.configure_rspec_metadata!
23
+ end
24
+
25
+ RSpec.configure do |c|
26
+ # so we can use `:vcr` rather than `:vcr => true`;
27
+ # in RSpec 3 this will no longer be necessary.
28
+ c.treat_symbols_as_metadata_keys_with_true_values = true
29
+ end
30
+ """
31
+
32
+ Scenario: Use `:vcr` metadata
33
+ Given a file named "spec/vcr_example_spec.rb" with:
34
+ """
35
+ start_sinatra_app(:port => 7777) do
36
+ get('/') { "Hello" }
37
+ end
38
+
39
+ def make_http_request
40
+ Net::HTTP.get_response('localhost', '/', 7777).body
41
+ end
42
+
43
+ require 'spec_helper'
44
+
45
+ describe "VCR example group metadata", :vcr do
46
+ it 'records an http request' do
47
+ make_http_request.should == 'Hello'
48
+ end
49
+
50
+ it 'records another http request' do
51
+ make_http_request.should == 'Hello'
52
+ end
53
+
54
+ context 'in a nested example group' do
55
+ it 'records another one' do
56
+ make_http_request.should == 'Hello'
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "VCR example metadata" do
62
+ it 'records an http request', :vcr do
63
+ make_http_request.should == 'Hello'
64
+ end
65
+ end
66
+ """
67
+ When I run `rspec spec/vcr_example_spec.rb`
68
+ Then it should pass with "4 examples, 0 failures"
69
+ And the file "spec/cassettes/VCR_example_group_metadata/records_an_http_request.yml" should contain "body: Hello"
70
+ And the file "spec/cassettes/VCR_example_group_metadata/records_another_http_request.yml" should contain "body: Hello"
71
+ And the file "spec/cassettes/VCR_example_group_metadata/in_a_nested_example_group/records_another_one.yml" should contain "body: Hello"
72
+ And the file "spec/cassettes/VCR_example_metadata/records_an_http_request.yml" should contain "body: Hello"
73
+
74
+ Scenario: Pass a hash to set the cassette options
75
+ Given a file named "spec/vcr_example_spec.rb" with:
76
+ """
77
+ require 'spec_helper'
78
+
79
+ describe "Using an options hash", :vcr => { :cassette_name => "example", :record => :new_episodes } do
80
+ it 'uses the provided cassette name' do
81
+ VCR.current_cassette.name.should == "example"
82
+ end
83
+
84
+ it 'sets the given options' do
85
+ VCR.current_cassette.record_mode.should == :new_episodes
86
+ end
87
+ end
88
+ """
89
+ When I run `rspec spec/vcr_example_spec.rb`
90
+ Then it should pass with "2 examples, 0 failures"
data/lib/vcr.rb CHANGED
@@ -65,7 +65,7 @@ module VCR
65
65
 
66
66
  def http_interactions
67
67
  return current_cassette.http_interactions if current_cassette
68
- VCR::Cassette::HTTPInteractionList::NullList.new
68
+ VCR::Cassette::HTTPInteractionList::NullList
69
69
  end
70
70
 
71
71
  def real_http_connections_allowed?
data/lib/vcr/cassette.rb CHANGED
@@ -34,7 +34,7 @@ module VCR
34
34
  @exclusive = options[:exclusive]
35
35
  @serializer = VCR.cassette_serializers[options[:serialize_with]]
36
36
  @record_mode = :all if should_re_record?
37
- @parent_list = @exclusive ? HTTPInteractionList::NullList.new : VCR.http_interactions
37
+ @parent_list = @exclusive ? HTTPInteractionList::NullList : VCR.http_interactions
38
38
 
39
39
  raise_error_unless_valid_record_mode
40
40
  end
@@ -144,7 +144,7 @@ module VCR
144
144
  if should_remove_matching_existing_interactions?
145
145
  new_interaction_list = HTTPInteractionList.new(new_recorded_interactions, match_requests_on)
146
146
  old_interactions = old_interactions.reject do |i|
147
- new_interaction_list.has_interaction_matching?(i.request)
147
+ new_interaction_list.response_for(i.request)
148
148
  end
149
149
  end
150
150
 
@@ -170,7 +170,7 @@ module VCR
170
170
 
171
171
  def invoke_hook(type, interactions)
172
172
  interactions.delete_if do |i|
173
- VCR.configuration.invoke_hook(type, tag, i, self)
173
+ VCR.configuration.invoke_tagged_hook(type, tag, i, self)
174
174
  i.ignored?
175
175
  end
176
176
  end
@@ -1,16 +1,18 @@
1
1
  module VCR
2
2
  class Cassette
3
3
  class HTTPInteractionList
4
- class NullList
4
+ module NullList
5
+ extend self
5
6
  def response_for(*a); nil; end
6
- def has_interaction_matching?(*a); false; end
7
+ def has_used_interaction_matching?(*a); false; end
8
+ def remaining_unused_interaction_count(*a); 0; end
7
9
  end
8
10
 
9
11
  attr_reader :interactions, :request_matchers, :allow_playback_repeats, :parent_list
10
12
 
11
- def initialize(interactions, request_matchers, allow_playback_repeats = false, parent_list = NullList.new)
13
+ def initialize(interactions, request_matchers, allow_playback_repeats = false, parent_list = NullList)
12
14
  @interactions = interactions.dup
13
- @request_matchers = request_matchers
15
+ @request_matchers = request_matchers.map { |m| VCR.request_matchers[m] }
14
16
  @allow_playback_repeats = allow_playback_repeats
15
17
  @parent_list = parent_list
16
18
  @used_interactions = []
@@ -28,10 +30,12 @@ module VCR
28
30
  end
29
31
  end
30
32
 
31
- def has_interaction_matching?(request)
32
- !!matching_interaction_index_for(request) ||
33
- !!matching_used_interaction_for(request) ||
34
- @parent_list.has_interaction_matching?(request)
33
+ def has_used_interaction_matching?(request)
34
+ @used_interactions.any? { |i| interaction_matches_request?(request, i) }
35
+ end
36
+
37
+ def remaining_unused_interaction_count
38
+ @interactions.size
35
39
  end
36
40
 
37
41
  private
@@ -47,7 +51,7 @@ module VCR
47
51
 
48
52
  def interaction_matches_request?(request, interaction)
49
53
  @request_matchers.all? do |matcher|
50
- VCR.request_matchers[matcher].matches?(request, interaction.request)
54
+ matcher.matches?(request, interaction.request)
51
55
  end
52
56
  end
53
57
  end