Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improved the :all record mode so that it keeps previously recorded in…

…teractions that do not match the new recorded interactions.

Previously, all of the previously recorded interactions were deleted.
  • Loading branch information...
commit 4839e582593f113da77a038d7865d99e90c6f96c 1 parent 6d8bfce
@myronmarston authored
View
5 CHANGELOG.md
@@ -1,5 +1,10 @@
#Changelog
+## In git
+
+* Improved the `:all` record mode so that it keeps previously recorded interactions that do not match the
+ new recorded interactions. Previously, all of the previously recorded interactions were deleted.
+
## 1.1.2 (September 9, 2010)
* Fixed a minor bug with the WebMock integration: WebMock extends each `Net::HTTPResponse` with an extension
View
3  Gemfile
@@ -7,6 +7,9 @@ group :development do
gem 'patron', '~> 0.4.6'
gem 'em-http-request', '~> 0.2.7'
end
+
+ # I've got a fix that allows a stubbed object to be serialized properly. It's waiting to be merged in to rspec-mocks.
+ gem 'rspec-mocks', :git => 'git://github.com/myronmarston/rspec-mocks.git', :branch => 'fix_yaml_serialization'
end
# Additional gems that are useful, but not required for development.
View
13 Gemfile.lock
@@ -1,3 +1,12 @@
+GIT
+ remote: git://github.com/myronmarston/rspec-mocks.git
+ revision: ca6a7ce31a79d0368972285fa6512a41a85c294c
+ branch: fix_yaml_serialization
+ specs:
+ rspec-mocks (2.0.0.beta.22)
+ rspec-core (= 2.0.0.beta.22)
+ rspec-expectations (= 2.0.0.beta.22)
+
PATH
remote: .
specs:
@@ -60,9 +69,6 @@ GEM
rspec-core (2.0.0.beta.22)
rspec-expectations (2.0.0.beta.22)
diff-lcs (>= 1.1.2)
- rspec-mocks (2.0.0.beta.22)
- rspec-core (= 2.0.0.beta.22)
- rspec-expectations (= 2.0.0.beta.22)
ruby-debug (0.10.3)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.3.0)
@@ -106,6 +112,7 @@ DEPENDENCIES
rake (~> 0.8.7)
rcov
rspec (~> 2.0.0.beta.22)
+ rspec-mocks!
ruby-debug
ruby-debug-base19 (= 0.11.23)
ruby-debug19
View
62 features/fixtures/vcr_cassettes/1.9.1/record_all.yml
@@ -0,0 +1,62 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ :request: !ruby/struct:VCR::Request
+ :method: :get
+ :uri: http://example.com:80/a
+ :body:
+ :headers:
+ :response: !ruby/struct:VCR::Response
+ :status: !ruby/struct:VCR::ResponseStatus
+ :code: 200
+ :message: OK
+ :headers:
+ etag:
+ - "\"24ec5-1b6-4059a80bfd280\""
+ :body: a response 1
+ :http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ :request: !ruby/struct:VCR::Request
+ :method: :get
+ :uri: http://example.com:80/a
+ :body:
+ :headers:
+ :response: !ruby/struct:VCR::Response
+ :status: !ruby/struct:VCR::ResponseStatus
+ :code: 200
+ :message: OK
+ :headers:
+ etag:
+ - "\"24ec5-1b6-4059a80bfd280\""
+ :body: a response 2
+ :http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ :request: !ruby/struct:VCR::Request
+ :method: :get
+ :uri: http://example.com:80/b
+ :body:
+ :headers:
+ :response: !ruby/struct:VCR::Response
+ :status: !ruby/struct:VCR::ResponseStatus
+ :code: 200
+ :message: OK
+ :headers:
+ etag:
+ - "\"24ec5-1b6-4059a80bfd280\""
+ :body: b response 1
+ :http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ :request: !ruby/struct:VCR::Request
+ :method: :get
+ :uri: http://example.com:80/b
+ :body:
+ :headers:
+ :response: !ruby/struct:VCR::Response
+ :status: !ruby/struct:VCR::ResponseStatus
+ :code: 200
+ :message: OK
+ :headers:
+ etag:
+ - "\"24ec5-1b6-4059a80bfd280\""
+ :body: b response 2
+ :http_version: "1.1"
+
View
61 features/fixtures/vcr_cassettes/not_1.9.1/record_all.yml
@@ -0,0 +1,61 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri: http://example.com:80/a
+ body:
+ headers:
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ etag:
+ - "\"24ec5-1b6-4059a80bfd280\""
+ body: a response 1
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri: http://example.com:80/a
+ body:
+ headers:
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ etag:
+ - "\"24ec5-1b6-4059a80bfd280\""
+ body: a response 2
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri: http://example.com:80/b
+ body:
+ headers:
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ etag:
+ - "\"24ec5-1b6-4059a80bfd280\""
+ body: b response 1
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri: http://example.com:80/b
+ body:
+ headers:
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ etag:
+ - "\"24ec5-1b6-4059a80bfd280\""
+ body: b response 2
+ http_version: "1.1"
View
15 features/record_response.feature
@@ -37,11 +37,24 @@ Feature: Record response
Then the "cucumber_tags/record_cassette2" library file should have a response for "http://example.com/before_nested" that matches /The requested URL \/before_nested was not found/
And the "cucumber_tags/record_cassette2" library file should have a response for "http://example.com/after_nested" that matches /The requested URL \/after_nested was not found/
- Scenario: Make an HTTP request in a cassette with record mode set to :all
+ Scenario: Make an HTTP request in a cassette with record mode set to :all when the cassette does not already exist
Given we do not have a "temp/record_all_cassette" cassette
When I make an HTTP get request to "http://example.com/" within the "temp/record_all_cassette" cassette using cassette options: { :record => :all }
Then the "temp/record_all_cassette" library file should have a response for "http://example.com/" that matches /You have reached this web page by typing.*example\.com/
+ @copy_record_all_to_temp
+ Scenario: Make an HTTP request in a cassette with record mode set to :all when the cassette already exists
+ Given the "temp/record_all" library file has a response for "http://example.com/a" that matches /a response 1/
+ And the "temp/record_all" library file has a response for "http://example.com/a" that matches /a response 2/
+ And the "temp/record_all" library file has a response for "http://example.com/b" that matches /b response 1/
+ And the "temp/record_all" library file has a response for "http://example.com/b" that matches /b response 2/
+ When I make an HTTP get request to "http://example.com/a" within the "temp/record_all" cassette using cassette options: { :record => :all }
+ Then the "temp/record_all" library file should have a response for "http://example.com/a" that matches /The requested URL \/a was not found/
+ And the "temp/record_all" library file should not have a response for "http://example.com/a" that matches /a response 1/
+ And the "temp/record_all" library file should not have a response for "http://example.com/a" that matches /a response 2/
+ And the "temp/record_all" library file should have a response for "http://example.com/b" that matches /b response 1/
+ And the "temp/record_all" library file should have a response for "http://example.com/b" that matches /b response 2/
+
Scenario: Make an HTTP request in a cassette with record mode set to :none
Given we do not have a "temp/record_none_cassette" cassette
When I make an HTTP get request to "http://example.com/" within the "temp/record_none_cassette" cassette using cassette options: { :record => :none }
View
5 features/step_definitions/vcr_steps.rb
@@ -178,9 +178,10 @@ def capture_response(url)
end
end
-Then /^the "([^\"]*)" library file should have a response for "([^\"]*)" that matches \/(.+)\/$/ do |cassette_name, url, regex_str|
+Then /^the "([^\"]*)" library file (should(?: not)?) have a response for "([^\"]*)" that matches \/(.+)\/$/ do |cassette_name, expectation, url, regex_str|
+ expectation = expectation.gsub(' ', '_')
interactions = recorded_interactions_for(cassette_name)
- interactions.should have_expected_response(regex_str, :url => url)
+ interactions.send(expectation, have_expected_response(regex_str, :url => url))
end
Then /^the "([^\"]*)" library file should have exactly (\d+) response$/ do |cassette_name, response_count|
View
12 features/support/env.rb
@@ -66,11 +66,13 @@ class << self
FileUtils.rm_rf(temp_dir) if File.exist?(temp_dir)
end
-Before('@copy_not_the_real_response_to_temp') do
- orig_file = File.join(VCR::Config.cassette_library_dir, 'not_the_real_response.yml')
- temp_file = File.join(VCR::Config.cassette_library_dir, 'temp', 'not_the_real_response.yml')
- FileUtils.mkdir_p(File.join(VCR::Config.cassette_library_dir, 'temp'))
- FileUtils.cp orig_file, temp_file
+%w[not_the_real_response record_all].each do |cassette|
+ Before("@copy_#{cassette}_to_temp") do
+ orig_file = File.join(VCR::Config.cassette_library_dir, "#{cassette}.yml")
+ temp_file = File.join(VCR::Config.cassette_library_dir, 'temp', "#{cassette}.yml")
+ FileUtils.mkdir_p(File.join(VCR::Config.cassette_library_dir, 'temp'))
+ FileUtils.cp orig_file, temp_file
+ end
end
Before('@create_replay_localhost_cassette') do
View
55 lib/vcr/cassette.rb
@@ -1,6 +1,7 @@
require 'fileutils'
require 'yaml'
require 'erb'
+require 'set'
module VCR
class Cassette
@@ -39,7 +40,11 @@ def recorded_interactions
end
def record_http_interaction(interaction)
- recorded_interactions << interaction
+ new_recorded_interactions << interaction
+ end
+
+ def new_recorded_interactions
+ @new_recorded_interactions ||= []
end
def file
@@ -58,12 +63,16 @@ def raise_error_unless_valid_record_mode(record_mode)
end
end
- def new_recorded_interactions
- recorded_interactions - @original_recorded_interactions
+ def should_allow_http_connections?
+ record_mode != :none
end
- def should_allow_http_connections?
- [:new_episodes, :all].include?(record_mode)
+ def should_stub_requests?
+ record_mode != :all
+ end
+
+ def should_remove_matching_existing_interactions?
+ record_mode == :all
end
def set_http_connections_allowed
@@ -77,11 +86,9 @@ def restore_http_connections_allowed
def load_recorded_interactions
VCR.http_stubbing_adapter.create_stubs_checkpoint(name)
- @original_recorded_interactions = []
- return if record_mode == :all
- if file
- @original_recorded_interactions = begin
+ if file && File.exist?(file)
+ begin
interactions = YAML.load(raw_yaml_content)
if VCR.http_stubbing_adapter.ignore_localhost?
@@ -90,16 +97,16 @@ def load_recorded_interactions
end
end
- interactions
+ recorded_interactions.replace(interactions)
rescue TypeError
raise unless raw_yaml_content =~ /VCR::RecordedResponse/
raise "The VCR cassette #{sanitized_name}.yml uses an old format that is now deprecated. VCR provides a rake task to migrate your old cassettes to the new format. See http://github.com/myronmarston/vcr/blob/master/CHANGELOG.md for more info."
- end if File.exist?(file)
-
- recorded_interactions.replace(@original_recorded_interactions)
+ end
end
- VCR.http_stubbing_adapter.stub_requests(recorded_interactions, match_requests_on)
+ if should_stub_requests?
+ VCR.http_stubbing_adapter.stub_requests(recorded_interactions, match_requests_on)
+ end
end
@@struct_cache = Hash.new do |hash, attributes|
@@ -131,11 +138,29 @@ def raw_yaml_content
end
end
+ def merged_interactions
+ old_interactions = recorded_interactions
+
+ if should_remove_matching_existing_interactions?
+ match_attributes = match_requests_on
+
+ new_request_matchers = Set.new new_recorded_interactions.map do |i|
+ i.request.matcher(match_attributes)
+ end
+
+ old_interactions = old_interactions.reject do |i|
+ new_request_matchers.include?(i.request.matcher(match_attributes))
+ end
+ end
+
+ old_interactions + new_recorded_interactions
+ end
+
def write_recorded_interactions_to_disk
if VCR::Config.cassette_library_dir && new_recorded_interactions.size > 0
directory = File.dirname(file)
FileUtils.mkdir_p directory unless File.exist?(directory)
- File.open(file, 'w') { |f| f.write recorded_interactions.to_yaml }
+ File.open(file, 'w') { |f| f.write merged_interactions.to_yaml }
end
end
end
View
181 spec/cassette_spec.rb
@@ -27,11 +27,11 @@
end
describe '#record_http_interaction' do
- it 'adds the interaction to #recorded_interactions' do
+ it 'adds the interaction to #new_recorded_interactions' do
cassette = VCR::Cassette.new(:test_cassette)
- cassette.recorded_interactions.should == []
+ cassette.new_recorded_interactions.should == []
cassette.record_http_interaction(:the_interaction)
- cassette.recorded_interactions.should == [:the_interaction]
+ cassette.new_recorded_interactions.should == [:the_interaction]
end
end
@@ -127,7 +127,7 @@ def cassette_body(name, options = {})
VCR::Cassette::VALID_RECORD_MODES.each do |record_mode|
http_connections_allowed = (record_mode != :none)
- load_interactions = (record_mode != :all)
+ stub_requests = (record_mode != :all)
context "when VCR::Config.default_cassette_options[:record] is :#{record_mode}" do
before(:each) { VCR::Config.default_cassette_options = { :record => record_mode } }
@@ -144,41 +144,40 @@ def cassette_body(name, options = {})
VCR::Cassette.new(:name, :record => record_mode)
end
- if load_interactions
+ [true, false].each do |ignore_localhost|
+ expected_uri_hosts = %w(example.com)
+ expected_uri_hosts += VCR::LOCALHOST_ALIASES unless ignore_localhost
- [true, false].each do |ignore_localhost|
- expected_uri_hosts = %w(example.com)
- expected_uri_hosts += VCR::LOCALHOST_ALIASES unless ignore_localhost
-
- it "#{ ignore_localhost ? 'does not load' : 'loads' } localhost interactions from the cassette file when http_stubbing_adapter.ignore_localhost is set to #{ignore_localhost}" do
- VCR.http_stubbing_adapter.stub!(:ignore_localhost?).and_return(ignore_localhost)
- VCR::Config.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec")
- cassette = VCR::Cassette.new('with_localhost_requests', :record => record_mode)
- cassette.recorded_interactions.map { |i| URI.parse(i.uri).host }.should =~ expected_uri_hosts
- end
+ it "#{ ignore_localhost ? 'does not load' : 'loads' } localhost interactions from the cassette file when http_stubbing_adapter.ignore_localhost is set to #{ignore_localhost}" do
+ VCR.http_stubbing_adapter.stub!(:ignore_localhost?).and_return(ignore_localhost)
+ VCR::Config.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec")
+ cassette = VCR::Cassette.new('with_localhost_requests', :record => record_mode)
+ cassette.recorded_interactions.map { |i| URI.parse(i.uri).host }.should =~ expected_uri_hosts
end
+ end
- it "loads the recorded interactions from the library yml file" do
- VCR::Config.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec")
- cassette = VCR::Cassette.new('example', :record => record_mode)
+ it "loads the recorded interactions from the library yml file" do
+ VCR::Config.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec")
+ cassette = VCR::Cassette.new('example', :record => record_mode)
- cassette.should have(3).recorded_interactions
+ cassette.should have(3).recorded_interactions
- i1, i2, i3 = *cassette.recorded_interactions
+ i1, i2, i3 = *cassette.recorded_interactions
- i1.request.method.should == :get
- i1.request.uri.should == 'http://example.com:80/'
- i1.response.body.should =~ /You have reached this web page by typing.+example\.com/
+ i1.request.method.should == :get
+ i1.request.uri.should == 'http://example.com:80/'
+ i1.response.body.should =~ /You have reached this web page by typing.+example\.com/
- i2.request.method.should == :get
- i2.request.uri.should == 'http://example.com:80/foo'
- i2.response.body.should =~ /foo was not found on this server/
+ i2.request.method.should == :get
+ i2.request.uri.should == 'http://example.com:80/foo'
+ i2.response.body.should =~ /foo was not found on this server/
- i3.request.method.should == :get
- i3.request.uri.should == 'http://example.com:80/'
- i3.response.body.should =~ /Another example\.com response/
- end
+ i3.request.method.should == :get
+ i3.request.uri.should == 'http://example.com:80/'
+ i3.response.body.should =~ /Another example\.com response/
+ end
+ if stub_requests
it "stubs the recorded requests with the http stubbing adapter" do
VCR::Config.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec")
VCR.http_stubbing_adapter.should_receive(:stub_requests).with([an_instance_of(VCR::HTTPInteraction)]*3, anything)
@@ -190,21 +189,12 @@ def cassette_body(name, options = {})
VCR.http_stubbing_adapter.should_receive(:stub_requests).with(anything, [:body, :headers])
cassette = VCR::Cassette.new('example', :record => record_mode, :match_requests_on => [:body, :headers])
end
-
else
-
it "does not stub the recorded requests with the http stubbing adapter" do
VCR::Config.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec")
VCR.http_stubbing_adapter.should_not_receive(:stub_requests)
cassette = VCR::Cassette.new('example', :record => record_mode)
end
-
- it "does not load the recorded interactions from the library yml file" do
- VCR::Config.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec")
- cassette = VCR::Cassette.new('example', :record => record_mode)
- cassette.should have(0).recorded_interactions
- end
-
end
end
end
@@ -230,7 +220,7 @@ def cassette_body(name, options = {})
]
cassette = VCR::Cassette.new(:eject_test)
- cassette.stub!(:recorded_interactions).and_return(recorded_interactions)
+ cassette.stub!(:new_recorded_interactions).and_return(recorded_interactions)
lambda { cassette.eject }.should change { File.exist?(cassette.file) }.from(false).to(true)
saved_recorded_interactions = File.open(cassette.file, "r") { |f| YAML.load(f.read) }
@@ -240,41 +230,98 @@ def cassette_body(name, options = {})
it "writes the recorded interactions to a subdirectory if the cassette name includes a directory" do
recorded_interactions = [VCR::HTTPInteraction.new(:the_request, :the_response)]
cassette = VCR::Cassette.new('subdirectory/test_cassette')
- cassette.stub!(:recorded_interactions).and_return(recorded_interactions)
+ cassette.stub!(:new_recorded_interactions).and_return(recorded_interactions)
lambda { cassette.eject }.should change { File.exist?(cassette.file) }.from(false).to(true)
saved_recorded_interactions = File.open(cassette.file, "r") { |f| YAML.load(f.read) }
saved_recorded_interactions.should == recorded_interactions
end
- it "writes both old and new recorded interactions to disk" do
- file = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec/example.yml")
- FileUtils.cp file, File.join(@temp_dir, 'previously_recorded_interactions.yml')
- cassette = VCR::Cassette.new('previously_recorded_interactions')
- cassette.should have(3).recorded_interactions
- new_recorded_interaction = VCR::HTTPInteraction.new(:the_request, :the_response)
- cassette.record_http_interaction(new_recorded_interaction)
- cassette.eject
- saved_recorded_interactions = File.open(cassette.file, "r") { |f| YAML.load(f.read) }
- saved_recorded_interactions.should have(4).recorded_interactions
- saved_recorded_interactions.last.should == new_recorded_interaction
- end
- end
+ [:all, :none, :new_episodes].each do |record_mode|
+ context "for a :record => :#{record_mode} cassette with previously recorded interactions" do
+ temp_dir File.expand_path(File.dirname(__FILE__) + "/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec/temp"), :assign_to_cassette_library_dir => true
- describe '#eject for a cassette with previously recorded interactions' do
- it "restore the stubs checkpoint on the http stubbing adapter" do
- VCR::Config.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec")
- cassette = VCR::Cassette.new('example', :record => :none)
- VCR.http_stubbing_adapter.should_receive(:restore_stubs_checkpoint).with('example')
- cassette.eject
- end
+ subject { VCR::Cassette.new('example', :record => record_mode, :match_requests_on => [:uri]) }
+
+ before(:each) do
+ base_dir = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec")
+ FileUtils.cp(base_dir + "/example.yml", base_dir + "/temp/example.yml")
+ end
- it "does not re-write to disk the previously recorded interactions if there are no new ones" do
- VCR::Config.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{YAML_SERIALIZATION_VERSION}/cassette_spec")
- yaml_file = File.join(VCR::Config.cassette_library_dir, 'example.yml')
- cassette = VCR::Cassette.new('example', :record => :none)
- File.should_not_receive(:open).with(cassette.file, 'w')
- lambda { cassette.eject }.should_not change { File.mtime(yaml_file) }
+ it "restore the stubs checkpoint on the http stubbing adapter" do
+ VCR.http_stubbing_adapter.should_receive(:restore_stubs_checkpoint).with('example')
+ subject.eject
+ end
+
+ it "does not re-write to disk the previously recorded interactions if there are no new ones" do
+ yaml_file = subject.file
+ File.should_not_receive(:open).with(subject.file, 'w')
+ lambda { subject.eject }.should_not change { File.mtime(yaml_file) }
+ end
+
+ context 'when some new interactions have been recorded' do
+ let(:new_interaction_1) { VCR::HTTPInteraction.new(VCR::Request.new, :response_1) }
+ let(:new_interaction_2) { VCR::HTTPInteraction.new(VCR::Request.new, :response_2) }
+ let(:new_interaction_3) { VCR::HTTPInteraction.new(VCR::Request.new, :response_3) }
+
+ let(:old_interaction_1) { subject.recorded_interactions[0] }
+ let(:old_interaction_2) { subject.recorded_interactions[1] }
+ let(:old_interaction_3) { subject.recorded_interactions[2] }
+
+ let(:saved_recorded_interactions) { YAML.load(File.read(subject.file)) }
+
+ before(:each) do
+ old_interaction_1.request.stub(:matcher => :matcher_c)
+ old_interaction_2.request.stub(:matcher => :matcher_d)
+ old_interaction_3.request.stub(:matcher => :matcher_c)
+
+ new_interaction_1.request.stub(:matcher => :matcher_a)
+ new_interaction_2.request.stub(:matcher => :matcher_b)
+ new_interaction_3.request.stub(:matcher => :matcher_c)
+
+ [new_interaction_1, new_interaction_2, new_interaction_3].each do |i|
+ subject.record_http_interaction(i)
+ end
+ end
+
+ if record_mode == :all
+ it 'removes the old interactions that match new requests, and saves the new interactions follow the old ones' do
+ subject.eject
+
+ saved_recorded_interactions.should == [
+ old_interaction_2,
+ new_interaction_1,
+ new_interaction_2,
+ new_interaction_3
+ ]
+ end
+
+ it "matches old requests to new ones using the cassette's match attributes" do
+ [
+ old_interaction_1, old_interaction_2, old_interaction_3,
+ new_interaction_1, new_interaction_2, new_interaction_3
+ ].each do |i|
+ i.request.should_receive(:matcher).with(subject.match_requests_on).and_return(:the_matcher)
+ end
+
+ subject.eject
+ end
+ else
+ it 'saves the old interactions followed by the new ones to disk' do
+ subject.eject
+
+ saved_recorded_interactions.should == [
+ old_interaction_1,
+ old_interaction_2,
+ old_interaction_3,
+ new_interaction_1,
+ new_interaction_2,
+ new_interaction_3
+ ]
+ end
+ end
+ end
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.