From b842963306746e05b13b2b8064f356e997f18fe1 Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Sat, 21 Sep 2013 17:08:15 -0700 Subject: [PATCH 01/11] Update rspec. --- Gemfile.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 71cf5508..128adc0c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,7 +38,7 @@ GEM debugger-linecache (1.1.2) debugger-ruby_core_source (>= 1.1.1) debugger-ruby_core_source (1.2.0) - diff-lcs (1.2.1) + diff-lcs (1.2.4) em-http-request (1.0.3) addressable (>= 2.2.3) cookiejar @@ -106,15 +106,15 @@ GEM rest-client (>= 1.6.1) rest-client (1.6.7) mime-types (>= 1.16) - rspec (2.13.0) - rspec-core (~> 2.13.0) - rspec-expectations (~> 2.13.0) - rspec-mocks (~> 2.13.0) - rspec-core (2.13.0) - rspec-expectations (2.13.0) + rspec (2.14.1) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + rspec-core (2.14.5) + rspec-expectations (2.14.2) diff-lcs (>= 1.1.3, < 2.0) rspec-instafail (0.2.4) - rspec-mocks (2.13.0) + rspec-mocks (2.14.3) ruby-debug (0.10.4) columnize (>= 0.1) ruby-debug-base (~> 0.10.4.0) From 01ed0a4d53062f0c33d9e1c307f2702d9519cb19 Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Sat, 21 Sep 2013 17:14:17 -0700 Subject: [PATCH 02/11] Convert to latest RSpec syntax using transept. --- spec/support/shared_example_groups/excon.rb | 4 +- .../hook_into_http_library.rb | 22 ++--- .../shared_example_groups/request_hooks.rb | 2 +- spec/support/vcr_stub_helpers.rb | 2 +- .../cassette/http_interaction_list_spec.rb | 20 ++-- spec/vcr/cassette/migrator_spec.rb | 2 +- spec/vcr/cassette/persisters_spec.rb | 4 +- spec/vcr/cassette/serializers_spec.rb | 4 +- spec/vcr/cassette_spec.rb | 92 +++++++++---------- spec/vcr/configuration_spec.rb | 46 +++++----- spec/vcr/deprecations_spec.rb | 18 ++-- spec/vcr/errors_spec.rb | 12 +-- spec/vcr/library_hooks/excon_spec.rb | 8 +- spec/vcr/library_hooks/fakeweb_spec.rb | 16 ++-- spec/vcr/library_hooks/faraday_spec.rb | 2 +- spec/vcr/library_hooks/typhoeus_0.4_spec.rb | 6 +- spec/vcr/library_hooks/typhoeus_spec.rb | 2 +- spec/vcr/library_hooks/webmock_spec.rb | 6 +- spec/vcr/middleware/faraday_spec.rb | 6 +- spec/vcr/middleware/rack_spec.rb | 4 +- spec/vcr/request_matcher_registry_spec.rb | 8 +- spec/vcr/structs_spec.rb | 38 ++++---- spec/vcr/test_frameworks/cucumber_spec.rb | 8 +- spec/vcr/util/hooks_spec.rb | 4 +- spec/vcr/util/internet_connection_spec.rb | 6 +- spec/vcr/util/version_checker_spec.rb | 8 +- spec/vcr_spec.rb | 32 +++---- 27 files changed, 191 insertions(+), 191 deletions(-) diff --git a/spec/support/shared_example_groups/excon.rb b/spec/support/shared_example_groups/excon.rb index 9c321fb2..74f631f4 100644 --- a/spec/support/shared_example_groups/excon.rb +++ b/spec/support/shared_example_groups/excon.rb @@ -1,7 +1,7 @@ shared_examples "Excon streaming" do context "when Excon's streaming API is used" do it 'properly records and plays back the response' do - VCR.stub(:real_http_connections_allowed? => true) + allow(VCR).to receive(:real_http_connections_allowed?).and_return(true) recorded, played_back = [1, 2].map do chunks = [] @@ -19,7 +19,7 @@ end it 'properly records and plays back the response for unexpected status' do - VCR.stub(:real_http_connections_allowed? => true) + allow(VCR).to receive(:real_http_connections_allowed?).and_return(true) recorded, played_back = [1, 2].map do chunks = [] diff --git a/spec/support/shared_example_groups/hook_into_http_library.rb b/spec/support/shared_example_groups/hook_into_http_library.rb index 2d831e9c..c950b714 100644 --- a/spec/support/shared_example_groups/hook_into_http_library.rb +++ b/spec/support/shared_example_groups/hook_into_http_library.rb @@ -109,7 +109,7 @@ def self.test_playback(description, url) call_count = 0 [:has_interaction_matching?, :response_for].each do |method_name| orig_meth = VCR.http_interactions.method(method_name) - VCR.http_interactions.stub(method_name) do |*args| + allow(VCR.http_interactions).to receive(method_name) do |*args| call_count += 1 orig_meth.call(*args) end @@ -135,7 +135,7 @@ def self.test_playback(description, url) VCR.insert_cassette('example') disable_real_connections - VCR.should_receive(:record_http_interaction) do |interaction| + expect(VCR).to receive(:record_http_interaction) do |interaction| expect(interaction.request.uri).to eq(request_url) end @@ -173,7 +173,7 @@ def self.test_playback(description, url) it 'does not record requests that are directly stubbed' do expect(VCR).to respond_to(:record_http_interaction) - VCR.should_not_receive(:record_http_interaction) + expect(VCR).not_to receive(:record_http_interaction) VCR.use_cassette("temp") do directly_stub_request(:get, request_url, "stubbed response") @@ -220,7 +220,7 @@ def self.test_playback(description, url) VCR.use_cassette('new_cassette', &request) end - VCR.should_receive(:record_http_interaction) do + expect(VCR).to receive(:record_http_interaction) do expect(VCR.current_cassette.name).to eq('new_cassette') end @@ -370,7 +370,7 @@ def self.test_playback(description, url) specify 'the after_http_request hook can be used to eject a cassette after the request is recorded' do VCR.configuration.after_http_request { |request| VCR.eject_cassette } - VCR.should_receive(:record_http_interaction) do |interaction| + expect(VCR).to receive(:record_http_interaction) do |interaction| expect(VCR.current_cassette).to be(inserted_cassette) end @@ -408,7 +408,7 @@ def make_request(disabled = false) end describe '.stub_requests using specific match_attributes' do - before(:each) { VCR.stub(:real_http_connections_allowed? => false) } + before(:each) { allow(VCR).to receive(:real_http_connections_allowed?).and_return(false) } let(:interactions) { interactions_from('match_requests_on.yml') } let(:normalized_interactions) do @@ -486,14 +486,14 @@ def self.test_real_http_request(http_allowed, *other) describe 'recording new http requests' do let(:recorded_interaction) do interaction = nil - VCR.should_receive(:record_http_interaction) { |i| interaction = i } + expect(VCR).to receive(:record_http_interaction) { |i| interaction = i } make_http_request(:post, url, "the body", { 'X-Http-Foo' => 'bar' }) interaction end it 'does not record the request if the hook is disabled' do VCR.library_hooks.exclusively_enabled :something_else do - VCR.should_not_receive(:record_http_interaction) + expect(VCR).not_to receive(:record_http_interaction) make_http_request(:get, url) end end unless other.include?(:not_disableable) @@ -534,7 +534,7 @@ def self.test_real_http_request(http_allowed, *other) end else it 'does not allow real HTTP requests or record them' do - VCR.should_receive(:record_http_interaction).never + expect(VCR).to receive(:record_http_interaction).never expect { make_http_request(:get, url) }.to raise_error(NET_CONNECT_NOT_ALLOWED_ERROR) end end @@ -542,7 +542,7 @@ def self.test_real_http_request(http_allowed, *other) [true, false].each do |http_allowed| context "when VCR.real_http_connections_allowed? is returning #{http_allowed}" do - before(:each) { VCR.stub(:real_http_connections_allowed? => http_allowed) } + before(:each) { allow(VCR).to receive(:real_http_connections_allowed?).and_return(http_allowed) } test_real_http_request(http_allowed, *other) @@ -573,7 +573,7 @@ def self.test_real_http_request(http_allowed, *other) end it 'gets the stubbed responses when requests are made to http://example.com/foo, and does not record them' do - VCR.should_receive(:record_http_interaction).never + expect(VCR).to receive(:record_http_interaction).never expect(get_body_string(make_http_request(:get, 'http://example.com/foo'))).to match(/example\.com get response \d with path=foo/) end diff --git a/spec/support/shared_example_groups/request_hooks.rb b/spec/support/shared_example_groups/request_hooks.rb index ecdb2959..a1797fdd 100644 --- a/spec/support/shared_example_groups/request_hooks.rb +++ b/spec/support/shared_example_groups/request_hooks.rb @@ -30,7 +30,7 @@ def assert_expected_response(response) specify "the #{hook} hook is not called if the library hook is disabled" do expect(VCR.library_hooks).to respond_to(:disabled?) - VCR.library_hooks.stub(:disabled? => true) + allow(VCR.library_hooks).to receive(:disabled?).and_return(true) hook_called = false VCR.configuration.send(hook) { |r| hook_called = true } diff --git a/spec/support/vcr_stub_helpers.rb b/spec/support/vcr_stub_helpers.rb index 8e710ab5..4510c09a 100644 --- a/spec/support/vcr_stub_helpers.rb +++ b/spec/support/vcr_stub_helpers.rb @@ -5,7 +5,7 @@ def interactions_from(file) end def stub_requests(*args) - VCR.stub(:http_interactions => VCR::Cassette::HTTPInteractionList.new(*args)) + allow(VCR).to receive(:http_interactions).and_return(VCR::Cassette::HTTPInteractionList.new(*args)) end def http_interaction(url, response_body = "FOO!", status_code = 200) diff --git a/spec/vcr/cassette/http_interaction_list_spec.rb b/spec/vcr/cassette/http_interaction_list_spec.rb index 8f9fe27e..5d6a61ee 100644 --- a/spec/vcr/cassette/http_interaction_list_spec.rb +++ b/spec/vcr/cassette/http_interaction_list_spec.rb @@ -11,8 +11,8 @@ class Cassette end before(:each) do - VCR.stub(:request_matchers => VCR::RequestMatcherRegistry.new) - VCR.stub_chain(:configuration, :debug_logger).and_return(stub.as_null_object) + allow(VCR).to receive(:request_matchers).and_return(VCR::RequestMatcherRegistry.new) + VCR.stub_chain(:configuration, :debug_logger).and_return(double.as_null_object) end def request_with(values) @@ -102,7 +102,7 @@ def interaction(body, request_values) describe "has_interaction_matching?" do it 'returns false when the list is empty' do - expect(HTTPInteractionList.new([], [:method])).not_to have_interaction_matching(stub) + expect(HTTPInteractionList.new([], [:method])).not_to have_interaction_matching(double) end it 'returns false when there is no matching interaction' do @@ -136,10 +136,10 @@ def interaction(body, request_values) end it "delegates to the parent list when it can't find a matching interaction" do - parent_list = mock(:has_interaction_matching? => true) - expect(HTTPInteractionList.new( [], [:method], false, parent_list)).to have_interaction_matching(stub) - parent_list = mock(:has_interaction_matching? => false) - expect(HTTPInteractionList.new( [], [:method], false, parent_list)).not_to have_interaction_matching(stub) + parent_list = double(:has_interaction_matching? => true) + expect(HTTPInteractionList.new( [], [:method], false, parent_list)).to have_interaction_matching(double) + parent_list = double(:has_interaction_matching? => false) + expect(HTTPInteractionList.new( [], [:method], false, parent_list)).not_to have_interaction_matching(double) end context 'when allow_playback_repeats is set to true' do @@ -173,7 +173,7 @@ def interaction(body, request_values) describe "#response_for" do it 'returns nil when the list is empty' do - expect(HTTPInteractionList.new([], [:method]).response_for(stub)).to respond_with(nil) + expect(HTTPInteractionList.new([], [:method]).response_for(double)).to respond_with(nil) end it 'returns nil when there is no matching interaction' do @@ -213,10 +213,10 @@ def interaction(body, request_values) end it "delegates to the parent list when it can't find a matching interaction" do - parent_list = mock(:response_for => response('parent')) + parent_list = double(:response_for => response('parent')) result = HTTPInteractionList.new( [], [:method], false, parent_list - ).response_for(stub) + ).response_for(double) expect(result).to respond_with('parent') end diff --git a/spec/vcr/cassette/migrator_spec.rb b/spec/vcr/cassette/migrator_spec.rb index 0665b8b2..c4603f6f 100644 --- a/spec/vcr/cassette/migrator_spec.rb +++ b/spec/vcr/cassette/migrator_spec.rb @@ -130,7 +130,7 @@ subject { described_class.new(dir, out_io) } before(:each) do - File.stub(:mtime).with(file_name).and_return(filemtime) + allow(File).to receive(:mtime).with(file_name).and_return(filemtime) end it 'migrates a cassette from the 1.x to 2.x format' do diff --git a/spec/vcr/cassette/persisters_spec.rb b/spec/vcr/cassette/persisters_spec.rb index 4c0d0051..d538c378 100644 --- a/spec/vcr/cassette/persisters_spec.rb +++ b/spec/vcr/cassette/persisters_spec.rb @@ -7,7 +7,7 @@ class Cassette context 'when there is already a persister registered for the given name' do before(:each) do subject[:foo] = :old_persister - subject.stub :warn + allow(subject).to receive :warn end it 'overrides the existing persister' do @@ -16,7 +16,7 @@ class Cassette end it 'warns that there is a name collision' do - subject.should_receive(:warn).with( + expect(subject).to receive(:warn).with( /WARNING: There is already a VCR cassette persister registered for :foo\. Overriding it/ ) subject[:foo] = :new_persister diff --git a/spec/vcr/cassette/serializers_spec.rb b/spec/vcr/cassette/serializers_spec.rb index 8083a4c0..907e7b67 100644 --- a/spec/vcr/cassette/serializers_spec.rb +++ b/spec/vcr/cassette/serializers_spec.rb @@ -114,7 +114,7 @@ def obj.deserialize(string) context 'when there is already a serializer registered for the given name' do before(:each) do subject[:foo] = :old_serializer - subject.stub :warn + allow(subject).to receive :warn end it 'overrides the existing serializer' do @@ -123,7 +123,7 @@ def obj.deserialize(string) end it 'warns that there is a name collision' do - subject.should_receive(:warn).with( + expect(subject).to receive(:warn).with( /WARNING: There is already a VCR cassette serializer registered for :foo\. Overriding it/ ) subject[:foo] = :new_serializer diff --git a/spec/vcr/cassette_spec.rb b/spec/vcr/cassette_spec.rb index a7d80745..4a9dec6a 100644 --- a/spec/vcr/cassette_spec.rb +++ b/spec/vcr/cassette_spec.rb @@ -12,12 +12,12 @@ def http_interaction it 'delegates the file resolution to the FileSystem persister' do fs = VCR::Cassette::Persisters::FileSystem expect(fs).to respond_to(:absolute_path_to_file).with(1).argument - fs.should_receive(:absolute_path_to_file).with("cassette name.yml") { "f.yml" } + expect(fs).to receive(:absolute_path_to_file).with("cassette name.yml") { "f.yml" } expect(VCR::Cassette.new("cassette name").file).to eq("f.yml") end it 'raises a NotImplementedError when a different persister is used' do - VCR.cassette_persisters[:a] = stub + VCR.cassette_persisters[:a] = double cassette = VCR::Cassette.new("f", :persist_with => :a) expect { cassette.file }.to raise_error(NotImplementedError) end @@ -38,7 +38,7 @@ def http_interaction end describe '#record_http_interaction' do - let(:the_interaction) { stub(:request => stub(:method => :get).as_null_object).as_null_object } + let(:the_interaction) { double(:request => double(:method => :get).as_null_object).as_null_object } it 'adds the interaction to #new_recorded_interactions' do cassette = VCR::Cassette.new(:test_cassette) @@ -63,8 +63,8 @@ def http_interaction let(:metadata) { subject.serializable_hash.reject { |k,v| k == "http_interactions" } } it 'includes the hash form of all recorded interactions' do - interaction_1.stub(:to_hash => { "i" => 1, 'body' => '' }) - interaction_2.stub(:to_hash => { "i" => 2, 'body' => '' }) + allow(interaction_1).to receive(:to_hash).and_return({ "i" => 1, 'body' => '' }) + allow(interaction_2).to receive(:to_hash).and_return({ "i" => 2, 'body' => '' }) expect(subject.serializable_hash).to include('http_interactions' => [{ "i" => 1, 'body' => '' }, { "i" => 2, 'body' => '' }]) end @@ -131,11 +131,11 @@ def http_interaction let(:empty_cassette_yaml) { YAML.dump("http_interactions" => []) } it 'optionally renders the file as ERB using the ERBRenderer' do - VCR::Cassette::Persisters::FileSystem.stub(:[] => empty_cassette_yaml) + allow(VCR::Cassette::Persisters::FileSystem).to receive(:[]).and_return(empty_cassette_yaml) - VCR::Cassette::ERBRenderer.should_receive(:new).with( + expect(VCR::Cassette::ERBRenderer).to receive(:new).with( empty_cassette_yaml, anything, "foo" - ).and_return(mock('renderer', :render => empty_cassette_yaml)) + ).and_return(double('renderer', :render => empty_cassette_yaml)) VCR::Cassette.new('foo', :record => :new_episodes).http_interactions end @@ -145,9 +145,9 @@ def http_interaction # test that it overrides the default VCR.configuration.default_cassette_options = { :erb => true } - VCR::Cassette::ERBRenderer.should_receive(:new).with( + expect(VCR::Cassette::ERBRenderer).to receive(:new).with( anything, erb, anything - ).and_return(mock('renderer', :render => empty_cassette_yaml)) + ).and_return(double('renderer', :render => empty_cassette_yaml)) VCR::Cassette.new('foo', :record => :new_episodes, :erb => erb).http_interactions end @@ -155,9 +155,9 @@ def http_interaction it "passes #{erb.inspect} to the VCR::Cassette::ERBRenderer when it is the default :erb option and none is given" do VCR.configuration.default_cassette_options = { :erb => erb } - VCR::Cassette::ERBRenderer.should_receive(:new).with( + expect(VCR::Cassette::ERBRenderer).to receive(:new).with( anything, erb, anything - ).and_return(mock('renderer', :render => empty_cassette_yaml)) + ).and_return(double('renderer', :render => empty_cassette_yaml)) VCR::Cassette.new('foo', :record => :new_episodes).http_interactions end @@ -187,12 +187,12 @@ def http_interaction expect(VCR::Cassette.new('empty', :record => :none).send(:previously_recorded_interactions)).to eq([]) end - let(:custom_persister) { stub("custom persister") } + let(:custom_persister) { double("custom persister") } it 'reads from the configured persister' do VCR.configuration.cassette_library_dir = nil VCR.cassette_persisters[:foo] = custom_persister - custom_persister.should_receive(:[]).with("abc.yml") { "" } + expect(custom_persister).to receive(:[]).with("abc.yml") { "" } VCR::Cassette.new("abc", :persist_with => :foo).http_interactions end @@ -211,8 +211,8 @@ def http_interaction context "when :#{record_mode} is passed as the record option" do def stub_old_interactions(interactions) hashes = interactions.map(&:to_hash) - VCR.cassette_serializers[:yaml].stub(:deserialize => { 'http_interactions' => hashes }) - VCR::HTTPInteraction.stub(:from_hash) do |hash| + allow(VCR.cassette_serializers[:yaml]).to receive(:deserialize).and_return({ 'http_interactions' => hashes }) + allow(VCR::HTTPInteraction).to receive(:from_hash) do |hash| interactions[hashes.index(hash)] end end @@ -225,8 +225,8 @@ def stub_old_interactions(interactions) it 'updates the content_length headers when given :update_content_length_header => true' do stub_old_interactions(interactions) - interaction_1.response.should_receive(:update_content_length_header) - interaction_2.response.should_receive(:update_content_length_header) + expect(interaction_1.response).to receive(:update_content_length_header) + expect(interaction_2.response).to receive(:update_content_length_header) VCR::Cassette.new('example', :record => record_mode, :update_content_length_header => true).http_interactions end @@ -234,8 +234,8 @@ def stub_old_interactions(interactions) [nil, false].each do |val| it "does not update the content_lenth headers when given :update_content_length_header => #{val.inspect}" do stub_old_interactions(interactions) - interaction_1.response.should_not_receive(:update_content_length_header) - interaction_2.response.should_not_receive(:update_content_length_header) + expect(interaction_1.response).not_to receive(:update_content_length_header) + expect(interaction_2.response).not_to receive(:update_content_length_header) VCR::Cassette.new('example', :record => record_mode, :update_content_length_header => val).http_interactions end @@ -246,7 +246,7 @@ def stub_old_interactions(interactions) subject { VCR::Cassette.new(File.basename(file_name).gsub('.yml', ''), :record => record_mode, :re_record_interval => 7.days) } context 'when the cassette file does not exist' do - before(:each) { File.stub(:exist?).with(file_name).and_return(false) } + before(:each) { allow(File).to receive(:exist?).with(file_name).and_return(false) } it "has :#{record_mode} for the record mode" do expect(subject.record_mode).to eq(record_mode) @@ -260,9 +260,9 @@ def stub_old_interactions(interactions) end yaml = YAML.dump("http_interactions" => interactions) - File.stub(:exist?).with(file_name).and_return(true) - File.stub(:size?).with(file_name).and_return(true) - File.stub(:read).with(file_name).and_return(yaml) + allow(File).to receive(:exist?).with(file_name).and_return(true) + allow(File).to receive(:size?).with(file_name).and_return(true) + allow(File).to receive(:read).with(file_name).and_return(yaml) end context 'and the earliest recorded interaction was recorded less than 7 days ago' do @@ -285,12 +285,12 @@ def stub_old_interactions(interactions) ] end it "has :all for the record mode when there is an internet connection available" do - VCR::InternetConnection.stub(:available? => true) + allow(VCR::InternetConnection).to receive(:available?).and_return(true) expect(subject.record_mode).to eq(:all) end it "has :#{record_mode} for the record mode when there is no internet connection available" do - VCR::InternetConnection.stub(:available? => false) + allow(VCR::InternetConnection).to receive(:available?).and_return(false) expect(subject.record_mode).to eq(record_mode) end end @@ -299,7 +299,7 @@ def stub_old_interactions(interactions) end it 'does not load ignored interactions' do - VCR.request_ignorer.stub(:ignore?) do |request| + allow(VCR.request_ignorer).to receive(:ignore?) do |request| request.uri !~ /example\.com/ end @@ -338,14 +338,14 @@ def stub_old_interactions(interactions) end it "instantiates the http_interactions with parent_list set to a null list if given :exclusive => true" do - VCR.stub(:http_interactions => stub) + allow(VCR).to receive(:http_interactions).and_return(double) VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec" cassette = VCR::Cassette.new('example', :record => record_mode, :exclusive => true) expect(cassette.http_interactions.parent_list).to be(VCR::Cassette::HTTPInteractionList::NullList) end it "instantiates the http_interactions with parent_list set to VCR.http_interactions if given :exclusive => false" do - VCR.stub(:http_interactions => stub) + allow(VCR).to receive(:http_interactions).and_return(double) VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec" cassette = VCR::Cassette.new('example', :record => record_mode, :exclusive => false) expect(cassette.http_interactions.parent_list).to be(VCR.http_interactions) @@ -353,7 +353,7 @@ def stub_old_interactions(interactions) if stub_requests it 'invokes the before_playback hooks' do - VCR.configuration.should_receive(:invoke_hook).with( + expect(VCR.configuration).to receive(:invoke_hook).with( :before_playback, an_instance_of(VCR::HTTPInteraction::HookAware), an_instance_of(VCR::Cassette) @@ -392,14 +392,14 @@ def stub_old_interactions(interactions) end describe '#eject' do - let(:custom_persister) { stub("custom persister", :[] => nil) } + let(:custom_persister) { double("custom persister", :[] => nil) } it 'asserts that there are no unused interactions if allow_unused_http_interactions is set to false' do cassette = VCR.insert_cassette("foo", :allow_unused_http_interactions => false) interaction_list = cassette.http_interactions expect(interaction_list).to respond_to(:assert_no_unused_interactions!).with(0).arguments - interaction_list.should_receive(:assert_no_unused_interactions!) + expect(interaction_list).to receive(:assert_no_unused_interactions!) cassette.eject end @@ -409,7 +409,7 @@ def stub_old_interactions(interactions) interaction_list = cassette.http_interactions expect(interaction_list).to respond_to(:assert_no_unused_interactions!) - interaction_list.should_not_receive(:assert_no_unused_interactions!) + expect(interaction_list).not_to receive(:assert_no_unused_interactions!) cassette.eject end @@ -420,7 +420,7 @@ def stub_old_interactions(interactions) cassette = VCR.insert_cassette("foo", :persist_with => :foo) cassette.record_http_interaction http_interaction - custom_persister.should_receive(:[]=).with("foo.yml", /http_interactions/) + expect(custom_persister).to receive(:[]=).with("foo.yml", /http_interactions/) cassette.eject end @@ -429,7 +429,7 @@ def stub_old_interactions(interactions) cassette = VCR::Cassette.new(:eject_test) cassette.record_http_interaction http_interaction # so it has one expect(cassette).to respond_to(:serializable_hash) - cassette.stub(:serializable_hash => { "http_interactions" => [1, 3, 5] }) + allow(cassette).to receive(:serializable_hash).and_return({ "http_interactions" => [1, 3, 5] }) expect { cassette.eject }.to change { File.exist?(cassette.file) }.from(false).to(true) saved_stuff = YAML.load_file(cassette.file) @@ -443,12 +443,12 @@ def stub_old_interactions(interactions) ] cassette = VCR::Cassette.new('example', :tag => :foo) - cassette.stub!(:new_recorded_interactions).and_return(interactions) + allow(cassette).to receive(:new_recorded_interactions).and_return(interactions) - VCR.configuration.stub(:invoke_hook).and_return([false]) + allow(VCR.configuration).to receive(:invoke_hook).and_return([false]) interactions.each do |i| - VCR.configuration.should_receive(:invoke_hook).with( + expect(VCR.configuration).to receive(:invoke_hook).with( :before_record, an_instance_of(VCR::HTTPInteraction::HookAware), cassette @@ -463,11 +463,11 @@ def stub_old_interactions(interactions) interaction_2 = http_interaction { |i| i.request.uri = 'http://bar.com/'; i.response.body = 'res 2' } hook_aware_interaction_1 = interaction_1.hook_aware - interaction_1.stub(:hook_aware => hook_aware_interaction_1) + allow(interaction_1).to receive(:hook_aware).and_return(hook_aware_interaction_1) hook_aware_interaction_1.ignore! cassette = VCR::Cassette.new('test_cassette') - cassette.stub!(:new_recorded_interactions).and_return([interaction_1, interaction_2]) + allow(cassette).to receive(:new_recorded_interactions).and_return([interaction_1, interaction_2]) cassette.eject saved_recorded_interactions = ::YAML.load_file(cassette.file) @@ -478,11 +478,11 @@ def stub_old_interactions(interactions) interaction_1 = http_interaction { |i| i.request.uri = 'http://foo.com/'; i.response.body = 'res 1' } hook_aware_interaction_1 = interaction_1.hook_aware - interaction_1.stub(:hook_aware => hook_aware_interaction_1) + allow(interaction_1).to receive(:hook_aware).and_return(hook_aware_interaction_1) hook_aware_interaction_1.ignore! cassette = VCR::Cassette.new('test_cassette') - cassette.stub!(:new_recorded_interactions).and_return([interaction_1]) + allow(cassette).to receive(:new_recorded_interactions).and_return([interaction_1]) cassette.eject expect(File).not_to exist(cassette.file) @@ -491,7 +491,7 @@ def stub_old_interactions(interactions) it "writes the recorded interactions to a subdirectory if the cassette name includes a directory" do recorded_interactions = [http_interaction { |i| i.response.body = "subdirectory response" }] cassette = VCR::Cassette.new('subdirectory/test_cassette') - cassette.stub(:new_recorded_interactions => recorded_interactions) + allow(cassette).to receive(:new_recorded_interactions).and_return(recorded_interactions) expect { cassette.eject }.to change { File.exist?(cassette.file) }.from(false).to(true) saved_recorded_interactions = YAML.load_file(cassette.file) @@ -509,7 +509,7 @@ def stub_old_interactions(interactions) 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') + expect(File).not_to receive(:open).with(subject.file, 'w') expect { subject.eject }.to_not change { File.mtime(yaml_file) } end @@ -531,8 +531,8 @@ def interaction(response_body, request_attributes) let(:now) { Time.utc(2011, 6, 11, 12, 30) } before(:each) do - Time.stub(:now => now) - subject.stub(:previously_recorded_interactions => [interaction_foo_1]) + allow(Time).to receive(:now).and_return(now) + allow(subject).to receive(:previously_recorded_interactions).and_return([interaction_foo_1]) subject.record_http_interaction(interaction_foo_2) subject.record_http_interaction(interaction_bar) subject.eject diff --git a/spec/vcr/configuration_spec.rb b/spec/vcr/configuration_spec.rb index 5140f15f..048e2929 100644 --- a/spec/vcr/configuration_spec.rb +++ b/spec/vcr/configuration_spec.rb @@ -68,8 +68,8 @@ describe '#hook_into' do it 'requires the named library hook' do - subject.should_receive(:require).with("vcr/library_hooks/fakeweb") - subject.should_receive(:require).with("vcr/library_hooks/excon") + expect(subject).to receive(:require).with("vcr/library_hooks/fakeweb") + expect(subject).to receive(:require).with("vcr/library_hooks/excon") subject.hook_into :fakeweb, :excon end @@ -89,14 +89,14 @@ describe '#ignore_hosts' do it 'delegates to the current request_ignorer instance' do - VCR.request_ignorer.should_receive(:ignore_hosts).with('example.com', 'example.net') + expect(VCR.request_ignorer).to receive(:ignore_hosts).with('example.com', 'example.net') subject.ignore_hosts 'example.com', 'example.net' end end describe '#ignore_localhost=' do it 'delegates to the current request_ignorer instance' do - VCR.request_ignorer.should_receive(:ignore_localhost=).with(true) + expect(VCR.request_ignorer).to receive(:ignore_localhost=).with(true) subject.ignore_localhost = true end end @@ -107,7 +107,7 @@ it 'registers the given block with the request ignorer' do block_called = false subject.ignore_request { |r| block_called = true } - VCR.request_ignorer.ignore?(stub(:parsed_uri => uri)) + VCR.request_ignorer.ignore?(double(:parsed_uri => uri)) expect(block_called).to be_true end end @@ -155,9 +155,9 @@ it 'sets up a tag filter' do called = false VCR.configuration.send(hook_type, :my_tag) { called = true } - VCR.configuration.invoke_hook(hook_type, stub, stub(:tags => [])) + VCR.configuration.invoke_hook(hook_type, double, double(:tags => [])) expect(called).to be_false - VCR.configuration.invoke_hook(hook_type, stub, stub(:tags => [:my_tag])) + VCR.configuration.invoke_hook(hook_type, double, double(:tags => [:my_tag])) expect(called).to be_true end end @@ -165,42 +165,42 @@ %w[ filter_sensitive_data define_cassette_placeholder ].each do |method| describe "##{method}" do - let(:interaction) { mock('interaction').as_null_object } - before(:each) { interaction.stub(:filter!) } + let(:interaction) { double('interaction').as_null_object } + before(:each) { allow(interaction).to receive(:filter!) } it 'adds a before_record hook that replaces the string returned by the block with the given string' do subject.send(method, 'foo', &lambda { 'bar' }) - interaction.should_receive(:filter!).with('bar', 'foo') - subject.invoke_hook(:before_record, interaction, stub.as_null_object) + expect(interaction).to receive(:filter!).with('bar', 'foo') + subject.invoke_hook(:before_record, interaction, double.as_null_object) end it 'adds a before_playback hook that replaces the given string with the string returned by the block' do subject.send(method, 'foo', &lambda { 'bar' }) - interaction.should_receive(:filter!).with('foo', 'bar') - subject.invoke_hook(:before_playback, interaction, stub.as_null_object) + expect(interaction).to receive(:filter!).with('foo', 'bar') + subject.invoke_hook(:before_playback, interaction, double.as_null_object) end it 'tags the before_record hook when given a tag' do - subject.should_receive(:before_record).with(:my_tag) + expect(subject).to receive(:before_record).with(:my_tag) subject.send(method, 'foo', :my_tag) { 'bar' } end it 'tags the before_playback hook when given a tag' do - subject.should_receive(:before_playback).with(:my_tag) + expect(subject).to receive(:before_playback).with(:my_tag) subject.send(method, 'foo', :my_tag) { 'bar' } end it 'yields the interaction to the block for the before_record hook' do yielded_interaction = nil subject.send(method, 'foo', &lambda { |i| yielded_interaction = i; 'bar' }) - subject.invoke_hook(:before_record, interaction, stub.as_null_object) + subject.invoke_hook(:before_record, interaction, double.as_null_object) expect(yielded_interaction).to equal(interaction) end it 'yields the interaction to the block for the before_playback hook' do yielded_interaction = nil subject.send(method, 'foo', &lambda { |i| yielded_interaction = i; 'bar' }) - subject.invoke_hook(:before_playback, interaction, stub.as_null_object) + subject.invoke_hook(:before_playback, interaction, double.as_null_object) expect(yielded_interaction).to equal(interaction) end end @@ -235,7 +235,7 @@ def request(type) end if RUBY_VERSION < '1.9' describe "#cassette_serializers" do - let(:custom_serializer) { stub } + let(:custom_serializer) { double } it 'allows a custom serializer to be registered' do expect { subject.cassette_serializers[:custom] }.to raise_error(ArgumentError) subject.cassette_serializers[:custom] = custom_serializer @@ -244,7 +244,7 @@ def request(type) end describe "#cassette_persisters" do - let(:custom_persister) { stub } + let(:custom_persister) { double } it 'allows a custom persister to be registered' do expect { subject.cassette_persisters[:custom] }.to raise_error(ArgumentError) subject.cassette_persisters[:custom] = custom_persister @@ -253,7 +253,7 @@ def request(type) end describe "#uri_parser=" do - let(:custom_parser) { stub } + let(:custom_parser) { double } it 'allows a custom uri parser to be set' do subject.uri_parser = custom_parser expect(subject.uri_parser).to eq(custom_parser) @@ -266,7 +266,7 @@ def request(type) describe "#preserve_exact_body_bytes_for?" do def message_for(body) - stub(:body => body) + double(:body => body) end context "default hook" do @@ -302,7 +302,7 @@ def message_for(body) it "invokes the configured hook with the http message and the current cassette" do VCR.use_cassette('example') do |cassette| expect(cassette).to be_a(VCR::Cassette) - message = stub(:message) + message = double(:message) yielded_objects = nil subject.preserve_exact_body_bytes { |a, b| yielded_objects = [a, b] } @@ -314,7 +314,7 @@ def message_for(body) describe "#configure_rspec_metadata!" do it "only configures the underlying metadata once, no matter how many times it is called" do - VCR::RSpec::Metadata.should_receive(:configure!).once + expect(VCR::RSpec::Metadata).to receive(:configure!).once VCR.configure do |c| c.configure_rspec_metadata! end diff --git a/spec/vcr/deprecations_spec.rb b/spec/vcr/deprecations_spec.rb index 0bc81562..9c74fe07 100644 --- a/spec/vcr/deprecations_spec.rb +++ b/spec/vcr/deprecations_spec.rb @@ -3,7 +3,7 @@ describe VCR, 'deprecations', :disable_warnings do describe ".config" do it 'delegates to VCR.configure' do - VCR.should_receive(:configure) + expect(VCR).to receive(:configure) VCR.config { } end @@ -14,7 +14,7 @@ end it 'prints a deprecation warning' do - VCR.should_receive(:warn).with(/VCR.config.*deprecated/i) + expect(VCR).to receive(:warn).with(/VCR.config.*deprecated/i) VCR.config { } end @@ -26,7 +26,7 @@ end it 'prints a deprecation warning' do - VCR.should_receive(:warn).with(/VCR::Config.*deprecated/i) + expect(VCR).to receive(:warn).with(/VCR::Config.*deprecated/i) VCR::Config end @@ -44,7 +44,7 @@ end it 'prints a deprecation warning' do - VCR::Cassette.should_receive(:warn).with(/VCR::Cassette::MissingERBVariableError.*deprecated/i) + expect(VCR::Cassette).to receive(:warn).with(/VCR::Cassette::MissingERBVariableError.*deprecated/i) VCR::Cassette::MissingERBVariableError end @@ -58,26 +58,26 @@ describe "VCR.configure { |c| c.stub_with ... }" do it 'delegates to #hook_into' do - VCR.configuration.should_receive(:hook_into).with(:fakeweb, :excon) + expect(VCR.configuration).to receive(:hook_into).with(:fakeweb, :excon) VCR.configure { |c| c.stub_with :fakeweb, :excon } end it 'prints a deprecation warning' do - VCR.configuration.should_receive(:warn).with(/stub_with.*deprecated/i) + expect(VCR.configuration).to receive(:warn).with(/stub_with.*deprecated/i) VCR.configure { |c| c.stub_with :fakeweb, :excon } end end describe "VCR::Middleware::Faraday" do it 'prints a deprecation warning when passed a block' do - Kernel.should_receive(:warn).with(/Passing a block .* is deprecated/) - VCR::Middleware::Faraday.new(stub) { } + expect(Kernel).to receive(:warn).with(/Passing a block .* is deprecated/) + VCR::Middleware::Faraday.new(double) { } end end describe "VCR::RSpec::Macros" do it 'prints a deprecation warning' do - Kernel.should_receive(:warn).with(/VCR::RSpec::Macros is deprecated/) + expect(Kernel).to receive(:warn).with(/VCR::RSpec::Macros is deprecated/) Class.new.extend(VCR::RSpec::Macros) end end diff --git a/spec/vcr/errors_spec.rb b/spec/vcr/errors_spec.rb index 76d450ca..6541f130 100644 --- a/spec/vcr/errors_spec.rb +++ b/spec/vcr/errors_spec.rb @@ -82,7 +82,7 @@ def request_with(values) it 'mentions :allow_playback_repeats if the current cassette has a used matching interaction' do VCR.use_cassette('example') do |cassette| expect(cassette.http_interactions).to respond_to(:has_used_interaction_matching?) - cassette.http_interactions.stub(:has_used_interaction_matching? => true) + allow(cassette.http_interactions).to receive(:has_used_interaction_matching?).and_return(true) expect(message).to include('allow_playback_repeats') end end @@ -90,7 +90,7 @@ def request_with(values) it 'does not mention :allow_playback_repeats if the current cassette does not have a used matching interaction' do VCR.use_cassette('example') do |cassette| expect(cassette.http_interactions).to respond_to(:has_used_interaction_matching?) - cassette.http_interactions.stub(:has_used_interaction_matching? => false) + allow(cassette.http_interactions).to receive(:has_used_interaction_matching?).and_return(false) expect(message).not_to include('allow_playback_repeats') end end @@ -98,7 +98,7 @@ def request_with(values) it 'does not mention using a different :match_requests_on option when there are no remaining unused interactions' do VCR.use_cassette('example') do |cassette| expect(cassette.http_interactions).to respond_to(:remaining_unused_interaction_count) - cassette.http_interactions.stub(:remaining_unused_interaction_count => 0) + allow(cassette.http_interactions).to receive(:remaining_unused_interaction_count).and_return(0) expect(message).not_to include('match_requests_on cassette option') end end @@ -106,7 +106,7 @@ def request_with(values) it 'mentions using a different :match_requests_on option when there are some remaining unused interactions' do VCR.use_cassette('example') do |cassette| expect(cassette.http_interactions).to respond_to(:remaining_unused_interaction_count) - cassette.http_interactions.stub(:remaining_unused_interaction_count => 1) + allow(cassette.http_interactions).to receive(:remaining_unused_interaction_count).and_return(1) expect(message).to include('match_requests_on cassette option') end end @@ -114,7 +114,7 @@ def request_with(values) it 'uses the singular (HTTP interaction) when there is only 1 left' do VCR.use_cassette('example') do |cassette| expect(cassette.http_interactions).to respond_to(:remaining_unused_interaction_count) - cassette.http_interactions.stub(:remaining_unused_interaction_count => 1) + allow(cassette.http_interactions).to receive(:remaining_unused_interaction_count).and_return(1) expect(message).to include('1 HTTP interaction ') end end @@ -122,7 +122,7 @@ def request_with(values) it 'uses the plural (HTTP interactions) when there is more than 1 left' do VCR.use_cassette('example') do |cassette| expect(cassette.http_interactions).to respond_to(:remaining_unused_interaction_count) - cassette.http_interactions.stub(:remaining_unused_interaction_count => 2) + allow(cassette.http_interactions).to receive(:remaining_unused_interaction_count).and_return(2) expect(message).to include('2 HTTP interactions ') end end diff --git a/spec/vcr/library_hooks/excon_spec.rb b/spec/vcr/library_hooks/excon_spec.rb index 8ca78567..7c811383 100644 --- a/spec/vcr/library_hooks/excon_spec.rb +++ b/spec/vcr/library_hooks/excon_spec.rb @@ -14,7 +14,7 @@ let(:excon) { ::Excon.new("http://localhost:#{VCR::SinatraApp.port}/search") } it 'properly records and plays back the response' do - VCR.stub(:real_http_connections_allowed? => true) + allow(VCR).to receive(:real_http_connections_allowed?).and_return(true) recorded, played_back = [1, 2].map do VCR.use_cassette('excon_query', :record => :once) do excon.request(:method => :get, :query => { :q => 'Tolkien' }).body @@ -30,11 +30,11 @@ context 'when Excon raises an error due to an unexpected response status' do before(:each) do - VCR.stub(:real_http_connections_allowed? => true) + allow(VCR).to receive(:real_http_connections_allowed?).and_return(true) end it 'still records properly' do - VCR.should_receive(:record_http_interaction) do |interaction| + expect(VCR).to receive(:record_http_interaction) do |interaction| expect(interaction.response.status.code).to eq(404) expect(interaction.response.body).to eq('404 not 200') end @@ -77,7 +77,7 @@ def make_request(disabled = false) describe "VCR.configuration.after_library_hooks_loaded hook" do it 'disables the webmock excon adapter so it does not conflict with our typhoeus hook' do expect(::WebMock::HttpLibAdapters::ExconAdapter).to respond_to(:disable!) - ::WebMock::HttpLibAdapters::ExconAdapter.should_receive(:disable!) + expect(::WebMock::HttpLibAdapters::ExconAdapter).to receive(:disable!) $excon_after_loaded_hook.conditionally_invoke end end diff --git a/spec/vcr/library_hooks/fakeweb_spec.rb b/spec/vcr/library_hooks/fakeweb_spec.rb index 5bb444af..84cf47eb 100644 --- a/spec/vcr/library_hooks/fakeweb_spec.rb +++ b/spec/vcr/library_hooks/fakeweb_spec.rb @@ -22,11 +22,11 @@ def directly_stub_request(method, url, response_body) describe "some specific Net::HTTP edge cases" do before(:each) do - VCR.stub(:real_http_connections_allowed? => true) + allow(VCR).to receive(:real_http_connections_allowed?).and_return(true) end it 'records the request body when using #post_form' do - VCR.should_receive(:record_http_interaction) do |interaction| + expect(VCR).to receive(:record_http_interaction) do |interaction| expect(interaction.request.body).to eq("q=ruby") end @@ -35,7 +35,7 @@ def directly_stub_request(method, url, response_body) end it "does not record headers for which Net::HTTP sets defaults near the end of the real request" do - VCR.should_receive(:record_http_interaction) do |interaction| + expect(VCR).to receive(:record_http_interaction) do |interaction| expect(interaction.request.headers).not_to have_key('content-type') expect(interaction.request.headers).not_to have_key('host') end @@ -43,7 +43,7 @@ def directly_stub_request(method, url, response_body) end it "records headers for which Net::HTTP usually sets defaults when the user manually sets their values" do - VCR.should_receive(:record_http_interaction) do |interaction| + expect(VCR).to receive(:record_http_interaction) do |interaction| expect(interaction.request.headers['content-type']).to eq(['foo/bar']) expect(interaction.request.headers['host']).to eq(['my-example.com']) end @@ -57,7 +57,7 @@ def perform_get_with_returning_block end it 'records the interaction when Net::HTTP#request is called with a block with a return statement' do - VCR.should_receive(:record_http_interaction).once + expect(VCR).to receive(:record_http_interaction).once expect(perform_get_with_returning_block.body).to eq("GET to root") end @@ -66,7 +66,7 @@ def make_post_request end it 'records the interaction only once, even when Net::HTTP internally recursively calls #request' do - VCR.should_receive(:record_http_interaction).once + expect(VCR).to receive(:record_http_interaction).once make_post_request end @@ -129,7 +129,7 @@ def make_post_request end it "warns about FakeWeb deprecation" do - ::Kernel.should_receive(:warn).with("WARNING: VCR's FakeWeb integration is deprecated and will be removed in VCR 3.0.") + expect(::Kernel).to receive(:warn).with("WARNING: VCR's FakeWeb integration is deprecated and will be removed in VCR 3.0.") run_hook end end @@ -148,7 +148,7 @@ def assert_expected_response(response) undef make_request def make_request(disabled = false) - ::Net::HTTP.any_instance.stub(:request_without_vcr).and_raise(SocketError) + allow_any_instance_of(::Net::HTTP).to receive(:request_without_vcr).and_raise(SocketError) expect { ::Net::HTTP.get_response(URI(request_url)) }.to raise_error(SocketError) diff --git a/spec/vcr/library_hooks/faraday_spec.rb b/spec/vcr/library_hooks/faraday_spec.rb index 54c173e7..e84e3575 100644 --- a/spec/vcr/library_hooks/faraday_spec.rb +++ b/spec/vcr/library_hooks/faraday_spec.rb @@ -47,7 +47,7 @@ builder.use Faraday::Response::Logger end - conn.builder.should_receive(:warn).with(/Faraday::Response::Logger/) + expect(conn.builder).to receive(:warn).with(/Faraday::Response::Logger/) conn.builder.lock! end diff --git a/spec/vcr/library_hooks/typhoeus_0.4_spec.rb b/spec/vcr/library_hooks/typhoeus_0.4_spec.rb index dfb2a84b..77eed5a9 100644 --- a/spec/vcr/library_hooks/typhoeus_0.4_spec.rb +++ b/spec/vcr/library_hooks/typhoeus_0.4_spec.rb @@ -16,19 +16,19 @@ def enable_real_connections def directly_stub_request(method, url, response_body) response = ::Typhoeus::Response.new(:code => 200, :body => response_body) - ::Typhoeus::Hydra.stub(method, url).and_return(response) + allow(::Typhoeus::Hydra).to receive(method, url).and_return(response) end it_behaves_like 'a hook into an HTTP library', :typhoeus, 'typhoeus 0.4' describe "VCR.configuration.after_library_hooks_loaded hook" do it 'disables the webmock typhoeus adapter so it does not conflict with our typhoeus hook' do - ::WebMock::HttpLibAdapters::TyphoeusAdapter.should_receive(:disable!) + expect(::WebMock::HttpLibAdapters::TyphoeusAdapter).to receive(:disable!) $typhoeus_after_loaded_hook.conditionally_invoke end it "warns about Typhoeus 0.4 deprecation" do - ::Kernel.should_receive(:warn).with("WARNING: VCR's Typhoeus 0.4 integration is deprecated and will be removed in VCR 3.0.") + expect(::Kernel).to receive(:warn).with("WARNING: VCR's Typhoeus 0.4 integration is deprecated and will be removed in VCR 3.0.") $typhoeus_0_4_after_loaded_hook.conditionally_invoke end end diff --git a/spec/vcr/library_hooks/typhoeus_spec.rb b/spec/vcr/library_hooks/typhoeus_spec.rb index c3774ee7..e6810352 100644 --- a/spec/vcr/library_hooks/typhoeus_spec.rb +++ b/spec/vcr/library_hooks/typhoeus_spec.rb @@ -23,7 +23,7 @@ def directly_stub_request(method, url, response_body) describe "VCR.configuration.after_library_hooks_loaded hook" do it 'disables the webmock typhoeus adapter so it does not conflict with our typhoeus hook' do - ::WebMock::HttpLibAdapters::TyphoeusAdapter.should_receive(:disable!) + expect(::WebMock::HttpLibAdapters::TyphoeusAdapter).to receive(:disable!) $typhoeus_after_loaded_hook.conditionally_invoke end end diff --git a/spec/vcr/library_hooks/webmock_spec.rb b/spec/vcr/library_hooks/webmock_spec.rb index c8f208b6..eb2e8c5c 100644 --- a/spec/vcr/library_hooks/webmock_spec.rb +++ b/spec/vcr/library_hooks/webmock_spec.rb @@ -40,10 +40,10 @@ def run_after_request_callback context "when there'ss a bug and the request does not have the @__typed_vcr_request in the after_request callbacks" do let(:warner) { VCR::LibraryHooks::WebMock } - before { warner.stub(:warn) } + before { allow(warner).to receive(:warn) } it 'records the HTTP interaction properly' do - VCR.should_receive(:record_http_interaction) do |i| + expect(VCR).to receive(:record_http_interaction) do |i| expect(i.request.uri).to eq("http://foo.com/") expect(i.response.body).to eq("OK") end @@ -63,7 +63,7 @@ def run_after_request_callback end it 'prints a warning' do - warner.should_receive(:warn).at_least(:once).with(/bug.*after_request/) + expect(warner).to receive(:warn).at_least(:once).with(/bug.*after_request/) run_after_request_callback end diff --git a/spec/vcr/middleware/faraday_spec.rb b/spec/vcr/middleware/faraday_spec.rb index 00a77c78..56833701 100644 --- a/spec/vcr/middleware/faraday_spec.rb +++ b/spec/vcr/middleware/faraday_spec.rb @@ -22,7 +22,7 @@ def self.test_recording it 'records the request body correctly' do payload = { :file => Faraday::UploadIO.new(__FILE__, 'text/plain') } - VCR.should_receive(:record_http_interaction) do |i| + expect(VCR).to receive(:record_http_interaction) do |i| expect(i.request.headers['Content-Type'].first).to include("multipart") expect(i.request.body).to include(File.read(__FILE__)) end @@ -131,7 +131,7 @@ def make_request context 'for a recorded request' do let!(:inserted_cassette) { VCR.insert_cassette('new_cassette') } - before(:each) { VCR.should_receive(:record_http_interaction) } + before(:each) { expect(VCR).to receive(:record_http_interaction) } it_behaves_like "exclusive library hook" end @@ -161,7 +161,7 @@ def make_request(disabled = false) it 'can be used to eject a cassette after the request is recorded' do VCR.configuration.after_http_request { |request| VCR.eject_cassette } - VCR.should_receive(:record_http_interaction) do |interaction| + expect(VCR).to receive(:record_http_interaction) do |interaction| expect(VCR.current_cassette).to be(inserted_cassette) end diff --git a/spec/vcr/middleware/rack_spec.rb b/spec/vcr/middleware/rack_spec.rb index 387eb6a5..6aa0028b 100644 --- a/spec/vcr/middleware/rack_spec.rb +++ b/spec/vcr/middleware/rack_spec.rb @@ -45,8 +45,8 @@ module Middleware describe '#call' do let(:env_hash) { { :env => :hash } } it 'calls the provided rack app and returns its response' do - rack_app = mock - rack_app.should_receive(:call).with(env_hash).and_return(:response) + rack_app = double + expect(rack_app).to receive(:call).with(env_hash).and_return(:response) instance = described_class.new(rack_app) { |c| c.name 'cassette_name' } expect(instance.call(env_hash)).to eq(:response) end diff --git a/spec/vcr/request_matcher_registry_spec.rb b/spec/vcr/request_matcher_registry_spec.rb index f1e1e2c7..73c85604 100644 --- a/spec/vcr/request_matcher_registry_spec.rb +++ b/spec/vcr/request_matcher_registry_spec.rb @@ -20,23 +20,23 @@ def request_with(values) it 'registers a request matcher block that can be used later' do matcher_called = false subject.register(:my_matcher) { |*a| matcher_called = true } - subject[:my_matcher].matches?(stub, stub) + subject[:my_matcher].matches?(double, double) expect(matcher_called).to be_true end context 'when there is already a matcher for the given name' do before(:each) do subject.register(:foo) { |*a| false } - subject.stub :warn + allow(subject).to receive :warn end it 'overrides the existing matcher' do subject.register(:foo) { |*a| true } - expect(subject[:foo].matches?(stub, stub)).to be_true + expect(subject[:foo].matches?(double, double)).to be_true end it 'warns that there is a name collision' do - subject.should_receive(:warn).with( + expect(subject).to receive(:warn).with( /WARNING: There is already a VCR request matcher registered for :foo\. Overriding it/ ) diff --git a/spec/vcr/structs_spec.rb b/spec/vcr/structs_spec.rb index 3d68a563..3d123647 100644 --- a/spec/vcr/structs_spec.rb +++ b/spec/vcr/structs_spec.rb @@ -77,7 +77,7 @@ def body_hash(key, value) let(:now) { Time.now } it 'is initialized to the current time' do - Time.stub(:now => now) + allow(Time).to receive(:now).and_return(now) expect(VCR::HTTPInteraction.new.recorded_at).to eq(now) end end @@ -192,7 +192,7 @@ def body_hash(key, value) expect(string).to be_valid_encoding hash['request']['body'] = { 'string' => string, 'encoding' => 'ASCII-8BIT' } - Request.should_not_receive(:warn) + expect(Request).not_to receive(:warn) i = HTTPInteraction.from_hash(hash) expect(i.request.body).to eq(string) expect(i.request.body.bytes.to_a).to eq(string.bytes.to_a) @@ -205,8 +205,8 @@ def verify_encoding_error end before do - Request.stub(:warn) - Response.stub(:warn) + allow(Request).to receive(:warn) + allow(Response).to receive(:warn) hash['request']['body'] = { 'string' => "\xFAbc", 'encoding' => 'ISO-8859-1' } hash['response']['body'] = { 'string' => "\xFAbc", 'encoding' => 'ISO-8859-1' } @@ -223,8 +223,8 @@ def verify_encoding_error end it 'prints a warning and informs users of the :preserve_exact_body_bytes option' do - Request.should_receive(:warn).with(/ISO-8859-1.*preserve_exact_body_bytes/) - Response.should_receive(:warn).with(/ISO-8859-1.*preserve_exact_body_bytes/) + expect(Request).to receive(:warn).with(/ISO-8859-1.*preserve_exact_body_bytes/) + expect(Response).to receive(:warn).with(/ISO-8859-1.*preserve_exact_body_bytes/) HTTPInteraction.from_hash(hash) end @@ -304,15 +304,15 @@ def assert_yielded_keys(hash, *keys) describe "#parsed_uri" do before :each do - uri_parser.stub(:parse).and_return(uri) + allow(uri_parser).to receive(:parse).and_return(uri) VCR.stub_chain(:configuration, :uri_parser).and_return(uri_parser) end - let(:uri_parser){ mock('parser') } - let(:uri){ mock('uri').as_null_object } + let(:uri_parser){ double('parser') } + let(:uri){ double('uri').as_null_object } it "parses the uri using the current uri_parser" do - uri_parser.should_receive(:parse).with(request.uri) + expect(uri_parser).to receive(:parse).with(request.uri) request.parsed_uri end @@ -408,14 +408,14 @@ def assert_yielded_keys(hash, *keys) describe Request::Typed do [:uri, :method, :headers, :body].each do |method| it "delegates ##{method} to the request" do - request = stub(method => "delegated value") + request = double(method => "delegated value") expect(Request::Typed.new(request, :type).send(method)).to eq("delegated value") end end describe "#type" do it 'returns the initialized type' do - expect(Request::Typed.new(stub, :ignored).type).to be(:ignored) + expect(Request::Typed.new(double, :ignored).type).to be(:ignored) end end @@ -423,11 +423,11 @@ def assert_yielded_keys(hash, *keys) valid_types.each do |type| describe "##{type}?" do it "returns true if the type is set to :#{type}" do - expect(Request::Typed.new(stub, type).send("#{type}?")).to be_true + expect(Request::Typed.new(double, type).send("#{type}?")).to be_true end it "returns false if the type is set to :other" do - expect(Request::Typed.new(stub, :other).send("#{type}?")).to be_false + expect(Request::Typed.new(double, :other).send("#{type}?")).to be_false end end end @@ -436,13 +436,13 @@ def assert_yielded_keys(hash, *keys) real_types = [:ignored, :recordable] real_types.each do |type| it "returns true if the type is set to :#{type}" do - expect(Request::Typed.new(stub, type)).to be_real + expect(Request::Typed.new(double, type)).to be_real end end (valid_types - real_types).each do |type| it "returns false if the type is set to :#{type}" do - expect(Request::Typed.new(stub, type)).not_to be_real + expect(Request::Typed.new(double, type)).not_to be_real end end end @@ -451,13 +451,13 @@ def assert_yielded_keys(hash, *keys) stubbed_types = [:externally_stubbed, :stubbed_by_vcr] stubbed_types.each do |type| it "returns true if the type is set to :#{type}" do - expect(Request::Typed.new(stub, type)).to be_stubbed + expect(Request::Typed.new(double, type)).to be_stubbed end end (valid_types - stubbed_types).each do |type| it "returns false if the type is set to :#{type}" do - expect(Request::Typed.new(stub, type)).not_to be_stubbed + expect(Request::Typed.new(double, type)).not_to be_stubbed end end end @@ -527,7 +527,7 @@ def uri_for(uri) end it 'can be cast to a proc' do - Fiber.should_receive(:yield) + expect(Fiber).to receive(:yield) lambda(&subject).call end end if RUBY_VERSION > '1.9' diff --git a/spec/vcr/test_frameworks/cucumber_spec.rb b/spec/vcr/test_frameworks/cucumber_spec.rb index 2d3a1a41..211b5c11 100644 --- a/spec/vcr/test_frameworks/cucumber_spec.rb +++ b/spec/vcr/test_frameworks/cucumber_spec.rb @@ -6,7 +6,7 @@ let(:after_blocks_for_tags) { {} } def scenario(name) - stub(:name => name, :feature => stub(:name => "My feature name\nThe preamble text is not included")) + double(:name => name, :feature => double(:name => "My feature name\nThe preamble text is not included")) end let(:current_scenario) { scenario "My scenario name\nThe preamble text is not included" } @@ -64,8 +64,8 @@ def test_tag(cassette_attribute, tag, expected_value, scenario=current_scenario) it "makes a unique name for each element of scenario outline" do subject.send(tag_method, 'tag1', :use_scenario_name => true) - scenario_with_outline = stub(:name => "My row name", - :scenario_outline => stub(:feature => stub(:name => "My feature name\nThe preamble text is not included"), + scenario_with_outline = double(:name => "My row name", + :scenario_outline => double(:feature => double(:name => "My feature name\nThe preamble text is not included"), :name => "My scenario outline name")) test_tag(:name, 'tag1', 'My feature name/My scenario outline name/My row name', scenario_with_outline) end @@ -73,7 +73,7 @@ def test_tag(cassette_attribute, tag, expected_value, scenario=current_scenario) it 'does not pass :use_scenario_name along the given options to the cassette' do subject.send(tag_method, 'tag1', :use_scenario_name => true) - VCR::Cassette.should_receive(:new).with(anything, hash_not_including(:use_scenario_name)) + expect(VCR::Cassette).to receive(:new).with(anything, hash_not_including(:use_scenario_name)) before_blocks_for_tags['tag1'].call(current_scenario) end diff --git a/spec/vcr/util/hooks_spec.rb b/spec/vcr/util/hooks_spec.rb index 333b2be4..198ded7a 100644 --- a/spec/vcr/util/hooks_spec.rb +++ b/spec/vcr/util/hooks_spec.rb @@ -68,7 +68,7 @@ it '#to_procs the filter objects' do filter_called = false subject.hook = lambda { } - subject.filters = [stub(:to_proc => lambda { filter_called = true })] + subject.filters = [double(:to_proc => lambda { filter_called = true })] subject.conditionally_invoke expect(filter_called).to be_true end @@ -129,7 +129,7 @@ it 'does not invoke any filtered callbacks' do subject.before_foo(:real?) { invocations << :blue_callback } - subject.invoke_hook(:before_foo, stub(:real? => false)) + subject.invoke_hook(:before_foo, double(:real? => false)) expect(invocations).to be_empty end diff --git a/spec/vcr/util/internet_connection_spec.rb b/spec/vcr/util/internet_connection_spec.rb index cdbf824f..a17b2d6e 100644 --- a/spec/vcr/util/internet_connection_spec.rb +++ b/spec/vcr/util/internet_connection_spec.rb @@ -7,7 +7,7 @@ end def stub_pingecho_with(value) - VCR::Ping.stub(:pingecho).with("example.com", anything, anything).and_return(value) + allow(VCR::Ping).to receive(:pingecho).with("example.com", anything, anything).and_return(value) end context 'when pinging example.com succeeds' do @@ -17,7 +17,7 @@ def stub_pingecho_with(value) end it 'memoizes the value so no extra pings are made' do - VCR::Ping.should_receive(:pingecho).once.and_return(true) + expect(VCR::Ping).to receive(:pingecho).once.and_return(true) 3.times { described_class.available? } end end @@ -29,7 +29,7 @@ def stub_pingecho_with(value) end it 'memoizes the value so no extra pings are made' do - VCR::Ping.should_receive(:pingecho).once.and_return(false) + expect(VCR::Ping).to receive(:pingecho).once.and_return(false) 3.times { described_class.available? } end end diff --git a/spec/vcr/util/version_checker_spec.rb b/spec/vcr/util/version_checker_spec.rb index 2592ddb9..a7a57fb7 100644 --- a/spec/vcr/util/version_checker_spec.rb +++ b/spec/vcr/util/version_checker_spec.rb @@ -19,25 +19,25 @@ module VCR it 'prints a warning if the major version is too high' do checker = VersionChecker.new('foo', '2.0.0', '1.0.0', '1.1') - Kernel.should_receive(:warn).with(/may not work with this version/) + expect(Kernel).to receive(:warn).with(/may not work with this version/) checker.check_version! end it 'prints a warning if the minor version is too high' do checker = VersionChecker.new('foo', '1.2.0', '1.0.0', '1.1') - Kernel.should_receive(:warn).with(/may not work with this version/) + expect(Kernel).to receive(:warn).with(/may not work with this version/) checker.check_version! end it 'does not raise an error or print a warning when the major version is between the min and max' do checker = VersionChecker.new('foo', '2.0.0', '1.0.0', '3.0') - Kernel.should_not_receive(:warn) + expect(Kernel).not_to receive(:warn) checker.check_version! end it 'does not raise an error or print a warning when the min_patch is 0.6.5, the max_minor is 0.7 and the version is 0.7.3' do checker = VersionChecker.new('foo', '0.7.3', '0.6.5', '0.7') - Kernel.should_not_receive(:warn) + expect(Kernel).not_to receive(:warn) checker.check_version! end end diff --git a/spec/vcr_spec.rb b/spec/vcr_spec.rb index 57718deb..13509bfd 100644 --- a/spec/vcr_spec.rb +++ b/spec/vcr_spec.rb @@ -28,7 +28,7 @@ def insert_cassette(name = :cassette_test) describe '.eject_cassette' do it 'ejects the current cassette' do cassette = insert_cassette - cassette.should_receive(:eject) + expect(cassette).to receive(:eject) VCR.eject_cassette end @@ -45,7 +45,7 @@ def insert_cassette(name = :cassette_test) it 'keeps the cassette as the current one until after #eject has finished' do cassette = insert_cassette current = nil - cassette.stub(:eject) { current = VCR.current_cassette } + allow(cassette).to receive(:eject) { current = VCR.current_cassette } VCR.eject_cassette @@ -55,7 +55,7 @@ def insert_cassette(name = :cassette_test) it 'properly pops the cassette off the stack even if an error occurs' do cassette = insert_cassette - cassette.stub(:eject) { raise "boom" } + allow(cassette).to receive(:eject) { raise "boom" } expect { VCR.eject_cassette }.to raise_error("boom") expect(VCR.current_cassette).to be_nil end @@ -64,7 +64,7 @@ def insert_cassette(name = :cassette_test) describe '.use_cassette' do it 'inserts a new cassette' do new_cassette = VCR::Cassette.new(:use_cassette_test) - VCR.should_receive(:insert_cassette).and_return(new_cassette) + expect(VCR).to receive(:insert_cassette).and_return(new_cassette) VCR.use_cassette(:cassette_test) { } end @@ -88,18 +88,18 @@ def insert_cassette(name = :cassette_test) end it 'ejects the cassette' do - VCR.should_receive(:eject_cassette) + expect(VCR).to receive(:eject_cassette) VCR.use_cassette(:cassette_test) { } end it 'ejects the cassette even if there is an error' do - VCR.should_receive(:eject_cassette) + expect(VCR).to receive(:eject_cassette) expect { VCR.use_cassette(:cassette_test) { raise StandardError } }.to raise_error end it 'does not eject a cassette if there was an error inserting it' do - VCR.should_receive(:insert_cassette).and_raise(StandardError.new('Boom!')) - VCR.should_not_receive(:eject_cassette) + expect(VCR).to receive(:insert_cassette).and_raise(StandardError.new('Boom!')) + expect(VCR).not_to receive(:eject_cassette) expect { VCR.use_cassette(:test) { } }.to raise_error(StandardError, 'Boom!') end @@ -228,8 +228,8 @@ def insert_cassette(name = :cassette_test) end describe '.record_http_interaction' do - before(:each) { VCR.stub(:current_cassette => current_cassette) } - let(:interaction) { stub(:request => stub) } + before(:each) { allow(VCR).to receive(:current_cassette).and_return(current_cassette) } + let(:interaction) { double(:request => double) } context 'when there is not a current cassette' do let(:current_cassette) { nil } @@ -242,17 +242,17 @@ def insert_cassette(name = :cassette_test) end context 'when there is a current cassette' do - let(:current_cassette) { mock('current cassette') } + let(:current_cassette) { double('current cassette') } it 'records the request when it should not be ignored' do - VCR.request_ignorer.stub(:ignore?).with(interaction.request).and_return(false) - current_cassette.should_receive(:record_http_interaction).with(interaction) + allow(VCR.request_ignorer).to receive(:ignore?).with(interaction.request).and_return(false) + expect(current_cassette).to receive(:record_http_interaction).with(interaction) VCR.record_http_interaction(interaction) end it 'does not record the request when it should be ignored' do - VCR.request_ignorer.stub(:ignore?).with(interaction.request).and_return(true) - current_cassette.should_not_receive(:record_http_interaction) + allow(VCR.request_ignorer).to receive(:ignore?).with(interaction.request).and_return(true) + expect(current_cassette).not_to receive(:record_http_interaction) VCR.record_http_interaction(interaction) end end @@ -329,7 +329,7 @@ def insert_cassette(name = :cassette_test) end it 'passes options through to .turn_off!' do - VCR.should_receive(:turn_off!).with(:ignore_cassettes => true) + expect(VCR).to receive(:turn_off!).with(:ignore_cassettes => true) VCR.turned_off(:ignore_cassettes => true) { } end end From 7941bf924ccdc74a54f931fe5b29402efbc1bfc5 Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Sat, 21 Sep 2013 17:37:32 -0700 Subject: [PATCH 03/11] Fix deprecated rspec usage. --- spec/vcr/library_hooks/webmock_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/vcr/library_hooks/webmock_spec.rb b/spec/vcr/library_hooks/webmock_spec.rb index eb2e8c5c..da37f1f9 100644 --- a/spec/vcr/library_hooks/webmock_spec.rb +++ b/spec/vcr/library_hooks/webmock_spec.rb @@ -98,7 +98,7 @@ def normalize_request_headers(headers) expect { make_http_request(:get, request_url) - }.to_not raise_error(unexpected_error) + }.to_not raise_error end it 'can allow connections to matching urls' do @@ -107,7 +107,7 @@ def normalize_request_headers(headers) expect { make_http_request(:get, request_url) - }.to_not raise_error(unexpected_error) + }.to_not raise_error end end end From 2d8420cccdf57d90f3378a8a18a4629e360ffb41 Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Sat, 21 Sep 2013 17:46:49 -0700 Subject: [PATCH 04/11] Upgrade lots of other gems. --- Gemfile.lock | 74 +++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 128adc0c..397a1fbb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ GEM remote: https://rubygems.org/ specs: addressable (2.3.5) - appraisal (0.5.1) + appraisal (0.5.2) bundler rake archive-tar-minitar (0.5.2) @@ -15,8 +15,8 @@ GEM childprocess (>= 0.3.6) cucumber (>= 1.1.1) rspec-expectations (>= 2.7.0) - bouncy-castle-java (1.5.0146.1) - builder (3.2.0) + bouncy-castle-java (1.5.0147) + builder (3.2.2) childprocess (0.3.9) ffi (~> 1.0, >= 1.0.11) coderay (1.0.9) @@ -30,14 +30,13 @@ GEM gherkin (~> 2.9.0) json (>= 1.4.6) term-ansicolor (>= 1.0.6) - curb (0.8.3) - debugger (1.3.3) + curb (0.8.4) + debugger (1.6.1) columnize (>= 0.3.1) - debugger-linecache (~> 1.1.1) - debugger-ruby_core_source (~> 1.2.0) - debugger-linecache (1.1.2) - debugger-ruby_core_source (>= 1.1.1) - debugger-ruby_core_source (1.2.0) + debugger-linecache (~> 1.2.0) + debugger-ruby_core_source (~> 1.2.3) + debugger-linecache (1.2.0) + debugger-ruby_core_source (1.2.3) diff-lcs (1.2.4) em-http-request (1.0.3) addressable (>= 2.2.3) @@ -45,19 +44,19 @@ GEM em-socksify eventmachine (>= 1.0.0.beta.4) http_parser.rb (>= 0.5.3) - em-socksify (0.2.1) + em-socksify (0.3.0) eventmachine (>= 1.0.0.beta.4) - ethon (0.5.10) - ffi (~> 1.3.0) + ethon (0.6.1) + ffi (>= 1.3.0) mime-types (~> 1.18) - eventmachine (1.0.1) - eventmachine (1.0.1-java) + eventmachine (1.0.3) + eventmachine (1.0.3-java) excon (0.22.1) fakeweb (1.3.0) - faraday (0.8.6) - multipart-post (~> 1.1) - ffi (1.3.1) - ffi (1.3.1-java) + faraday (0.8.8) + multipart-post (~> 1.2.0) + ffi (1.9.0) + ffi (1.9.0-java) fuubar (1.0.0) rspec (~> 2.0) rspec-instafail (~> 0.2.0) @@ -72,35 +71,35 @@ GEM github-markup (0.7.5) http_parser.rb (0.5.3) http_parser.rb (0.5.3-java) - httpclient (2.3.3) - jruby-openssl (0.8.2) - bouncy-castle-java (>= 1.5.0146.1) + httpclient (2.3.4.1) + jruby-openssl (0.9.0) + bouncy-castle-java (>= 1.5.0147) json (1.6.8) json (1.6.8-java) linecache (0.46) rbx-require-relative (> 0.0.4) - method_source (0.8.1) - mime-types (1.21) + method_source (0.8.2) + mime-types (1.25) multi_json (1.0.4) multipart-post (1.2.0) patron (0.4.18) - pry (0.9.12) + pry (0.9.12.2) coderay (~> 1.0.5) method_source (~> 0.8) slop (~> 3.4) - pry (0.9.12-java) + pry (0.9.12.2-java) coderay (~> 1.0.5) method_source (~> 0.8) slop (~> 3.4) spoon (~> 0.0) rack (1.3.10) - rack-protection (1.4.0) + rack-protection (1.5.0) rack rake (0.9.6) rbx-require-relative (0.0.9) redcarpet (1.17.2) redis (2.2.2) - relish (0.6) + relish (0.7) archive-tar-minitar (>= 0.5.2) json (>= 1.4.6) rest-client (>= 1.6.1) @@ -122,7 +121,7 @@ GEM linecache (>= 0.3) ruby-debug-base (0.10.4-java) ruby-progressbar (0.0.10) - safe_yaml (0.9.4) + safe_yaml (0.9.7) shoulda (2.9.2) simplecov (0.5.4) multi_json (~> 1.0.3) @@ -132,18 +131,21 @@ GEM rack (~> 1.3, >= 1.3.6) rack-protection (~> 1.2) tilt (~> 1.3, >= 1.3.3) - slop (3.4.3) - spoon (0.0.1) - term-ansicolor (1.0.7) - tilt (1.3.4) + slop (3.4.6) + spoon (0.0.4) + ffi + term-ansicolor (1.2.2) + tins (~> 0.8) + tilt (1.4.1) timecop (0.3.5) - typhoeus (0.6.2) - ethon (~> 0.5.10) + tins (0.10.0) + typhoeus (0.6.5) + ethon (~> 0.6.1) webmock (1.13.0) addressable (>= 2.2.7) crack (>= 0.3.2) yajl-ruby (1.1.0) - yard (0.8.5.2) + yard (0.8.7.2) PLATFORMS java From 441abf5b4f0ccc031825f1fc0df3b98352181b3c Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Sat, 21 Sep 2013 18:00:51 -0700 Subject: [PATCH 05/11] Move away from `stub_chain`. --- spec/support/configuration_stubbing.rb | 8 ++++++ .../cassette/http_interaction_list_spec.rb | 2 +- spec/vcr/request_matcher_registry_spec.rb | 9 +++++-- spec/vcr/structs_spec.rb | 26 ++++++++++++++----- 4 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 spec/support/configuration_stubbing.rb diff --git a/spec/support/configuration_stubbing.rb b/spec/support/configuration_stubbing.rb new file mode 100644 index 00000000..909a245a --- /dev/null +++ b/spec/support/configuration_stubbing.rb @@ -0,0 +1,8 @@ +shared_context "configuration stubbing" do + let(:config) { double("VCR::Configuration") } + + before do + allow(VCR).to receive(:configuration) { config } + end +end + diff --git a/spec/vcr/cassette/http_interaction_list_spec.rb b/spec/vcr/cassette/http_interaction_list_spec.rb index 5d6a61ee..69516075 100644 --- a/spec/vcr/cassette/http_interaction_list_spec.rb +++ b/spec/vcr/cassette/http_interaction_list_spec.rb @@ -12,7 +12,7 @@ class Cassette before(:each) do allow(VCR).to receive(:request_matchers).and_return(VCR::RequestMatcherRegistry.new) - VCR.stub_chain(:configuration, :debug_logger).and_return(double.as_null_object) + allow(VCR.configuration).to receive(:debug_logger).and_return(double.as_null_object) end def request_with(values) diff --git a/spec/vcr/request_matcher_registry_spec.rb b/spec/vcr/request_matcher_registry_spec.rb index 73c85604..fc565f9d 100644 --- a/spec/vcr/request_matcher_registry_spec.rb +++ b/spec/vcr/request_matcher_registry_spec.rb @@ -2,11 +2,16 @@ require 'vcr/structs' require 'support/limited_uri' require 'cgi' +require 'support/configuration_stubbing' module VCR describe RequestMatcherRegistry do - before { VCR.stub_chain(:configuration, :uri_parser) { LimitedURI } } - before { VCR.stub_chain(:configuration, :query_parser) { CGI.method(:parse) } } + include_context "configuration stubbing" + + before do + allow(config).to receive(:uri_parser) { LimitedURI } + allow(config).to receive(:query_parser) { CGI.method(:parse) } + end def request_with(values) VCR::Request.new.tap do |request| diff --git a/spec/vcr/structs_spec.rb b/spec/vcr/structs_spec.rb index 3d123647..b8d63e5d 100644 --- a/spec/vcr/structs_spec.rb +++ b/spec/vcr/structs_spec.rb @@ -8,6 +8,7 @@ require 'zlib' require 'stringio' require 'support/limited_uri' +require 'support/configuration_stubbing' shared_examples_for "a header normalizer" do let(:instance) do @@ -61,7 +62,8 @@ module VCR describe HTTPInteraction do - before { VCR.stub_chain(:configuration, :uri_parser) { LimitedURI } } + include_context "configuration stubbing" + before { allow(config).to receive(:uri_parser) { LimitedURI } } if ''.respond_to?(:encoding) def body_hash(key, value) @@ -233,9 +235,11 @@ def verify_encoding_error end describe "#to_hash" do + include_context "configuration stubbing" + before(:each) do - VCR.stub_chain(:configuration, :preserve_exact_body_bytes_for?).and_return(false) - VCR.stub_chain(:configuration, :uri_parser).and_return(URI) + allow(config).to receive(:preserve_exact_body_bytes_for?).and_return(false) + allow(config).to receive(:uri_parser).and_return(URI) end let(:hash) { interaction.to_hash } @@ -275,7 +279,7 @@ def verify_encoding_error end it 'encodes the body as base64 when the configuration is so set' do - VCR.stub_chain(:configuration, :preserve_exact_body_bytes_for?).and_return(true) + allow(config).to receive(:preserve_exact_body_bytes_for?).and_return(true) expect(hash['request']['body']).to eq(body_hash('base64_string', Base64.encode64('req body'))) expect(hash['response']['body']).to eq(body_hash('base64_string', Base64.encode64('res body'))) end @@ -305,7 +309,7 @@ def assert_yielded_keys(hash, *keys) describe "#parsed_uri" do before :each do allow(uri_parser).to receive(:parse).and_return(uri) - VCR.stub_chain(:configuration, :uri_parser).and_return(uri_parser) + allow(config).to receive(:uri_parser).and_return(uri_parser) end let(:uri_parser){ double('parser') } @@ -323,7 +327,11 @@ def assert_yielded_keys(hash, *keys) end describe HTTPInteraction::HookAware do - before { VCR.stub_chain(:configuration, :uri_parser) { LimitedURI } } + include_context "configuration stubbing" + + before do + allow(config).to receive(:uri_parser) { LimitedURI } + end let(:response_status) { VCR::ResponseStatus.new(200, "OK foo") } let(:body) { "The body foo this is (foo-Foo)" } @@ -464,7 +472,11 @@ def assert_yielded_keys(hash, *keys) end describe Request do - before { VCR.stub_chain(:configuration, :uri_parser) { LimitedURI } } + include_context "configuration stubbing" + + before do + allow(config).to receive(:uri_parser) { LimitedURI } + end describe '#method' do subject { VCR::Request.new(:get) } From 37f5ae4ea1825732e42c65c28dd708aa212afedb Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Sat, 21 Sep 2013 18:01:01 -0700 Subject: [PATCH 06/11] Enforce use of new rspec-mocks syntax. --- spec/spec_helper.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 444acbeb..4cc9defb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -60,6 +60,10 @@ def reset!(hook = :fakeweb) expectations.syntax = :expect end + config.mock_with :rspec do |mocks| + mocks.syntax = :expect + end + tmp_dir = File.expand_path('../../tmp/cassette_library_dir', __FILE__) config.before(:each) do unless example.metadata[:skip_vcr_reset] From 038b7294195705361016eecdb1a472027056fc35 Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Sat, 21 Sep 2013 18:06:31 -0700 Subject: [PATCH 07/11] Update excon. Excon now includes a default user-agent. --- Gemfile.lock | 2 +- features/request_matching/headers.feature | 1 - spec/support/http_library_adapters.rb | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 397a1fbb..ceb4e89b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -51,7 +51,7 @@ GEM mime-types (~> 1.18) eventmachine (1.0.3) eventmachine (1.0.3-java) - excon (0.22.1) + excon (0.25.3) fakeweb (1.3.0) faraday (0.8.8) multipart-post (~> 1.2.0) diff --git a/features/request_matching/headers.feature b/features/request_matching/headers.feature index 31715df5..b9534b3b 100644 --- a/features/request_matching/headers.feature +++ b/features/request_matching/headers.feature @@ -83,5 +83,4 @@ Feature: Matching on Headers | c.hook_into :webmock | curb | | c.hook_into :webmock | patron | | c.hook_into :webmock | em-http-request | - | c.hook_into :excon | excon | diff --git a/spec/support/http_library_adapters.rb b/spec/support/http_library_adapters.rb index 8a47d9a8..2222b1a1 100644 --- a/spec/support/http_library_adapters.rb +++ b/spec/support/http_library_adapters.rb @@ -223,7 +223,7 @@ def make_http_request(method, url, body = nil, headers = {}) end def normalize_request_headers(headers) - headers + headers.merge('User-Agent' => [Excon::USER_AGENT]) end end From e243d01e392c42082e38540dc98dde70fc662925 Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Sat, 21 Sep 2013 18:21:59 -0700 Subject: [PATCH 08/11] Update typhoeus-old Gemfile.lock as well. --- gemfiles/typhoeus_old.gemfile.lock | 65 ++++++++++++++++-------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/gemfiles/typhoeus_old.gemfile.lock b/gemfiles/typhoeus_old.gemfile.lock index 81d86db5..71eb734c 100644 --- a/gemfiles/typhoeus_old.gemfile.lock +++ b/gemfiles/typhoeus_old.gemfile.lock @@ -6,43 +6,43 @@ PATH GEM remote: https://rubygems.org/ specs: - addressable (2.3.3) - appraisal (0.5.1) + addressable (2.3.5) + appraisal (0.5.2) bundler rake archive-tar-minitar (0.5.2) - aruba (0.4.11) - childprocess (>= 0.2.3) + aruba (0.5.3) + childprocess (>= 0.3.6) cucumber (>= 1.1.1) - ffi (>= 1.0.11) - rspec (>= 2.7.0) - builder (3.2.0) + rspec-expectations (>= 2.7.0) + builder (3.2.2) childprocess (0.3.9) ffi (~> 1.0, >= 1.0.11) cookiejar (0.3.0) - crack (0.3.2) + crack (0.4.1) + safe_yaml (~> 0.9.0) cucumber (1.1.9) builder (>= 2.1.2) diff-lcs (>= 1.1.2) gherkin (~> 2.9.0) json (>= 1.4.6) term-ansicolor (>= 1.0.6) - curb (0.8.3) - diff-lcs (1.2.1) + curb (0.8.4) + diff-lcs (1.2.4) em-http-request (1.0.3) addressable (>= 2.2.3) cookiejar em-socksify eventmachine (>= 1.0.0.beta.4) http_parser.rb (>= 0.5.3) - em-socksify (0.2.1) + em-socksify (0.3.0) eventmachine (>= 1.0.0.beta.4) - eventmachine (1.0.1) - excon (0.22.1) + eventmachine (1.0.3) + excon (0.25.3) fakeweb (1.3.0) - faraday (0.8.6) - multipart-post (~> 1.1) - ffi (1.3.1) + faraday (0.8.8) + multipart-post (~> 1.2.0) + ffi (1.9.0) fuubar (1.0.0) rspec (~> 2.0) rspec-instafail (~> 0.2.0) @@ -54,34 +54,35 @@ GEM json (>= 1.4.6) github-markup (0.7.5) http_parser.rb (0.5.3) - httpclient (2.3.3) + httpclient (2.3.4.1) json (1.6.8) - mime-types (1.21) + mime-types (1.25) multi_json (1.0.4) multipart-post (1.2.0) patron (0.4.18) rack (1.3.10) - rack-protection (1.4.0) + rack-protection (1.5.0) rack rake (0.9.6) redcarpet (1.17.2) redis (2.2.2) - relish (0.6) + relish (0.7) archive-tar-minitar (>= 0.5.2) json (>= 1.4.6) rest-client (>= 1.6.1) rest-client (1.6.7) mime-types (>= 1.16) - rspec (2.13.0) - rspec-core (~> 2.13.0) - rspec-expectations (~> 2.13.0) - rspec-mocks (~> 2.13.0) - rspec-core (2.13.0) - rspec-expectations (2.13.0) + rspec (2.14.1) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + rspec-core (2.14.5) + rspec-expectations (2.14.2) diff-lcs (>= 1.1.3, < 2.0) rspec-instafail (0.2.4) - rspec-mocks (2.13.0) + rspec-mocks (2.14.3) ruby-progressbar (0.0.10) + safe_yaml (0.9.7) shoulda (2.9.2) simplecov (0.5.4) multi_json (~> 1.0.3) @@ -91,9 +92,11 @@ GEM rack (~> 1.3, >= 1.3.6) rack-protection (~> 1.2) tilt (~> 1.3, >= 1.3.3) - term-ansicolor (1.0.7) - tilt (1.3.4) + term-ansicolor (1.2.2) + tins (~> 0.8) + tilt (1.4.1) timecop (0.3.5) + tins (0.10.0) typhoeus (0.4.2) ffi (~> 1.0) mime-types (~> 1.18) @@ -101,14 +104,14 @@ GEM addressable (>= 2.2.7) crack (>= 0.1.7) yajl-ruby (1.1.0) - yard (0.8.5.2) + yard (0.8.7.2) PLATFORMS ruby DEPENDENCIES appraisal - aruba (~> 0.4.11) + aruba (~> 0.5) bundler (>= 1.0.7) cucumber (~> 1.1.4) curb (~> 0.8.0) From 891a141d965c9a84df5df48d45ae874e6dc33324 Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Sat, 21 Sep 2013 18:23:31 -0700 Subject: [PATCH 09/11] This was Typhoeus::Hydra.stub, not rspec's stub. --- spec/vcr/library_hooks/typhoeus_0.4_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/vcr/library_hooks/typhoeus_0.4_spec.rb b/spec/vcr/library_hooks/typhoeus_0.4_spec.rb index 77eed5a9..df671f8b 100644 --- a/spec/vcr/library_hooks/typhoeus_0.4_spec.rb +++ b/spec/vcr/library_hooks/typhoeus_0.4_spec.rb @@ -16,7 +16,7 @@ def enable_real_connections def directly_stub_request(method, url, response_body) response = ::Typhoeus::Response.new(:code => 200, :body => response_body) - allow(::Typhoeus::Hydra).to receive(method, url).and_return(response) + ::Typhoeus::Hydra.stub(method, url).and_return(response) end it_behaves_like 'a hook into an HTTP library', :typhoeus, 'typhoeus 0.4' From 49f31166e30009f2576d92f5f3c95b79a770a689 Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Sat, 21 Sep 2013 19:11:07 -0700 Subject: [PATCH 10/11] Relax excon version check: 0.25 works fine. --- lib/vcr/middleware/excon.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vcr/middleware/excon.rb b/lib/vcr/middleware/excon.rb index a3198a87..d4e24e5d 100644 --- a/lib/vcr/middleware/excon.rb +++ b/lib/vcr/middleware/excon.rb @@ -2,7 +2,7 @@ require 'vcr/request_handler' require 'vcr/util/version_checker' -VCR::VersionChecker.new('Excon', Excon::VERSION, '0.22.0', '0.22').check_version! +VCR::VersionChecker.new('Excon', Excon::VERSION, '0.22.0', '0.25').check_version! module VCR # Contains middlewares for use with different libraries. From 85016b54332618083e35b6e49e580aaf6c010340 Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Sun, 22 Sep 2013 07:12:08 -0700 Subject: [PATCH 11/11] Ensure `SPEC_ROOT` is expanded. Our absolute dir spec depends on this. --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4cc9defb..924c75be 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -41,7 +41,7 @@ require "support/http_library_adapters" module VCR - SPEC_ROOT = File.dirname(__FILE__) + SPEC_ROOT = File.dirname(File.expand_path('.', __FILE__)) def reset!(hook = :fakeweb) instance_variables.each do |ivar|