diff --git a/test/unit/plugins/commands/box/command/add_test.rb b/test/unit/plugins/commands/box/command/add_test.rb index 23b109974..e874ab487 100644 --- a/test/unit/plugins/commands/box/command/add_test.rb +++ b/test/unit/plugins/commands/box/command/add_test.rb @@ -32,11 +32,11 @@ describe VagrantPlugins::CommandBox::Command::Add do let(:argv) { ["foo"] } it "executes the runner with the proper actions" do - action_runner.should_receive(:run).with do |action, **opts| + expect(action_runner).to receive(:run).with { |action, **opts| expect(opts[:box_name]).to be_nil expect(opts[:box_url]).to eq("foo") true - end + } subject.execute end @@ -46,11 +46,11 @@ describe VagrantPlugins::CommandBox::Command::Add do let(:argv) { ["foo", "bar"] } it "executes the runner with the proper actions" do - action_runner.should_receive(:run).with do |action, **opts| + expect(action_runner).to receive(:run).with { |action, **opts| expect(opts[:box_name]).to eq("foo") expect(opts[:box_url]).to eq("bar") true - end + } subject.execute end diff --git a/test/unit/plugins/commands/box/command/remove_test.rb b/test/unit/plugins/commands/box/command/remove_test.rb index a13fd30fb..67c4a0131 100644 --- a/test/unit/plugins/commands/box/command/remove_test.rb +++ b/test/unit/plugins/commands/box/command/remove_test.rb @@ -32,10 +32,10 @@ describe VagrantPlugins::CommandBox::Command::Remove do let(:argv) { ["foo"] } it "invokes the action runner" do - action_runner.should_receive(:run).with do |action, opts| + expect(action_runner).to receive(:run).with { |action, opts| expect(opts[:box_name]).to eq("foo") true - end + } subject.execute end @@ -45,11 +45,11 @@ describe VagrantPlugins::CommandBox::Command::Remove do let(:argv) { ["foo", "bar"] } it "uses the 2nd arg as a provider" do - action_runner.should_receive(:run).with do |action, opts| + expect(action_runner).to receive(:run).with { |action, opts| expect(opts[:box_name]).to eq("foo") expect(opts[:box_provider]).to eq("bar") true - end + } subject.execute end diff --git a/test/unit/plugins/commands/box/command/update_test.rb b/test/unit/plugins/commands/box/command/update_test.rb index 1ba9cdc2c..b41b82100 100644 --- a/test/unit/plugins/commands/box/command/update_test.rb +++ b/test/unit/plugins/commands/box/command/update_test.rb @@ -42,7 +42,7 @@ describe VagrantPlugins::CommandBox::Command::Update do it "doesn't update if they're up to date" do called = false - action_runner.stub(:run) do |callable, opts| + allow(action_runner).to receive(:run) do |callable, opts| if opts[:box_provider] called = true end @@ -79,7 +79,7 @@ describe VagrantPlugins::CommandBox::Command::Update do end action_called = false - action_runner.stub(:run) do |action, opts| + allow(action_runner).to receive(:run) do |action, opts| if opts[:box_provider] action_called = true expect(opts[:box_url]).to eq(metadata_url.to_s) @@ -98,7 +98,7 @@ describe VagrantPlugins::CommandBox::Command::Update do it "raises an error if there are multiple providers" do test_iso_env.box3("foo", "1.0", :vmware) - action_runner.should_receive(:run).never + expect(action_runner).to receive(:run).never expect { subject.execute }. to raise_error(Vagrant::Errors::BoxUpdateMultiProvider) @@ -133,7 +133,7 @@ describe VagrantPlugins::CommandBox::Command::Update do test_iso_env.box3("foo", "1.0", :vmware) action_called = false - action_runner.stub(:run) do |action, opts| + allow(action_runner).to receive(:run) do |action, opts| if opts[:box_provider] action_called = true expect(opts[:box_url]).to eq(metadata_url.to_s) @@ -150,7 +150,7 @@ describe VagrantPlugins::CommandBox::Command::Update do end it "raises an error if that provider doesn't exist" do - action_runner.should_receive(:run).never + expect(action_runner).to receive(:run).never expect { subject.execute }. to raise_error(Vagrant::Errors::BoxNotFoundWithProvider) @@ -161,7 +161,7 @@ describe VagrantPlugins::CommandBox::Command::Update do let(:argv) { ["--box", "nope"] } it "raises an exception" do - action_runner.should_receive(:run).never + expect(action_runner).to receive(:run).never expect { subject.execute }. to raise_error(Vagrant::Errors::BoxNotFound) @@ -171,7 +171,7 @@ describe VagrantPlugins::CommandBox::Command::Update do context "updating environment machines" do before do - subject.stub(:with_target_vms) { |&block| block.call machine } + allow(subject).to receive(:with_target_vms) { |&block| block.call machine } end let(:box) do @@ -183,18 +183,18 @@ describe VagrantPlugins::CommandBox::Command::Update do end it "ignores machines without boxes" do - action_runner.should_receive(:run).never + expect(action_runner).to receive(:run).never subject.execute end it "doesn't update boxes if they're up-to-date" do machine.stub(box: box) - box.should_receive(:has_update?). + expect(box).to receive(:has_update?). with(machine.config.vm.box_version). and_return(nil) - action_runner.should_receive(:run).never + expect(action_runner).to receive(:run).never subject.execute end @@ -221,17 +221,17 @@ describe VagrantPlugins::CommandBox::Command::Update do RAW machine.stub(box: box) - box.should_receive(:has_update?). + expect(box).to receive(:has_update?). with(machine.config.vm.box_version). and_return([md, md.version("1.1"), md.version("1.1").provider("virtualbox")]) - action_runner.should_receive(:run).with do |action, opts| + expect(action_runner).to receive(:run).with { |action, opts| expect(opts[:box_url]).to eq(box.metadata_url) expect(opts[:box_provider]).to eq("virtualbox") expect(opts[:box_version]).to eq("1.1") expect(opts[:ui]).to equal(machine.ui) true - end + } subject.execute end diff --git a/test/unit/plugins/commands/list-commands/command_test.rb b/test/unit/plugins/commands/list-commands/command_test.rb index 006396ba8..e8cc4ba56 100644 --- a/test/unit/plugins/commands/list-commands/command_test.rb +++ b/test/unit/plugins/commands/list-commands/command_test.rb @@ -28,11 +28,11 @@ describe VagrantPlugins::CommandListCommands::Command do commands[:bar] = [command_lambda("bar", 0), { primary: true }] commands[:baz] = [command_lambda("baz", 0), { primary: false }] - iso_env.ui.should_receive(:info).with do |message, opts| + expect(iso_env.ui).to receive(:info).with { |message, opts| expect(message).to include("foo") expect(message).to include("bar") expect(message).to include("baz") - end + } subject.execute end diff --git a/test/unit/plugins/commands/plugin/action/install_gem_test.rb b/test/unit/plugins/commands/plugin/action/install_gem_test.rb index df5362555..e038d6595 100644 --- a/test/unit/plugins/commands/plugin/action/install_gem_test.rb +++ b/test/unit/plugins/commands/plugin/action/install_gem_test.rb @@ -17,10 +17,10 @@ describe VagrantPlugins::CommandPlugin::Action::InstallGem do describe "#call" do it "should install the plugin" do spec = Gem::Specification.new - manager.should_receive(:install_plugin).with( + expect(manager).to receive(:install_plugin).with( "foo", version: nil, require: nil, sources: nil, verbose: false).once.and_return(spec) - app.should_receive(:call).with(env).once + expect(app).to receive(:call).with(env).once env[:plugin_name] = "foo" subject.call(env) @@ -28,10 +28,10 @@ describe VagrantPlugins::CommandPlugin::Action::InstallGem do it "should specify the version if given" do spec = Gem::Specification.new - manager.should_receive(:install_plugin).with( + expect(manager).to receive(:install_plugin).with( "foo", version: "bar", require: nil, sources: nil, verbose: false).once.and_return(spec) - app.should_receive(:call).with(env).once + expect(app).to receive(:call).with(env).once env[:plugin_name] = "foo" env[:plugin_version] = "bar" @@ -40,10 +40,10 @@ describe VagrantPlugins::CommandPlugin::Action::InstallGem do it "should specify the entrypoint if given" do spec = Gem::Specification.new - manager.should_receive(:install_plugin).with( + expect(manager).to receive(:install_plugin).with( "foo", version: "bar", require: "baz", sources: nil, verbose: false).once.and_return(spec) - app.should_receive(:call).with(env).once + expect(app).to receive(:call).with(env).once env[:plugin_entry_point] = "baz" env[:plugin_name] = "foo" @@ -53,10 +53,10 @@ describe VagrantPlugins::CommandPlugin::Action::InstallGem do it "should specify the sources if given" do spec = Gem::Specification.new - manager.should_receive(:install_plugin).with( + expect(manager).to receive(:install_plugin).with( "foo", version: nil, require: nil, sources: ["foo"], verbose: false).once.and_return(spec) - app.should_receive(:call).with(env).once + expect(app).to receive(:call).with(env).once env[:plugin_name] = "foo" env[:plugin_sources] = ["foo"] @@ -84,9 +84,9 @@ describe VagrantPlugins::CommandPlugin::Action::InstallGem do end it "should uninstall the plugin" do - action_runner.should_receive(:run).with do |action, newenv| + expect(action_runner).to receive(:run).with { |action, newenv| expect(newenv[:plugin_name]).to eql("foo") - end + } subject.recover(env) end diff --git a/test/unit/plugins/commands/plugin/action/plugin_exists_check_test.rb b/test/unit/plugins/commands/plugin/action/plugin_exists_check_test.rb index 3a442e9ae..cf157f92f 100644 --- a/test/unit/plugins/commands/plugin/action/plugin_exists_check_test.rb +++ b/test/unit/plugins/commands/plugin/action/plugin_exists_check_test.rb @@ -14,7 +14,7 @@ describe VagrantPlugins::CommandPlugin::Action::PluginExistsCheck do it "should raise an exception if the plugin doesn't exist" do manager.stub(installed_plugins: { "foo" => {} }) - app.should_not_receive(:call) + expect(app).not_to receive(:call) env[:plugin_name] = "bar" expect { subject.call(env) }. @@ -23,7 +23,7 @@ describe VagrantPlugins::CommandPlugin::Action::PluginExistsCheck do it "should call the app if the plugin is installed" do manager.stub(installed_plugins: { "bar" => {} }) - app.should_receive(:call).once.with(env) + expect(app).to receive(:call).once.with(env) env[:plugin_name] = "bar" subject.call(env) diff --git a/test/unit/plugins/commands/plugin/action/uninstall_plugin_test.rb b/test/unit/plugins/commands/plugin/action/uninstall_plugin_test.rb index ffe17122e..13d9dc134 100644 --- a/test/unit/plugins/commands/plugin/action/uninstall_plugin_test.rb +++ b/test/unit/plugins/commands/plugin/action/uninstall_plugin_test.rb @@ -15,8 +15,8 @@ describe VagrantPlugins::CommandPlugin::Action::UninstallPlugin do end it "uninstalls the specified plugin" do - manager.should_receive(:uninstall_plugin).with("bar").ordered - app.should_receive(:call).ordered + expect(manager).to receive(:uninstall_plugin).with("bar").ordered + expect(app).to receive(:call).ordered env[:plugin_name] = "bar" subject.call(env) diff --git a/test/unit/plugins/commands/plugin/action/update_gems_test.rb b/test/unit/plugins/commands/plugin/action/update_gems_test.rb index f92b26990..50e56267b 100644 --- a/test/unit/plugins/commands/plugin/action/update_gems_test.rb +++ b/test/unit/plugins/commands/plugin/action/update_gems_test.rb @@ -17,14 +17,14 @@ describe VagrantPlugins::CommandPlugin::Action::UpdateGems do describe "#call" do it "should update all plugins if none are specified" do - manager.should_receive(:update_plugins).with([]).once.and_return([]) - app.should_receive(:call).with(env).once + expect(manager).to receive(:update_plugins).with([]).once.and_return([]) + expect(app).to receive(:call).with(env).once subject.call(env) end it "should update specified plugins" do - manager.should_receive(:update_plugins).with(["foo"]).once.and_return([]) - app.should_receive(:call).with(env).once + expect(manager).to receive(:update_plugins).with(["foo"]).once.and_return([]) + expect(app).to receive(:call).with(env).once env[:plugin_name] = ["foo"] subject.call(env) diff --git a/test/unit/plugins/commands/ssh_config/command_test.rb b/test/unit/plugins/commands/ssh_config/command_test.rb index 4f5c51459..7e8b9be6e 100644 --- a/test/unit/plugins/commands/ssh_config/command_test.rb +++ b/test/unit/plugins/commands/ssh_config/command_test.rb @@ -31,12 +31,12 @@ describe VagrantPlugins::CommandSSHConfig::Command do before do machine.stub(ssh_info: ssh_info) - subject.stub(:with_target_vms) { |&block| block.call machine } + allow(subject).to receive(:with_target_vms) { |&block| block.call machine } end describe "execute" do it "prints out the ssh config for the given machine" do - subject.should_receive(:safe_puts).with(<<-SSHCONFIG) + expect(subject).to receive(:safe_puts).with(<<-SSHCONFIG) Host #{machine.name} HostName testhost.vagrant.dev User testuser @@ -51,34 +51,34 @@ Host #{machine.name} end it "turns on agent forwarding when it is configured" do - machine.stub(:ssh_info) { ssh_info.merge(:forward_agent => true) } - subject.should_receive(:safe_puts).with { |ssh_config| - ssh_config.should include("ForwardAgent yes") + allow(machine).to receive(:ssh_info) { ssh_info.merge(:forward_agent => true) } + expect(subject).to receive(:safe_puts).with { |ssh_config| + expect(ssh_config).to include("ForwardAgent yes") } subject.execute end it "turns on x11 forwarding when it is configured" do - machine.stub(:ssh_info) { ssh_info.merge(:forward_x11 => true) } - subject.should_receive(:safe_puts).with { |ssh_config| - ssh_config.should include("ForwardX11 yes") + allow(machine).to receive(:ssh_info) { ssh_info.merge(:forward_x11 => true) } + expect(subject).to receive(:safe_puts).with { |ssh_config| + expect(ssh_config).to include("ForwardX11 yes") } subject.execute end it "handles multiple private key paths" do - machine.stub(:ssh_info) { ssh_info.merge(:private_key_path => ["foo", "bar"]) } - subject.should_receive(:safe_puts).with { |ssh_config| - ssh_config.should include("IdentityFile foo") - ssh_config.should include("IdentityFile bar") + allow(machine).to receive(:ssh_info) { ssh_info.merge(:private_key_path => ["foo", "bar"]) } + expect(subject).to receive(:safe_puts).with { |ssh_config| + expect(ssh_config).to include("IdentityFile foo") + expect(ssh_config).to include("IdentityFile bar") } subject.execute end it "puts quotes around an identityfile path if it has a space" do - machine.stub(:ssh_info) { ssh_info.merge(:private_key_path => ["with a space"]) } - subject.should_receive(:safe_puts).with { |ssh_config| - ssh_config.should include('IdentityFile "with a space"') + allow(machine).to receive(:ssh_info) { ssh_info.merge(:private_key_path => ["with a space"]) } + expect(subject).to receive(:safe_puts).with { |ssh_config| + expect(ssh_config).to include('IdentityFile "with a space"') } subject.execute end diff --git a/test/unit/plugins/guests/debian/cap/change_host_name_test.rb b/test/unit/plugins/guests/debian/cap/change_host_name_test.rb index 83ba71016..76a1a48ba 100644 --- a/test/unit/plugins/guests/debian/cap/change_host_name_test.rb +++ b/test/unit/plugins/guests/debian/cap/change_host_name_test.rb @@ -10,7 +10,7 @@ describe "VagrantPlugins::GuestDebian::Cap::ChangeHostName" do let(:old_hostname) { 'oldhostname.olddomain.tld' } before do - machine.stub(:communicate).and_return(communicator) + allow(machine).to receive(:communicate).and_return(communicator) communicator.stub_command('hostname -f', stdout: old_hostname) end diff --git a/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb b/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb index c08525f02..663cfa298 100644 --- a/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb +++ b/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb @@ -9,7 +9,7 @@ describe "VagrantPlugins::GuestRedHat::Cap::ChangeHostName" do let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) } before do - machine.stub(:communicate).and_return(communicator) + allow(machine).to receive(:communicate).and_return(communicator) communicator.stub_command('hostname -f', stdout: old_hostname) communicator.expect_command('hostname -f') end @@ -61,7 +61,7 @@ describe "VagrantPlugins::GuestRedHat::Cap::ChangeHostName" do it "does more even when the provided hostname is not different" do described_class.change_host_name(machine, old_hostname) - communicator.received_commands.to_set.should_not == communicator.expected_commands.keys.to_set + expect(communicator.received_commands.to_set).not_to eq(communicator.expected_commands.keys.to_set) end end end diff --git a/test/unit/plugins/guests/support/shared/debian_like_host_name_examples.rb b/test/unit/plugins/guests/support/shared/debian_like_host_name_examples.rb index afa2e63e6..b7ae47929 100644 --- a/test/unit/plugins/guests/support/shared/debian_like_host_name_examples.rb +++ b/test/unit/plugins/guests/support/shared/debian_like_host_name_examples.rb @@ -11,7 +11,7 @@ shared_examples "a debian-like host name change" do it "does nothing when the provided hostname is not different" do described_class.change_host_name(machine, 'oldhostname.olddomain.tld') - communicator.received_commands.should == ['hostname -f'] + expect(communicator.received_commands).to eq(['hostname -f']) end describe "flipping out the old hostname in /etc/hosts" do @@ -36,7 +36,7 @@ shared_examples "a debian-like host name change" do modified_etc_hosts = original_etc_hosts.gsub(search, replace) - modified_etc_hosts.should == <<-RESULT.gsub(/^ */, '') + expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '') 127.0.0.1 localhost 127.0.1.1 newhostname.newdomain.tld newhostname RESULT @@ -56,7 +56,7 @@ shared_examples "a debian-like host name change" do modified_etc_hosts = original_etc_hosts.gsub(search, replace) - modified_etc_hosts.should == <<-RESULT.gsub(/^ */, '') + expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '') 127.0.0.1 localhost 127.0.1.1 newhostname.newdomain.tld newhostname @@ -79,7 +79,7 @@ shared_examples "a debian-like host name change" do modified_etc_hosts = original_etc_hosts.gsub(search, replace) - modified_etc_hosts.should == <<-RESULT.gsub(/^ */, '') + expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '') 127.0.0.1 localhost 127.0.1.1 newhostname.newdomain.tld newhostname RESULT diff --git a/test/unit/plugins/guests/support/shared/redhat_like_host_name_examples.rb b/test/unit/plugins/guests/support/shared/redhat_like_host_name_examples.rb index d72099589..1b4959449 100644 --- a/test/unit/plugins/guests/support/shared/redhat_like_host_name_examples.rb +++ b/test/unit/plugins/guests/support/shared/redhat_like_host_name_examples.rb @@ -51,12 +51,12 @@ shared_examples 'a full redhat-like host name change' do it "does nothing when the provided hostname is not different" do described_class.change_host_name(machine, old_hostname) - communicator.received_commands.to_set.should == communicator.expected_commands.keys.to_set + expect(communicator.received_commands.to_set).to eq(communicator.expected_commands.keys.to_set) end it "does more when the provided hostname is a similar version" do described_class.change_host_name(machine, similar_hostname) - communicator.received_commands.to_set.should_not == communicator.expected_commands.keys.to_set + expect(communicator.received_commands.to_set).not_to eq(communicator.expected_commands.keys.to_set) end end @@ -89,7 +89,7 @@ shared_examples 'inserting hostname in /etc/hosts' do modified_etc_hosts = original_etc_hosts.gsub(search, replace) - modified_etc_hosts.should == <<-RESULT.gsub(/^ */, '') + expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '') 127.0.0.1 newhostname.newdomain.tld newhostname localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 RESULT @@ -107,7 +107,7 @@ shared_examples 'inserting hostname in /etc/hosts' do modified_etc_hosts = original_etc_hosts.gsub(search, replace) - modified_etc_hosts.should == <<-RESULT.gsub(/^ */, '') + expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '') 127.0.0.1 newhostname localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 RESULT @@ -129,7 +129,7 @@ shared_examples 'swapping simple hostname in /etc/hosts' do modified_etc_hosts = original_etc_hosts.gsub(search, replace) - modified_etc_hosts.should == <<-RESULT.gsub(/^ */, '') + expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '') 127.0.0.1 newhostname.newdomain.tld newhostname localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 RESULT @@ -143,7 +143,7 @@ shared_examples 'swapping simple hostname in /etc/hosts' do modified_etc_hosts = original_etc_hosts.gsub(search, replace) - modified_etc_hosts.should == <<-RESULT.gsub(/^ */, '') + expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '') 127.0.0.1 newhostname.newdomain.tld newhostname oldhostname.nope localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 RESULT @@ -161,7 +161,7 @@ shared_examples 'swapping simple hostname in /etc/hosts' do modified_etc_hosts = original_etc_hosts.gsub(search, replace) - modified_etc_hosts.should == <<-RESULT.gsub(/^ */, '') + expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '') 127.0.0.1 newhostname localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 RESULT @@ -175,7 +175,7 @@ shared_examples 'swapping simple hostname in /etc/hosts' do modified_etc_hosts = original_etc_hosts.gsub(search, replace) - modified_etc_hosts.should == <<-RESULT.gsub(/^ */, '') + expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '') 127.0.0.1 newhostname oldhostname.nope localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 RESULT @@ -197,7 +197,7 @@ shared_examples 'swapping qualified hostname in /etc/hosts' do modified_etc_hosts = original_etc_hosts.gsub(search, replace) - modified_etc_hosts.should == <<-RESULT.gsub(/^ */, '') + expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '') 127.0.0.1 newhostname.newdomain.tld newhostname localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 RESULT @@ -211,7 +211,7 @@ shared_examples 'swapping qualified hostname in /etc/hosts' do modified_etc_hosts = original_etc_hosts.gsub(search, replace) - modified_etc_hosts.should == <<-RESULT.gsub(/^ */, '') + expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '') 127.0.0.1 newhostname.newdomain.tld newhostname oldhostname.nope localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 RESULT @@ -229,7 +229,7 @@ shared_examples 'swapping qualified hostname in /etc/hosts' do modified_etc_hosts = original_etc_hosts.gsub(search, replace) - modified_etc_hosts.should == <<-RESULT.gsub(/^ */, '') + expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '') 127.0.0.1 newhostname localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 RESULT @@ -243,7 +243,7 @@ shared_examples 'swapping qualified hostname in /etc/hosts' do modified_etc_hosts = original_etc_hosts.gsub(search, replace) - modified_etc_hosts.should == <<-RESULT.gsub(/^ */, '') + expect(modified_etc_hosts).to eq <<-RESULT.gsub(/^ */, '') 127.0.0.1 newhostname oldhostname.nope localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 RESULT diff --git a/test/unit/plugins/guests/ubuntu/cap/change_host_name_test.rb b/test/unit/plugins/guests/ubuntu/cap/change_host_name_test.rb index 2cc631e3d..15473ea3c 100644 --- a/test/unit/plugins/guests/ubuntu/cap/change_host_name_test.rb +++ b/test/unit/plugins/guests/ubuntu/cap/change_host_name_test.rb @@ -10,7 +10,7 @@ describe "VagrantPlugins::GuestUbuntu::Cap::ChangeHostName" do let(:old_hostname) {'oldhostname.olddomain.tld' } before do - machine.stub(:communicate).and_return(communicator) + allow(machine).to receive(:communicate).and_return(communicator) communicator.stub_command('hostname -f', stdout: old_hostname) end diff --git a/test/unit/plugins/providers/hyperv/config_test.rb b/test/unit/plugins/providers/hyperv/config_test.rb index 0aac992ab..5177dca59 100644 --- a/test/unit/plugins/providers/hyperv/config_test.rb +++ b/test/unit/plugins/providers/hyperv/config_test.rb @@ -1,18 +1,18 @@ -require_relative "../../../base" - -require Vagrant.source_root.join("plugins/providers/hyperv/config") - -describe VagrantPlugins::HyperV::Config do - describe "#ip_address_timeout" do - it "can be set" do - subject.ip_address_timeout = 180 - subject.finalize! - expect(subject.ip_address_timeout).to eq(180) - end - - it "defaults to a number" do - subject.finalize! - expect(subject.ip_address_timeout).to eq(120) - end - end -end +require_relative "../../../base" + +require Vagrant.source_root.join("plugins/providers/hyperv/config") + +describe VagrantPlugins::HyperV::Config do + describe "#ip_address_timeout" do + it "can be set" do + subject.ip_address_timeout = 180 + subject.finalize! + expect(subject.ip_address_timeout).to eq(180) + end + + it "defaults to a number" do + subject.finalize! + expect(subject.ip_address_timeout).to eq(120) + end + end +end diff --git a/test/unit/plugins/providers/hyperv/provider_test.rb b/test/unit/plugins/providers/hyperv/provider_test.rb index b0f1aeb16..1adeb04c3 100644 --- a/test/unit/plugins/providers/hyperv/provider_test.rb +++ b/test/unit/plugins/providers/hyperv/provider_test.rb @@ -56,7 +56,7 @@ describe VagrantPlugins::HyperV::Provider do it "calls an action to determine the ID" do machine.stub(id: "foo") - machine.should_receive(:action).with(:read_state). + expect(machine).to receive(:action).with(:read_state). and_return({ machine_state_id: :bar }) expect(subject.state.id).to eq(:bar) diff --git a/test/unit/plugins/providers/virtualbox/action/prepare_nfs_settings_test.rb b/test/unit/plugins/providers/virtualbox/action/prepare_nfs_settings_test.rb index 8ce3c603b..6353ea095 100644 --- a/test/unit/plugins/providers/virtualbox/action/prepare_nfs_settings_test.rb +++ b/test/unit/plugins/providers/virtualbox/action/prepare_nfs_settings_test.rb @@ -32,7 +32,7 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings do action = described_class.new(app, env) action.call(env) - called.should == true + expect(called).to eq(true) end context "with an nfs synced folder" do @@ -50,22 +50,22 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings do driver.stub(read_host_only_interfaces: [ {name: "vmnet2", ip: "1.2.3.4"}, ]) - driver.stub(:read_guest_ip).with(1).and_return("2.3.4.5") + allow(driver).to receive(:read_guest_ip).with(1).and_return("2.3.4.5") # override sleep to 0 so test does not take seconds retry_options = subject.retry_options - subject.stub(:retry_options).and_return(retry_options.merge(sleep: 0)) + allow(subject).to receive(:retry_options).and_return(retry_options.merge(sleep: 0)) end it "sets nfs_host_ip and nfs_machine_ip properly" do subject.call(env) - env[:nfs_host_ip].should == "1.2.3.4" - env[:nfs_machine_ip].should == "2.3.4.5" + expect(env[:nfs_host_ip]).to eq("1.2.3.4") + expect(env[:nfs_machine_ip]).to eq("2.3.4.5") end it "raises an error when no host only adapter is configured" do - driver.stub(:read_network_interfaces) {{}} + allow(driver).to receive(:read_network_interfaces) {{}} expect { subject.call(env) }. to raise_error(Vagrant::Errors::NFSNoHostonlyNetwork) @@ -76,16 +76,16 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings do lambda { raise Vagrant::Errors::VirtualBoxGuestPropertyNotFound, :guest_property => 'stub' }, lambda { "2.3.4.5" } ] - driver.stub(:read_guest_ip) { raise_then_return.shift.call } + allow(driver).to receive(:read_guest_ip) { raise_then_return.shift.call } subject.call(env) - env[:nfs_host_ip].should == "1.2.3.4" - env[:nfs_machine_ip].should == "2.3.4.5" + expect(env[:nfs_host_ip]).to eq("1.2.3.4") + expect(env[:nfs_machine_ip]).to eq("2.3.4.5") end it "raises an error informing the user of a bug when the guest IP cannot be found" do - driver.stub(:read_guest_ip) { + allow(driver).to receive(:read_guest_ip) { raise Vagrant::Errors::VirtualBoxGuestPropertyNotFound, :guest_property => 'stub' } @@ -96,14 +96,14 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings do it "allows statically configured guest IPs to work for NFS, even when guest property would fail" do env[:machine].config.vm.network :private_network, ip: "11.12.13.14" - driver.stub(:read_guest_ip) { + allow(driver).to receive(:read_guest_ip) { raise Vagrant::Errors::VirtualBoxGuestPropertyNotFound, :guest_property => "stub" } subject.call(env) - env[:nfs_host_ip].should == "1.2.3.4" - env[:nfs_machine_ip].should == ["11.12.13.14"] + expect(env[:nfs_host_ip]).to eq("1.2.3.4") + expect(env[:nfs_machine_ip]).to eq(["11.12.13.14"]) end end end diff --git a/test/unit/plugins/providers/virtualbox/action/prepare_nfs_valid_ids_test.rb b/test/unit/plugins/providers/virtualbox/action/prepare_nfs_valid_ids_test.rb index 23a2328a6..d6ed4cf9d 100644 --- a/test/unit/plugins/providers/virtualbox/action/prepare_nfs_valid_ids_test.rb +++ b/test/unit/plugins/providers/virtualbox/action/prepare_nfs_valid_ids_test.rb @@ -34,7 +34,7 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSValidIds do action = described_class.new(app, env) action.call(env) - called.should == true + expect(called).to eq(true) end it "sets nfs_valid_ids" do diff --git a/test/unit/plugins/providers/virtualbox/cap_test.rb b/test/unit/plugins/providers/virtualbox/cap_test.rb index 5513f18a1..baa7f610f 100644 --- a/test/unit/plugins/providers/virtualbox/cap_test.rb +++ b/test/unit/plugins/providers/virtualbox/cap_test.rb @@ -22,7 +22,7 @@ describe VagrantPlugins::ProviderVirtualBox::Cap do describe "#forwarded_ports" do it "returns all the forwarded ports" do - driver.should_receive(:read_forwarded_ports).and_return([ + expect(driver).to receive(:read_forwarded_ports).and_return([ [nil, nil, 123, 456], [nil, nil, 245, 245], ]) diff --git a/test/unit/plugins/providers/virtualbox/config_test.rb b/test/unit/plugins/providers/virtualbox/config_test.rb index 0429df31c..c17790c53 100644 --- a/test/unit/plugins/providers/virtualbox/config_test.rb +++ b/test/unit/plugins/providers/virtualbox/config_test.rb @@ -1,27 +1,29 @@ -require_relative "../../../base" - -require Vagrant.source_root.join("plugins/providers/virtualbox/config") - -describe VagrantPlugins::ProviderVirtualBox::Config do - context "defaults" do - before { subject.finalize! } - - its(:check_guest_additions) { should be_true } - its(:gui) { should be_false } - its(:name) { should be_nil } - - it "should have one NAT adapter" do - expect(subject.network_adapters).to eql({ - 1 => [:nat, {}], - }) - end - end - - describe "#network_adapter" do - it "configures additional adapters" do - subject.network_adapter(2, :bridged, auto_config: true) - expect(subject.network_adapters[2]).to eql( - [:bridged, auto_config: true]) - end - end -end +require_relative "../../../base" + +require Vagrant.source_root.join("plugins/providers/virtualbox/config") + +describe VagrantPlugins::ProviderVirtualBox::Config do + context "defaults" do + subject { VagrantPlugins::ProviderVirtualBox::Config.new } + + before { subject.finalize! } + + it { expect(subject.check_guest_additions).to be_true } + it { expect(subject.gui).to be_false } + it { expect(subject.name).to be_nil } + + it "should have one NAT adapter" do + expect(subject.network_adapters).to eql({ + 1 => [:nat, {}], + }) + end + end + + describe "#network_adapter" do + it "configures additional adapters" do + subject.network_adapter(2, :bridged, auto_config: true) + expect(subject.network_adapters[2]).to eql( + [:bridged, auto_config: true]) + end + end +end diff --git a/test/unit/plugins/providers/virtualbox/support/shared/virtualbox_driver_version_4_x_examples.rb b/test/unit/plugins/providers/virtualbox/support/shared/virtualbox_driver_version_4_x_examples.rb index 761e1bef7..cb84e2325 100644 --- a/test/unit/plugins/providers/virtualbox/support/shared/virtualbox_driver_version_4_x_examples.rb +++ b/test/unit/plugins/providers/virtualbox/support/shared/virtualbox_driver_version_4_x_examples.rb @@ -7,17 +7,17 @@ shared_examples "a version 4.x virtualbox driver" do |options| it "reads the guest property of the machine referenced by the UUID" do key = "/Foo/Bar" - subprocess.should_receive(:execute). + expect(subprocess).to receive(:execute). with("VBoxManage", "guestproperty", "get", uuid, key, an_instance_of(Hash)). and_return(subprocess_result(stdout: "Value: Baz\n")) - subject.read_guest_property(key).should == "Baz" + expect(subject.read_guest_property(key)).to eq("Baz") end it "raises a virtualBoxGuestPropertyNotFound exception when the value is not set" do key = "/Not/There" - subprocess.should_receive(:execute). + expect(subprocess).to receive(:execute). with("VBoxManage", "guestproperty", "get", uuid, key, an_instance_of(Hash)). and_return(subprocess_result(stdout: "No value set!")) @@ -30,13 +30,13 @@ shared_examples "a version 4.x virtualbox driver" do |options| it "reads the guest property for the provided adapter number" do key = "/VirtualBox/GuestInfo/Net/1/V4/IP" - subprocess.should_receive(:execute). + expect(subprocess).to receive(:execute). with("VBoxManage", "guestproperty", "get", uuid, key, an_instance_of(Hash)). and_return(subprocess_result(stdout: "Value: 127.1.2.3")) value = subject.read_guest_ip(1) - value.should == "127.1.2.3" + expect(value).to eq("127.1.2.3") end end end diff --git a/test/unit/plugins/providers/virtualbox/synced_folder_test.rb b/test/unit/plugins/providers/virtualbox/synced_folder_test.rb index 592de0955..93cec0a18 100644 --- a/test/unit/plugins/providers/virtualbox/synced_folder_test.rb +++ b/test/unit/plugins/providers/virtualbox/synced_folder_test.rb @@ -14,12 +14,12 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do describe "usable" do it "should be with virtualbox provider" do machine.stub(provider_name: :virtualbox) - subject.should be_usable(machine) + expect(subject).to be_usable(machine) end it "should not be with another provider" do machine.stub(provider_name: :vmware_fusion) - subject.should_not be_usable(machine) + expect(subject).not_to be_usable(machine) end end diff --git a/test/unit/plugins/provisioners/chef/provisioner/base_test.rb b/test/unit/plugins/provisioners/chef/provisioner/base_test.rb index 7f2861b13..6274ed317 100644 --- a/test/unit/plugins/provisioners/chef/provisioner/base_test.rb +++ b/test/unit/plugins/provisioners/chef/provisioner/base_test.rb @@ -15,18 +15,18 @@ describe VagrantPlugins::Chef::Provisioner::Base do let(:root_path) { "/my/root" } before do - machine.stub(:env).and_return(env) - env.stub(:root_path).and_return(root_path) + allow(machine).to receive(:env).and_return(env) + allow(env).to receive(:root_path).and_return(root_path) end it "returns absolute path as is" do - config.should_receive(:encrypted_data_bag_secret_key_path). + expect(config).to receive(:encrypted_data_bag_secret_key_path). and_return("/foo/bar") expect(subject.encrypted_data_bag_secret_key_path).to eq "/foo/bar" end it "returns relative path joined to root_path" do - config.should_receive(:encrypted_data_bag_secret_key_path). + expect(config).to receive(:encrypted_data_bag_secret_key_path). and_return("secret") expect(subject.encrypted_data_bag_secret_key_path).to eq "/my/root/secret" end @@ -34,14 +34,14 @@ describe VagrantPlugins::Chef::Provisioner::Base do describe "#guest_encrypted_data_bag_secret_key_path" do it "returns nil if host path is not configured" do - config.stub(:encrypted_data_bag_secret_key_path).and_return(nil) - config.stub(:provisioning_path).and_return("/tmp/foo") + allow(config).to receive(:encrypted_data_bag_secret_key_path).and_return(nil) + allow(config).to receive(:provisioning_path).and_return("/tmp/foo") expect(subject.guest_encrypted_data_bag_secret_key_path).to be_nil end it "returns path under config.provisioning_path" do - config.stub(:encrypted_data_bag_secret_key_path).and_return("secret") - config.stub(:provisioning_path).and_return("/tmp/foo") + allow(config).to receive(:encrypted_data_bag_secret_key_path).and_return("secret") + allow(config).to receive(:provisioning_path).and_return("/tmp/foo") expect(File.dirname(subject.guest_encrypted_data_bag_secret_key_path)). to eq "/tmp/foo" end diff --git a/test/unit/plugins/provisioners/shell/config_test.rb b/test/unit/plugins/provisioners/shell/config_test.rb index 8b05f452b..9827e66e8 100644 --- a/test/unit/plugins/provisioners/shell/config_test.rb +++ b/test/unit/plugins/provisioners/shell/config_test.rb @@ -17,7 +17,7 @@ describe "VagrantPlugins::Shell::Config" do result = subject.validate(machine) - result["shell provisioner"].should == [] + expect(result["shell provisioner"]).to eq([]) end it "passes with string args" do @@ -27,7 +27,7 @@ describe "VagrantPlugins::Shell::Config" do result = subject.validate(machine) - result["shell provisioner"].should == [] + expect(result["shell provisioner"]).to eq([]) end it "passes with fixnum args" do @@ -37,7 +37,7 @@ describe "VagrantPlugins::Shell::Config" do result = subject.validate(machine) - result["shell provisioner"].should == [] + expect(result["shell provisioner"]).to eq([]) end it "passes with array args" do @@ -47,7 +47,7 @@ describe "VagrantPlugins::Shell::Config" do result = subject.validate(machine) - result["shell provisioner"].should == [] + expect(result["shell provisioner"]).to eq([]) end it "returns an error if args is neither a string nor an array" do @@ -59,9 +59,9 @@ describe "VagrantPlugins::Shell::Config" do result = subject.validate(machine) - result["shell provisioner"].should == [ + expect(result["shell provisioner"]).to eq([ I18n.t("vagrant.provisioners.shell.args_bad_type") - ] + ]) end it "handles scalar array args" do @@ -71,7 +71,7 @@ describe "VagrantPlugins::Shell::Config" do result = subject.validate(machine) - result["shell provisioner"].should == [] + expect(result["shell provisioner"]).to eq([]) end it "returns an error if args is an array with non-scalar types" do @@ -81,9 +81,9 @@ describe "VagrantPlugins::Shell::Config" do result = subject.validate(machine) - result["shell provisioner"].should == [ + expect(result["shell provisioner"]).to eq([ I18n.t("vagrant.provisioners.shell.args_bad_type") - ] + ]) end end end diff --git a/test/unit/plugins/synced_folders/nfs/action_cleanup_test.rb b/test/unit/plugins/synced_folders/nfs/action_cleanup_test.rb index 3fc329238..fb2ea5c2a 100644 --- a/test/unit/plugins/synced_folders/nfs/action_cleanup_test.rb +++ b/test/unit/plugins/synced_folders/nfs/action_cleanup_test.rb @@ -27,14 +27,14 @@ describe VagrantPlugins::SyncedFolderNFS::ActionCleanup do end it "does nothing if there are no valid IDs" do - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end it "does nothing if the host doesn't support pruning NFS" do - host.stub(:capability?).with(:nfs_prune).and_return(false) - host.should_receive(:capability).never - app.should_receive(:call).with(env) + allow(host).to receive(:capability?).with(:nfs_prune).and_return(false) + expect(host).to receive(:capability).never + expect(app).to receive(:call).with(env) subject.call(env) end @@ -42,9 +42,9 @@ describe VagrantPlugins::SyncedFolderNFS::ActionCleanup do it "prunes the NFS entries if valid IDs are given" do env[:nfs_valid_ids] = [1,2,3] - host.stub(:capability?).with(:nfs_prune).and_return(true) - host.should_receive(:capability).with(:nfs_prune, machine.ui, [1,2,3]).ordered - app.should_receive(:call).with(env).ordered + allow(host).to receive(:capability?).with(:nfs_prune).and_return(true) + expect(host).to receive(:capability).with(:nfs_prune, machine.ui, [1,2,3]).ordered + expect(app).to receive(:call).with(env).ordered subject.call(env) end diff --git a/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb b/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb index 7da7cc9a8..bb8982b9f 100644 --- a/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb +++ b/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb @@ -43,7 +43,7 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do ] paths["/foo"].each do |data| - helper_class.should_receive(:rsync_single). + expect(helper_class).to receive(:rsync_single). with(data[:machine], data[:machine].ssh_info, data[:opts]). once end @@ -64,7 +64,7 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do ] paths["/foo"].each do |data| - helper_class.should_receive(:rsync_single). + expect(helper_class).to receive(:rsync_single). with(data[:machine], data[:machine].ssh_info, data[:opts]). once end @@ -85,7 +85,7 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do ] paths["/foo"].each do |data| - helper_class.should_receive(:rsync_single). + expect(helper_class).to receive(:rsync_single). with(data[:machine], data[:machine].ssh_info, data[:opts]). once end diff --git a/test/unit/plugins/synced_folders/rsync/command/rsync_test.rb b/test/unit/plugins/synced_folders/rsync/command/rsync_test.rb index 7f0cc50e8..4be389d9f 100644 --- a/test/unit/plugins/synced_folders/rsync/command/rsync_test.rb +++ b/test/unit/plugins/synced_folders/rsync/command/rsync_test.rb @@ -53,14 +53,14 @@ describe VagrantPlugins::SyncedFolderRSync::Command::Rsync do it "doesn't sync if communicator isn't ready and exits with 1" do communicator.stub(ready?: false) - helper_class.should_receive(:rsync_single).never + expect(helper_class).to receive(:rsync_single).never expect(subject.execute).to eql(1) end it "rsyncs each folder and exits successfully" do synced_folders[:rsync].each do |_, opts| - helper_class.should_receive(:rsync_single). + expect(helper_class).to receive(:rsync_single). with(machine, ssh_info, opts). ordered end diff --git a/test/unit/plugins/synced_folders/rsync/helper_test.rb b/test/unit/plugins/synced_folders/rsync/helper_test.rb index 7b2d7561e..4b92687ab 100644 --- a/test/unit/plugins/synced_folders/rsync/helper_test.rb +++ b/test/unit/plugins/synced_folders/rsync/helper_test.rb @@ -23,7 +23,7 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do machine.stub(guest: guest) # Don't do all the crazy Cygwin stuff - Vagrant::Util::Platform.stub(:cygwin_path) do |path, **opts| + allow(Vagrant::Util::Platform).to receive(:cygwin_path) do |path, **opts| path end end @@ -75,17 +75,17 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do it "doesn't call cygwin_path on non-Windows" do Vagrant::Util::Platform.stub(windows?: false) - Vagrant::Util::Platform.should_not_receive(:cygwin_path) + expect(Vagrant::Util::Platform).not_to receive(:cygwin_path) subject.rsync_single(machine, ssh_info, opts) end it "calls cygwin_path on Windows" do Vagrant::Util::Platform.stub(windows?: true) - Vagrant::Util::Platform.should_receive(:cygwin_path).and_return("foo") + expect(Vagrant::Util::Platform).to receive(:cygwin_path).and_return("foo") - Vagrant::Util::Subprocess.should_receive(:execute).with do |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| expect(args[args.length - 3]).to eql("foo/") - end + } subject.rsync_single(machine, ssh_info, opts) end @@ -103,11 +103,11 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do opts[:hostpath] = "/foo" opts[:guestpath] = "/bar" - Vagrant::Util::Subprocess.should_receive(:execute).with do |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| expected = Vagrant::Util::Platform.fs_real_path("/foo").to_s expect(args[args.length - 3]).to eql("#{expected}/") expect(args[args.length - 2]).to include("/bar") - end + } subject.rsync_single(machine, ssh_info, opts) end @@ -118,38 +118,38 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do hostpath_expanded = File.expand_path(opts[:hostpath], machine.env.root_path) - Vagrant::Util::Subprocess.should_receive(:execute).with do |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| expect(args[args.length - 3]).to eql("#{hostpath_expanded}/") expect(args[args.length - 2]).to include("/bar") - end + } subject.rsync_single(machine, ssh_info, opts) end end it "executes within the root path" do - Vagrant::Util::Subprocess.should_receive(:execute).with do |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| expect(args.last).to be_kind_of(Hash) opts = args.last expect(opts[:workdir]).to eql(machine.env.root_path.to_s) - end + } subject.rsync_single(machine, ssh_info, opts) end it "executes the rsync_pre capability first if it exists" do - guest.should_receive(:capability?).with(:rsync_pre).and_return(true) - guest.should_receive(:capability).with(:rsync_pre, opts).ordered - Vagrant::Util::Subprocess.should_receive(:execute).ordered.and_return(result) + expect(guest).to receive(:capability?).with(:rsync_pre).and_return(true) + expect(guest).to receive(:capability).with(:rsync_pre, opts).ordered + expect(Vagrant::Util::Subprocess).to receive(:execute).ordered.and_return(result) subject.rsync_single(machine, ssh_info, opts) end it "executes the rsync_post capability after if it exists" do - guest.should_receive(:capability?).with(:rsync_post).and_return(true) - Vagrant::Util::Subprocess.should_receive(:execute).ordered.and_return(result) - guest.should_receive(:capability).with(:rsync_post, opts).ordered + expect(guest).to receive(:capability?).with(:rsync_post).and_return(true) + expect(Vagrant::Util::Subprocess).to receive(:execute).ordered.and_return(result) + expect(guest).to receive(:capability).with(:rsync_post, opts).ordered subject.rsync_single(machine, ssh_info, opts) end @@ -158,11 +158,11 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do it "excludes files if given as a string" do opts[:exclude] = "foo" - Vagrant::Util::Subprocess.should_receive(:execute).with do |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| index = args.find_index("foo") expect(index).to be > 0 expect(args[index-1]).to eql("--exclude") - end + } subject.rsync_single(machine, ssh_info, opts) end @@ -170,7 +170,7 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do it "excludes multiple files" do opts[:exclude] = ["foo", "bar"] - Vagrant::Util::Subprocess.should_receive(:execute).with do |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| index = args.find_index("foo") expect(index).to be > 0 expect(args[index-1]).to eql("--exclude") @@ -178,7 +178,7 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do index = args.find_index("bar") expect(index).to be > 0 expect(args[index-1]).to eql("--exclude") - end + } subject.rsync_single(machine, ssh_info, opts) end @@ -186,14 +186,14 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do context "custom arguments" do it "uses the default arguments if not given" do - Vagrant::Util::Subprocess.should_receive(:execute).with do |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| expect(args[1]).to eq("--verbose") expect(args[2]).to eq("--archive") expect(args[3]).to eq("--delete") expected = Vagrant::Util::Platform.fs_real_path("/foo").to_s expect(args[args.length - 3]).to eql("#{expected}/") - end + } subject.rsync_single(machine, ssh_info, opts) end @@ -201,13 +201,13 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do it "uses the custom arguments if given" do opts[:args] = ["--verbose", "-z"] - Vagrant::Util::Subprocess.should_receive(:execute).with do |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| expect(args[1]).to eq("--verbose") expect(args[2]).to eq("-z") expected = Vagrant::Util::Platform.fs_real_path("/foo").to_s expect(args[args.length - 3]).to eql("#{expected}/") - end + } subject.rsync_single(machine, ssh_info, opts) end diff --git a/test/unit/plugins/synced_folders/rsync/synced_folder_test.rb b/test/unit/plugins/synced_folders/rsync/synced_folder_test.rb index 2dae9cb82..07d2d4b53 100644 --- a/test/unit/plugins/synced_folders/rsync/synced_folder_test.rb +++ b/test/unit/plugins/synced_folders/rsync/synced_folder_test.rb @@ -25,17 +25,17 @@ describe VagrantPlugins::SyncedFolderRSync::SyncedFolder do describe "#usable?" do it "is usable if rsync can be found" do - Vagrant::Util::Which.should_receive(:which).with("rsync").and_return(true) + expect(Vagrant::Util::Which).to receive(:which).with("rsync").and_return(true) expect(subject.usable?(machine)).to be_true end it "is not usable if rsync cant be found" do - Vagrant::Util::Which.should_receive(:which).with("rsync").and_return(false) + expect(Vagrant::Util::Which).to receive(:which).with("rsync").and_return(false) expect(subject.usable?(machine)).to be_false end it "raises an exception if asked to" do - Vagrant::Util::Which.should_receive(:which).with("rsync").and_return(false) + expect(Vagrant::Util::Which).to receive(:which).with("rsync").and_return(false) expect { subject.usable?(machine, true) }. to raise_error(Vagrant::Errors::RSyncNotFound) end @@ -48,7 +48,7 @@ describe VagrantPlugins::SyncedFolderRSync::SyncedFolder do before do machine.stub(ssh_info: ssh_info) - guest.stub(:capability?).with(:rsync_installed) + allow(guest).to receive(:capability?).with(:rsync_installed) end it "rsyncs each folder" do @@ -58,7 +58,7 @@ describe VagrantPlugins::SyncedFolderRSync::SyncedFolder do ] folders.each do |_, opts| - helper_class.should_receive(:rsync_single). + expect(helper_class).to receive(:rsync_single). with(machine, ssh_info, opts). ordered end @@ -69,10 +69,10 @@ describe VagrantPlugins::SyncedFolderRSync::SyncedFolder do it "installs rsync if capable" do folders = [ [:foo, {}] ] - helper_class.stub(:rsync_single) + allow(helper_class).to receive(:rsync_single) - guest.stub(:capability?).with(:rsync_installed).and_return(true) - guest.stub(:capability?).with(:rsync_install).and_return(true) + allow(guest).to receive(:capability?).with(:rsync_installed).and_return(true) + allow(guest).to receive(:capability?).with(:rsync_install).and_return(true) expect(guest).to receive(:capability).with(:rsync_installed).and_return(false) expect(guest).to receive(:capability).with(:rsync_install) @@ -83,10 +83,10 @@ describe VagrantPlugins::SyncedFolderRSync::SyncedFolder do it "errors if rsync not installable" do folders = [ [:foo, {}] ] - helper_class.stub(:rsync_single) + allow(helper_class).to receive(:rsync_single) - guest.stub(:capability?).with(:rsync_installed).and_return(true) - guest.stub(:capability?).with(:rsync_install).and_return(false) + allow(guest).to receive(:capability?).with(:rsync_installed).and_return(true) + allow(guest).to receive(:capability?).with(:rsync_install).and_return(false) expect(guest).to receive(:capability).with(:rsync_installed).and_return(false) diff --git a/test/unit/support/shared/virtualbox_context.rb b/test/unit/support/shared/virtualbox_context.rb index 13f3d16bc..1909ccdc9 100644 --- a/test/unit/support/shared/virtualbox_context.rb +++ b/test/unit/support/shared/virtualbox_context.rb @@ -20,12 +20,12 @@ shared_context "virtualbox" do # drivers will blow up on instantiation if they cannot determine the # virtualbox version, so wire this stub in automatically - subprocess.stub(:execute). + allow(subprocess).to receive(:execute). with("VBoxManage", "--version", an_instance_of(Hash)). and_return(subprocess_result(stdout: vbox_version)) # drivers also call vm_exists? during init; - subprocess.stub(:execute). + allow(subprocess).to receive(:execute). with("VBoxManage", "showvminfo", kind_of(String), kind_of(Hash)). and_return(subprocess_result(exit_code: 0)) end diff --git a/test/unit/vagrant/action/builder_test.rb b/test/unit/vagrant/action/builder_test.rb index 50d80eb37..dfc20654a 100644 --- a/test/unit/vagrant/action/builder_test.rb +++ b/test/unit/vagrant/action/builder_test.rb @@ -19,7 +19,7 @@ describe Vagrant::Action::Builder do context "copying" do it "should copy the stack" do copy = subject.dup - copy.stack.object_id.should_not == subject.stack.object_id + expect(copy.stack.object_id).not_to eq(subject.stack.object_id) end end @@ -31,7 +31,7 @@ describe Vagrant::Action::Builder do subject = described_class.build(proc) subject.call(data) - data[:data].should == true + expect(data[:data]).to eq(true) end end @@ -43,7 +43,7 @@ describe Vagrant::Action::Builder do subject.use proc subject.call(data) - data[:data].should == true + expect(data[:data]).to eq(true) end it "should be able to add multiple items" do @@ -55,8 +55,8 @@ describe Vagrant::Action::Builder do subject.use proc2 subject.call(data) - data[:one].should == true - data[:two].should == true + expect(data[:one]).to eq(true) + expect(data[:two]).to eq(true) end it "should be able to add another builder" do @@ -73,7 +73,7 @@ describe Vagrant::Action::Builder do # Call the 2nd and verify results two.call(data) - data[:one].should == true + expect(data[:one]).to eq(true) end end @@ -83,7 +83,7 @@ describe Vagrant::Action::Builder do subject.insert(0, appender_proc(2)) subject.call(data) - data[:data].should == [2, 1] + expect(data[:data]).to eq([2, 1]) end it "can insert by name" do @@ -96,7 +96,7 @@ describe Vagrant::Action::Builder do subject.insert_before :bar, appender_proc(3) subject.call(data) - data[:data].should == [1, 3, 2] + expect(data[:data]).to eq([1, 3, 2]) end it "can insert next to a previous object" do @@ -106,7 +106,7 @@ describe Vagrant::Action::Builder do subject.insert(proc2, appender_proc(3)) subject.call(data) - data[:data].should == [1, 3, 2] + expect(data[:data]).to eq([1, 3, 2]) end it "can insert before" do @@ -114,7 +114,7 @@ describe Vagrant::Action::Builder do subject.insert_before 0, appender_proc(2) subject.call(data) - data[:data].should == [2, 1] + expect(data[:data]).to eq([2, 1]) end it "can insert after" do @@ -123,7 +123,7 @@ describe Vagrant::Action::Builder do subject.insert_after 0, appender_proc(2) subject.call(data) - data[:data].should == [1, 2, 3] + expect(data[:data]).to eq([1, 2, 3]) end it "merges middleware stacks of other builders" do @@ -152,7 +152,7 @@ describe Vagrant::Action::Builder do subject.insert(proc2, builder) subject.call(data) - data[:data].should == [1, "A1", "B1", 2, "B2", "A2"] + expect(data[:data]).to eq([1, "A1", "B1", 2, "B2", "A2"]) end it "raises an exception if an invalid object given for insert" do @@ -175,7 +175,7 @@ describe Vagrant::Action::Builder do subject.replace proc1, proc2 subject.call(data) - data[:data].should == [2] + expect(data[:data]).to eq([2]) end it "can replace by index" do @@ -186,7 +186,7 @@ describe Vagrant::Action::Builder do subject.replace 0, proc2 subject.call(data) - data[:data].should == [2] + expect(data[:data]).to eq([2]) end end @@ -199,7 +199,7 @@ describe Vagrant::Action::Builder do subject.delete proc1 subject.call(data) - data[:data].should == [2] + expect(data[:data]).to eq([2]) end it "can delete by index" do @@ -210,14 +210,14 @@ describe Vagrant::Action::Builder do subject.delete 0 subject.call(data) - data[:data].should == [2] + expect(data[:data]).to eq([2]) end end describe "action hooks" do it "applies them properly" do hook = double("hook") - hook.stub(:apply) do |builder| + allow(hook).to receive(:apply) do |builder| builder.use appender_proc(2) end @@ -226,13 +226,13 @@ describe Vagrant::Action::Builder do subject.use appender_proc(1) subject.call(data) - data[:data].should == [1, 2] - data[:action_hooks_already_ran].should == true + expect(data[:data]).to eq([1, 2]) + expect(data[:action_hooks_already_ran]).to eq(true) end it "applies without prepend/append if it has already" do hook = double("hook") - hook.should_receive(:apply).with(anything, { :no_prepend_or_append => true }).once + expect(hook).to receive(:apply).with(anything, { :no_prepend_or_append => true }).once data[:action_hooks] = [hook] data[:action_hooks_already_ran] = true diff --git a/test/unit/vagrant/action/builtin/box_add_test.rb b/test/unit/vagrant/action/builtin/box_add_test.rb index 584a9c95e..e59682fae 100644 --- a/test/unit/vagrant/action/builtin/box_add_test.rb +++ b/test/unit/vagrant/action/builtin/box_add_test.rb @@ -66,15 +66,15 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_name] = "foo" env[:box_url] = box_path.to_s - box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(box_collection).to receive(:add).with { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo") expect(version).to eq("0") expect(opts[:metadata_url]).to be_nil true - end.and_return(box) + }.and_return(box) - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end @@ -88,15 +88,15 @@ describe Vagrant::Action::Builtin::BoxAdd do box_path.to_s, ] - box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(box_collection).to receive(:add).with { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo") expect(version).to eq("0") expect(opts[:metadata_url]).to be_nil true - end.and_return(box) + }.and_return(box) - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end @@ -107,15 +107,15 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_name] = "foo" env[:box_url] = "http://127.0.0.1:#{port}/#{box_path.basename}" - box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(box_collection).to receive(:add).with { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo") expect(version).to eq("0") expect(opts[:metadata_url]).to be_nil true - end.and_return(box) + }.and_return(box) - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end @@ -126,8 +126,8 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_url] = box_path.to_s - box_collection.should_receive(:add).never - app.should_receive(:call).never + expect(box_collection).to receive(:add).never + expect(app).to receive(:call).never expect { subject.call(env) }. to raise_error(Vagrant::Errors::BoxAddNameRequired) @@ -140,10 +140,10 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_url] = box_path.to_s env[:box_provider] = "virtualbox" - box_collection.should_receive(:find).with( + expect(box_collection).to receive(:find).with( "foo", ["virtualbox"], "0").and_return(box) - box_collection.should_receive(:add).never - app.should_receive(:call).never + expect(box_collection).to receive(:add).never + expect(app).to receive(:call).never expect { subject.call(env) }. to raise_error(Vagrant::Errors::BoxAlreadyExists) @@ -157,8 +157,8 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_checksum] = checksum(box_path) + "A" env[:box_checksum_type] = "sha1" - box_collection.should_receive(:add).never - app.should_receive(:call).never + expect(box_collection).to receive(:add).never + expect(app).to receive(:call).never expect { subject.call(env) }. to raise_error(Vagrant::Errors::BoxChecksumMismatch) @@ -170,8 +170,8 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_name] = "foo" env[:box_url] = box_path.to_s + "nope" - box_collection.should_receive(:add).never - app.should_receive(:call).never + expect(box_collection).to receive(:add).never + expect(app).to receive(:call).never expect { subject.call(env) }. to raise_error(Vagrant::Errors::DownloaderError) @@ -186,14 +186,14 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_provider] = "virtualbox" box_collection.stub(find: box) - box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(box_collection).to receive(:add).with { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo") expect(version).to eq("0") expect(opts[:metadata_url]).to be_nil true - end.and_return(box) - app.should_receive(:call).with(env).once + }.and_return(box) + expect(app).to receive(:call).with(env).once subject.call(env) end @@ -229,15 +229,15 @@ describe Vagrant::Action::Builtin::BoxAdd do with_web_server(md_path) do |port| env[:box_url] = "http://127.0.0.1:#{port}/#{md_path.basename}" - box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(box_collection).to receive(:add).with { |path, name, version, **opts| expect(name).to eq("foo/bar") expect(version).to eq("0.7") expect(checksum(path)).to eq(checksum(box_path)) expect(opts[:metadata_url]).to eq(env[:box_url]) true - end.and_return(box) + }.and_return(box) - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end @@ -274,16 +274,16 @@ describe Vagrant::Action::Builtin::BoxAdd do url = "http://127.0.0.1:#{port}" env[:box_url] = "mitchellh/precise64.json" - box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(box_collection).to receive(:add).with { |path, name, version, **opts| expect(name).to eq("mitchellh/precise64") expect(version).to eq("0.7") expect(checksum(path)).to eq(checksum(box_path)) expect(opts[:metadata_url]).to eq( "#{url}/#{env[:box_url]}") true - end.and_return(box) + }.and_return(box) - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) with_temp_env("VAGRANT_SERVER_URL" => url) do subject.call(env) @@ -324,7 +324,7 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_url] = "foo" env[:hook] = double("hook") - env[:hook].stub(:call) do |name, opts| + allow(env[:hook]).to receive(:call) do |name, opts| expect(name).to eq(:authenticate_box_url) if opts[:box_urls] == ["foo"] next { box_urls: [real_url] } @@ -335,15 +335,15 @@ describe Vagrant::Action::Builtin::BoxAdd do end end - box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(box_collection).to receive(:add).with { |path, name, version, **opts| expect(name).to eq("foo/bar") expect(version).to eq("0.7") expect(checksum(path)).to eq(checksum(box_path)) expect(opts[:metadata_url]).to eq(env[:box_url]) true - end.and_return(box) + }.and_return(box) - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end @@ -380,15 +380,15 @@ describe Vagrant::Action::Builtin::BoxAdd do with_web_server(md_path) do |port| env[:box_url] = "http://127.0.0.1:#{port}/#{md_path.basename}" - box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(box_collection).to receive(:add).with { |path, name, version, **opts| expect(name).to eq("foo/bar") expect(version).to eq("0.7") expect(checksum(path)).to eq(checksum(box_path)) expect(opts[:metadata_url]).to eq(env[:box_url]) true - end.and_return(box) + }.and_return(box) - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end @@ -425,8 +425,8 @@ describe Vagrant::Action::Builtin::BoxAdd do with_web_server(md_path) do |port| env[:box_url] = "http://127.0.0.1:#{port}/#{md_path.basename}" - box_collection.should_receive(:add).never - app.should_receive(:call).never + expect(box_collection).to receive(:add).never + expect(app).to receive(:call).never expect { subject.call(env) }. to raise_error(Vagrant::Errors::BoxChecksumMismatch) @@ -439,8 +439,8 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_url] = "mitchellh/precise64.json" - box_collection.should_receive(:add).never - app.should_receive(:call).never + expect(box_collection).to receive(:add).never + expect(app).to receive(:call).never Vagrant.stub(server_url: nil) @@ -455,8 +455,8 @@ describe Vagrant::Action::Builtin::BoxAdd do with_web_server(Pathname.new(tf.path)) do |port| env[:box_url] = "mitchellh/precise64.json" - box_collection.should_receive(:add).never - app.should_receive(:call).never + expect(box_collection).to receive(:add).never + expect(app).to receive(:call).never url = "http://127.0.0.1:#{port}" with_temp_env("VAGRANT_SERVER_URL" => url) do @@ -495,8 +495,8 @@ describe Vagrant::Action::Builtin::BoxAdd do "/foo/bar/baz", tf.path, ] - box_collection.should_receive(:add).never - app.should_receive(:call).never + expect(box_collection).to receive(:add).never + expect(app).to receive(:call).never expect { subject.call(env) }. to raise_error(Vagrant::Errors::BoxAddMetadataMultiURL) @@ -528,15 +528,15 @@ describe Vagrant::Action::Builtin::BoxAdd do end env[:box_url] = tf.path - box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(box_collection).to receive(:add).with { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo/bar") expect(version).to eq("0.7") expect(opts[:metadata_url]).to eq("file://#{tf.path}") true - end.and_return(box) + }.and_return(box) - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end @@ -572,15 +572,15 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_url] = tf.path env[:box_provider] = "vmware" - box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(box_collection).to receive(:add).with { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo/bar") expect(version).to eq("0.7") expect(opts[:metadata_url]).to eq("file://#{tf.path}") true - end.and_return(box) + }.and_return(box) - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) @@ -621,15 +621,15 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_url] = tf.path env[:box_provider] = "vmware" - box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(box_collection).to receive(:add).with { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo/bar") expect(version).to eq("0.7") expect(opts[:metadata_url]).to eq("file://#{tf.path}") true - end.and_return(box) + }.and_return(box) - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) @@ -661,15 +661,15 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_url] = tf.path env[:box_version] = "~> 0.1" - box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(box_collection).to receive(:add).with { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo/bar") expect(version).to eq("0.5") expect(opts[:metadata_url]).to eq("file://#{tf.path}") true - end.and_return(box) + }.and_return(box) - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) @@ -706,15 +706,15 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_url] = tf.path env[:box_provider] = "vmware" env[:box_version] = "~> 0.1" - box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(box_collection).to receive(:add).with { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo/bar") expect(version).to eq("0.5") expect(opts[:metadata_url]).to eq("file://#{tf.path}") true - end.and_return(box) + }.and_return(box) - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) @@ -754,15 +754,15 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_url] = tf.path env[:box_provider] = ["virtualbox", "vmware"] - box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(box_collection).to receive(:add).with { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo/bar") expect(version).to eq("0.7") expect(opts[:metadata_url]).to eq("file://#{tf.path}") true - end.and_return(box) + }.and_return(box) - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) @@ -800,17 +800,17 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_url] = tf.path - env[:ui].should_receive(:ask).and_return("1") + expect(env[:ui]).to receive(:ask).and_return("1") - box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(box_collection).to receive(:add).with { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo/bar") expect(version).to eq("0.7") expect(opts[:metadata_url]).to eq("file://#{tf.path}") true - end.and_return(box) + }.and_return(box) - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end @@ -843,8 +843,8 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_name] = "foo" env[:box_url] = tf.path - box_collection.should_receive(:add).never - app.should_receive(:call).never + expect(box_collection).to receive(:add).never + expect(app).to receive(:call).never expect { subject.call(env) }. to raise_error(Vagrant::Errors::BoxAddNameMismatch) @@ -875,8 +875,8 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_url] = tf.path env[:box_version] = "~> 2.0" - box_collection.should_receive(:add).never - app.should_receive(:call).never + expect(box_collection).to receive(:add).never + expect(app).to receive(:call).never expect { subject.call(env) }. to raise_error(Vagrant::Errors::BoxAddNoMatchingVersion) @@ -908,8 +908,8 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_url] = tf.path env[:box_provider] = "vmware" - box_collection.should_receive(:add).never - app.should_receive(:call).never + expect(box_collection).to receive(:add).never + expect(app).to receive(:call).never expect { subject.call(env) }. to raise_error(Vagrant::Errors::BoxAddNoMatchingProvider) @@ -941,10 +941,10 @@ describe Vagrant::Action::Builtin::BoxAdd do end env[:box_url] = tf.path - box_collection.should_receive(:find). + expect(box_collection).to receive(:find). with("foo/bar", "virtualbox", "0.7").and_return(box) - box_collection.should_receive(:add).never - app.should_receive(:call).never + expect(box_collection).to receive(:add).never + expect(app).to receive(:call).never expect { subject.call(env) }. to raise_error(Vagrant::Errors::BoxAlreadyExists) @@ -978,16 +978,16 @@ describe Vagrant::Action::Builtin::BoxAdd do env[:box_force] = true env[:box_url] = tf.path box_collection.stub(find: box) - box_collection.should_receive(:add).with do |path, name, version, **opts| + expect(box_collection).to receive(:add).with { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo/bar") expect(version).to eq("0.7") expect(opts[:force]).to be_true expect(opts[:metadata_url]).to eq("file://#{tf.path}") true - end.and_return(box) + }.and_return(box) - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) diff --git a/test/unit/vagrant/action/builtin/box_check_outdated_test.rb b/test/unit/vagrant/action/builtin/box_check_outdated_test.rb index 32dcdac0e..0bb133549 100644 --- a/test/unit/vagrant/action/builtin/box_check_outdated_test.rb +++ b/test/unit/vagrant/action/builtin/box_check_outdated_test.rb @@ -42,7 +42,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do it "doesn't check" do machine.config.vm.box_check_update = false - app.should_receive(:call).with(env).once + expect(app).to receive(:call).with(env).once subject.call(env) @@ -53,7 +53,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do machine.config.vm.box_check_update = false env[:box_outdated_force] = true - app.should_receive(:call).with(env).once + expect(app).to receive(:call).with(env).once subject.call(env) @@ -65,7 +65,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do it "raises an exception if the machine doesn't have a box yet" do machine.stub(box: nil) - app.should_receive(:call).never + expect(app).to receive(:call).never expect { subject.call(env) }. to raise_error(Vagrant::Errors::BoxOutdatedNoBox) @@ -77,8 +77,8 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do box.stub(metadata_url: nil) box.stub(version: "0") - app.should_receive(:call).once - box.should_receive(:has_update?).never + expect(app).to receive(:call).once + expect(box).to receive(:has_update?).never subject.call(env) end @@ -86,9 +86,9 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do context "with a box" do it "sets env if no update" do - box.should_receive(:has_update?).and_return(nil) + expect(box).to receive(:has_update?).and_return(nil) - app.should_receive(:call).with(env).once + expect(app).to receive(:call).with(env).once subject.call(env) @@ -116,10 +116,10 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do } RAW - box.should_receive(:has_update?).with(machine.config.vm.box_version). + expect(box).to receive(:has_update?).with(machine.config.vm.box_version). and_return([md, md.version("1.1"), md.version("1.1").provider("virtualbox")]) - app.should_receive(:call).with(env).once + expect(app).to receive(:call).with(env).once subject.call(env) @@ -127,9 +127,9 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do end it "raises error if has_update? errors" do - box.should_receive(:has_update?).and_raise(Vagrant::Errors::VagrantError) + expect(box).to receive(:has_update?).and_raise(Vagrant::Errors::VagrantError) - app.should_receive(:call).never + expect(app).to receive(:call).never expect { subject.call(env) }.to raise_error(Vagrant::Errors::VagrantError) end @@ -137,8 +137,8 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do it "doesn't raise an error if ignore errors is on" do env[:box_outdated_ignore_errors] = true - box.should_receive(:has_update?).and_raise(Vagrant::Errors::VagrantError) - app.should_receive(:call).with(env).once + expect(box).to receive(:has_update?).and_raise(Vagrant::Errors::VagrantError) + expect(app).to receive(:call).with(env).once expect { subject.call(env) }.to_not raise_error end diff --git a/test/unit/vagrant/action/builtin/box_remove_test.rb b/test/unit/vagrant/action/builtin/box_remove_test.rb index 19a15b3f3..016a11749 100644 --- a/test/unit/vagrant/action/builtin/box_remove_test.rb +++ b/test/unit/vagrant/action/builtin/box_remove_test.rb @@ -24,10 +24,10 @@ describe Vagrant::Action::Builtin::BoxRemove do env[:box_name] = "foo" - box_collection.should_receive(:find).with( + expect(box_collection).to receive(:find).with( "foo", :virtualbox, "1.0").and_return(box) - box.should_receive(:destroy!).once - app.should_receive(:call).with(env).once + expect(box).to receive(:destroy!).once + expect(app).to receive(:call).with(env).once subject.call(env) @@ -44,10 +44,10 @@ describe Vagrant::Action::Builtin::BoxRemove do env[:box_name] = "foo" env[:box_provider] = "virtualbox" - box_collection.should_receive(:find).with( + expect(box_collection).to receive(:find).with( "foo", :virtualbox, "1.0").and_return(box) - box.should_receive(:destroy!).once - app.should_receive(:call).with(env).once + expect(box).to receive(:destroy!).once + expect(app).to receive(:call).with(env).once subject.call(env) @@ -57,7 +57,7 @@ describe Vagrant::Action::Builtin::BoxRemove do it "errors if the box doesn't exist" do box_collection.stub(all: []) - app.should_receive(:call).never + expect(app).to receive(:call).never expect { subject.call(env) }. to raise_error(Vagrant::Errors::BoxRemoveNotFound) @@ -69,7 +69,7 @@ describe Vagrant::Action::Builtin::BoxRemove do box_collection.stub(all: [["foo", "1.0", :virtualbox]]) - app.should_receive(:call).never + expect(app).to receive(:call).never expect { subject.call(env) }. to raise_error(Vagrant::Errors::BoxRemoveProviderNotFound) @@ -84,7 +84,7 @@ describe Vagrant::Action::Builtin::BoxRemove do ["foo", "1.0", :vmware], ]) - app.should_receive(:call).never + expect(app).to receive(:call).never expect { subject.call(env) }. to raise_error(Vagrant::Errors::BoxRemoveMultiProvider) @@ -100,7 +100,7 @@ describe Vagrant::Action::Builtin::BoxRemove do ["foo", "1.1", :virtualbox], ]) - app.should_receive(:call).never + expect(app).to receive(:call).never expect { subject.call(env) }. to raise_error(Vagrant::Errors::BoxRemoveMultiVersion) diff --git a/test/unit/vagrant/action/builtin/call_test.rb b/test/unit/vagrant/action/builtin/call_test.rb index bb3c9fc02..e4e937b57 100644 --- a/test/unit/vagrant/action/builtin/call_test.rb +++ b/test/unit/vagrant/action/builtin/call_test.rb @@ -15,7 +15,7 @@ describe Vagrant::Action::Builtin::Call do received = env[:result] end.call({}) - received.should == "value" + expect(received).to eq("value") end it "should update the original env with any changes" do @@ -26,7 +26,7 @@ describe Vagrant::Action::Builtin::Call do builder.use next_step end.call(env) - env[:inner].should == true + expect(env[:inner]).to eq(true) end it "should call the callable with the original environment" do @@ -37,7 +37,7 @@ describe Vagrant::Action::Builtin::Call do # Nothing. end.call({ :foo => :bar }) - received.should == :bar + expect(received).to eq(:bar) end it "should call the next builder" do @@ -49,7 +49,7 @@ describe Vagrant::Action::Builtin::Call do builder.use next_step end.call({}) - received.should == "value" + expect(received).to eq("value") end it "should call the next builder with the original environment" do @@ -61,7 +61,7 @@ describe Vagrant::Action::Builtin::Call do builder.use next_step end.call({ :foo => :bar }) - received.should == :bar + expect(received).to eq(:bar) end it "should instantiate the callable with the extra args" do @@ -81,7 +81,7 @@ describe Vagrant::Action::Builtin::Call do end instance.call(env) - result.should == :foo + expect(result).to eq(:foo) end it "should call the recover method for the sequence in an error" do @@ -131,7 +131,7 @@ describe Vagrant::Action::Builtin::Call do instance.call(env) instance.recover(env) - env[:steps].should == [:call_A, :call_B, :recover_B, :recover_A] + expect(env[:steps]).to eq([:call_A, :call_B, :recover_B, :recover_A]) end it "should recover even if it failed in the callable" do diff --git a/test/unit/vagrant/action/builtin/confirm_test.rb b/test/unit/vagrant/action/builtin/confirm_test.rb index 9cd201042..33122b17d 100644 --- a/test/unit/vagrant/action/builtin/confirm_test.rb +++ b/test/unit/vagrant/action/builtin/confirm_test.rb @@ -7,9 +7,9 @@ describe Vagrant::Action::Builtin::Confirm do ["y", "Y"].each do |valid| it "should set the result to true if '#{valid}' is given" do - env[:ui].should_receive(:ask).with(message).and_return(valid) + expect(env[:ui]).to receive(:ask).with(message).and_return(valid) described_class.new(app, env, message).call(env) - env[:result].should be + expect(env[:result]).to be end end @@ -17,26 +17,26 @@ describe Vagrant::Action::Builtin::Confirm do force_key = :tubes env[force_key] = true described_class.new(app, env, message, force_key).call(env) - env[:result].should be + expect(env[:result]).to be end it "should ask if force is not true" do force_key = :tubes env[force_key] = false - env[:ui].should_receive(:ask).with(message).and_return("nope") + expect(env[:ui]).to receive(:ask).with(message).and_return("nope") described_class.new(app, env, message).call(env) - env[:result].should_not be + expect(env[:result]).not_to be end it "should set result to false if anything else is given" do - env[:ui].should_receive(:ask).with(message).and_return("nope") + expect(env[:ui]).to receive(:ask).with(message).and_return("nope") described_class.new(app, env, message).call(env) - env[:result].should_not be + expect(env[:result]).not_to be end it "should ask multiple times if an allowed set is given and response isn't in that set" do times = 0 - env[:ui].stub(:ask) do |arg| + allow(env[:ui]).to receive(:ask) do |arg| expect(arg).to eql(message) times += 1 diff --git a/test/unit/vagrant/action/builtin/env_set_test.rb b/test/unit/vagrant/action/builtin/env_set_test.rb index 0a551ec2b..50dd4fc6d 100644 --- a/test/unit/vagrant/action/builtin/env_set_test.rb +++ b/test/unit/vagrant/action/builtin/env_set_test.rb @@ -7,14 +7,14 @@ describe Vagrant::Action::Builtin::EnvSet do it "should set the new environment" do described_class.new(app, env, :foo => :bar).call(env) - env[:foo].should == :bar + expect(env[:foo]).to eq(:bar) end it "should call the next middleware" do callable = lambda { |env| env[:called] = env[:foo] } - env[:called].should be_nil + expect(env[:called]).to be_nil described_class.new(callable, env, :foo => :yep).call(env) - env[:called].should == :yep + expect(env[:called]).to eq(:yep) end end diff --git a/test/unit/vagrant/action/builtin/graceful_halt_test.rb b/test/unit/vagrant/action/builtin/graceful_halt_test.rb index 05dd0473b..93d3fc887 100644 --- a/test/unit/vagrant/action/builtin/graceful_halt_test.rb +++ b/test/unit/vagrant/action/builtin/graceful_halt_test.rb @@ -5,9 +5,9 @@ describe Vagrant::Action::Builtin::GracefulHalt do let(:env) { { :machine => machine, :ui => ui } } let(:machine) do result = double("machine") - result.stub(:config).and_return(machine_config) - result.stub(:guest).and_return(machine_guest) - result.stub(:state).and_return(machine_state) + allow(result).to receive(:config).and_return(machine_config) + allow(result).to receive(:guest).and_return(machine_guest) + allow(result).to receive(:state).and_return(machine_state) result end let(:machine_config) do @@ -20,41 +20,41 @@ describe Vagrant::Action::Builtin::GracefulHalt do let(:machine_guest) { double("machine_guest") } let(:machine_state) do double("machine_state").tap do |result| - result.stub(:id).and_return(:unknown) + allow(result).to receive(:id).and_return(:unknown) end end let(:target_state) { :target } let(:ui) do double("ui").tap do |result| - result.stub(:output) + allow(result).to receive(:output) end end it "should do nothing if force is specified" do env[:force_halt] = true - machine_guest.should_not_receive(:capability) + expect(machine_guest).not_to receive(:capability) described_class.new(app, env, target_state).call(env) - env[:result].should == false + expect(env[:result]).to eq(false) end it "should do nothing if there is an invalid source state" do - machine_state.stub(:id).and_return(:invalid_source) - machine_guest.should_not_receive(:capability) + allow(machine_state).to receive(:id).and_return(:invalid_source) + expect(machine_guest).not_to receive(:capability) described_class.new(app, env, target_state, :target_source).call(env) - env[:result].should == false + expect(env[:result]).to eq(false) end it "should gracefully halt and wait for the target state" do - machine_guest.should_receive(:capability).with(:halt).once - machine_state.stub(:id).and_return(target_state) + expect(machine_guest).to receive(:capability).with(:halt).once + allow(machine_state).to receive(:id).and_return(target_state) described_class.new(app, env, target_state).call(env) - env[:result].should == true + expect(env[:result]).to eq(true) end end diff --git a/test/unit/vagrant/action/builtin/handle_box_test.rb b/test/unit/vagrant/action/builtin/handle_box_test.rb index 5ddbf7b7f..6b7d85818 100644 --- a/test/unit/vagrant/action/builtin/handle_box_test.rb +++ b/test/unit/vagrant/action/builtin/handle_box_test.rb @@ -32,7 +32,7 @@ describe Vagrant::Action::Builtin::HandleBox do machine.config.vm.box = nil machine.config.vm.box_url = nil - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end @@ -40,8 +40,8 @@ describe Vagrant::Action::Builtin::HandleBox do it "doesn't do anything if a box exists" do machine.stub(box: box) - action_runner.should_receive(:run).never - app.should_receive(:call).with(env) + expect(action_runner).to receive(:run).never + expect(app).to receive(:call).with(env) subject.call(env) end @@ -54,15 +54,15 @@ describe Vagrant::Action::Builtin::HandleBox do end it "adds a box that doesn't exist" do - action_runner.should_receive(:run).with do |action, opts| + expect(action_runner).to receive(:run).with { |action, opts| expect(opts[:box_name]).to eq(machine.config.vm.box) expect(opts[:box_url]).to eq(machine.config.vm.box) expect(opts[:box_provider]).to eq(:dummy) expect(opts[:box_version]).to eq(machine.config.vm.box_version) true - end + } - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end @@ -70,15 +70,15 @@ describe Vagrant::Action::Builtin::HandleBox do it "adds a box using any format the provider allows" do machine.provider_options[:box_format] = [:foo, :bar] - action_runner.should_receive(:run).with do |action, opts| + expect(action_runner).to receive(:run).with { |action, opts| expect(opts[:box_name]).to eq(machine.config.vm.box) expect(opts[:box_url]).to eq(machine.config.vm.box) expect(opts[:box_provider]).to eq([:foo, :bar]) expect(opts[:box_version]).to eq(machine.config.vm.box_version) true - end + } - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end @@ -93,15 +93,15 @@ describe Vagrant::Action::Builtin::HandleBox do end it "adds a box that doesn't exist" do - action_runner.should_receive(:run).with do |action, opts| + expect(action_runner).to receive(:run).with { |action, opts| expect(opts[:box_name]).to eq(machine.config.vm.box) expect(opts[:box_url]).to eq(machine.config.vm.box_url) expect(opts[:box_provider]).to eq(:dummy) expect(opts[:box_version]).to eq(machine.config.vm.box_version) true - end + } - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end diff --git a/test/unit/vagrant/action/builtin/is_state_test.rb b/test/unit/vagrant/action/builtin/is_state_test.rb index 68040fb63..3e0133365 100644 --- a/test/unit/vagrant/action/builtin/is_state_test.rb +++ b/test/unit/vagrant/action/builtin/is_state_test.rb @@ -1,51 +1,51 @@ -require "pathname" -require "tmpdir" - -require File.expand_path("../../../../base", __FILE__) - -describe Vagrant::Action::Builtin::IsState do - let(:app) { lambda { |env| } } - let(:env) { { :machine => machine } } - let(:machine) do - double("machine").tap do |machine| - machine.stub(:state).and_return(state) - end - end - - let(:state) { double("state") } - - describe "#call" do - it "sets result to false if is proper state" do - state.stub(id: :foo) - - subject = described_class.new(app, env, :bar) - - app.should_receive(:call).with(env) - - subject.call(env) - expect(env[:result]).to be_false - end - - it "sets result to true if is proper state" do - state.stub(id: :foo) - - subject = described_class.new(app, env, :foo) - - app.should_receive(:call).with(env) - - subject.call(env) - expect(env[:result]).to be_true - end - - it "inverts the result if specified" do - state.stub(id: :foo) - - subject = described_class.new(app, env, :foo, invert: true) - - app.should_receive(:call).with(env) - - subject.call(env) - expect(env[:result]).to be_false - end - end -end +require "pathname" +require "tmpdir" + +require File.expand_path("../../../../base", __FILE__) + +describe Vagrant::Action::Builtin::IsState do + let(:app) { lambda { |env| } } + let(:env) { { :machine => machine } } + let(:machine) do + double("machine").tap do |machine| + allow(machine).to receive(:state).and_return(state) + end + end + + let(:state) { double("state") } + + describe "#call" do + it "sets result to false if is proper state" do + state.stub(id: :foo) + + subject = described_class.new(app, env, :bar) + + expect(app).to receive(:call).with(env) + + subject.call(env) + expect(env[:result]).to be_false + end + + it "sets result to true if is proper state" do + state.stub(id: :foo) + + subject = described_class.new(app, env, :foo) + + expect(app).to receive(:call).with(env) + + subject.call(env) + expect(env[:result]).to be_true + end + + it "inverts the result if specified" do + state.stub(id: :foo) + + subject = described_class.new(app, env, :foo, invert: true) + + expect(app).to receive(:call).with(env) + + subject.call(env) + expect(env[:result]).to be_false + end + end +end diff --git a/test/unit/vagrant/action/builtin/lock_test.rb b/test/unit/vagrant/action/builtin/lock_test.rb index 35f0b9720..03c425772 100644 --- a/test/unit/vagrant/action/builtin/lock_test.rb +++ b/test/unit/vagrant/action/builtin/lock_test.rb @@ -42,7 +42,7 @@ describe Vagrant::Action::Builtin::Lock do instance = described_class.new(app, env, options) instance.call(env) - inner_acquire.should == false + expect(inner_acquire).to eq(false) end it "should allow the exception to be a proc" do @@ -51,7 +51,7 @@ describe Vagrant::Action::Builtin::Lock do File.open(lock_path, "w+") do |f| # Acquire lock - f.flock(File::LOCK_EX | File::LOCK_NB).should == 0 + expect(f.flock(File::LOCK_EX | File::LOCK_NB)).to eq(0) # Test! instance = described_class.new(app, env, options) @@ -71,13 +71,13 @@ describe Vagrant::Action::Builtin::Lock do instance = described_class.new(app, env, options) instance.call(env) - inner_acquire.should == false + expect(inner_acquire).to eq(false) end it "should raise an exception if the lock is already held" do File.open(lock_path, "w+") do |f| # Acquire lock - f.flock(File::LOCK_EX | File::LOCK_NB).should == 0 + expect(f.flock(File::LOCK_EX | File::LOCK_NB)).to eq(0) # Test! instance = described_class.new(app, env, options) @@ -93,6 +93,6 @@ describe Vagrant::Action::Builtin::Lock do outer = described_class.new(inner, env, options) outer.call(env) - called.should == true + expect(called).to eq(true) end end diff --git a/test/unit/vagrant/action/builtin/message_test.rb b/test/unit/vagrant/action/builtin/message_test.rb index a1ef4d344..bdb400646 100644 --- a/test/unit/vagrant/action/builtin/message_test.rb +++ b/test/unit/vagrant/action/builtin/message_test.rb @@ -1,22 +1,22 @@ -require "pathname" -require "tmpdir" - -require File.expand_path("../../../../base", __FILE__) - -describe Vagrant::Action::Builtin::Message do - let(:app) { lambda { |env| } } - let(:env) { { :ui => ui } } - - let(:ui) { double("ui") } - - describe "#call" do - it "outputs the given message" do - subject = described_class.new(app, env, "foo") - - ui.should_receive(:output).with("foo") - app.should_receive(:call).with(env) - - subject.call(env) - end - end -end +require "pathname" +require "tmpdir" + +require File.expand_path("../../../../base", __FILE__) + +describe Vagrant::Action::Builtin::Message do + let(:app) { lambda { |env| } } + let(:env) { { :ui => ui } } + + let(:ui) { double("ui") } + + describe "#call" do + it "outputs the given message" do + subject = described_class.new(app, env, "foo") + + expect(ui).to receive(:output).with("foo") + expect(app).to receive(:call).with(env) + + subject.call(env) + end + end +end diff --git a/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb b/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb index 224fa5e30..6c37356fb 100644 --- a/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb +++ b/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb @@ -13,7 +13,7 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do let(:machine) do double("machine").tap do |machine| - machine.stub(:config).and_return(machine_config) + allow(machine).to receive(:config).and_return(machine_config) end end @@ -34,7 +34,7 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do } result = subject.default_synced_folder_type(machine, plugins) - result.should == "good" + expect(result).to eq("good") end end @@ -47,9 +47,9 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do } result = subject.impl_opts("foo", env) - result.length.should == 2 - result[:foo_bar].should == "baz" - result[:foo_baz].should == "bar" + expect(result.length).to eq(2) + expect(result[:foo_bar]).to eq("baz") + expect(result[:foo_baz]).to eq("bar") end end @@ -79,13 +79,13 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do folders["nfs"] = { type: "nfs" } result = subject.synced_folders(machine) - result.length.should == 2 - result[:default].should == { + expect(result.length).to eq(2) + expect(result[:default]).to eq({ "another" => folders["another"], "foo" => folders["foo"], "root" => folders["root"], - } - result[:nfs].should == { "nfs" => folders["nfs"] } + }) + expect(result[:nfs]).to eq({ "nfs" => folders["nfs"] }) end it "should error if an explicit type is unusable" do @@ -101,8 +101,8 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do folders["foo"] = { disabled: true } result = subject.synced_folders(machine) - result.length.should == 1 - result[:default].length.should == 1 + expect(result.length).to eq(1) + expect(result[:default].length).to eq(1) end it "should scope hash override the settings" do diff --git a/test/unit/vagrant/action/builtin/ssh_exec_test.rb b/test/unit/vagrant/action/builtin/ssh_exec_test.rb index 34d8a9d72..d2ba286c6 100644 --- a/test/unit/vagrant/action/builtin/ssh_exec_test.rb +++ b/test/unit/vagrant/action/builtin/ssh_exec_test.rb @@ -7,7 +7,7 @@ describe Vagrant::Action::Builtin::SSHExec do let(:env) { { :machine => machine } } let(:machine) do result = double("machine") - result.stub(:ssh_info).and_return(machine_ssh_info) + allow(result).to receive(:ssh_info).and_return(machine_ssh_info) result end let(:machine_ssh_info) { {} } @@ -16,13 +16,13 @@ describe Vagrant::Action::Builtin::SSHExec do before(:each) do # Stub the methods so that even if we test incorrectly, no side # effects actually happen. - ssh_klass.stub(:check_key_permissions) - ssh_klass.stub(:exec) + allow(ssh_klass).to receive(:check_key_permissions) + allow(ssh_klass).to receive(:exec) end it "should raise an exception if SSH is not ready" do not_ready_machine = double("machine") - not_ready_machine.stub(:ssh_info).and_return(nil) + allow(not_ready_machine).to receive(:ssh_info).and_return(nil) env[:machine] = not_ready_machine expect { described_class.new(app, env).call(env) }. @@ -33,12 +33,12 @@ describe Vagrant::Action::Builtin::SSHExec do key_path = "/foo" machine_ssh_info[:private_key_path] = [key_path] - ssh_klass.should_receive(:check_key_permissions). + expect(ssh_klass).to receive(:check_key_permissions). with(Pathname.new(key_path)). once. ordered - ssh_klass.should_receive(:exec). + expect(ssh_klass).to receive(:exec). with(machine_ssh_info, nil). once. ordered @@ -49,7 +49,7 @@ describe Vagrant::Action::Builtin::SSHExec do it "should exec with the options given in `ssh_opts`" do ssh_opts = { :foo => :bar } - ssh_klass.should_receive(:exec). + expect(ssh_klass).to receive(:exec). with(machine_ssh_info, ssh_opts) env[:ssh_opts] = ssh_opts diff --git a/test/unit/vagrant/action/builtin/synced_folder_cleanup_test.rb b/test/unit/vagrant/action/builtin/synced_folder_cleanup_test.rb index 310311967..c1ed71f5e 100644 --- a/test/unit/vagrant/action/builtin/synced_folder_cleanup_test.rb +++ b/test/unit/vagrant/action/builtin/synced_folder_cleanup_test.rb @@ -10,7 +10,7 @@ describe Vagrant::Action::Builtin::SyncedFolderCleanup do let(:env) { { :machine => machine, :ui => ui } } let(:machine) do double("machine").tap do |machine| - machine.stub(:config).and_return(machine_config) + allow(machine).to receive(:config).and_return(machine_config) end end @@ -24,7 +24,7 @@ describe Vagrant::Action::Builtin::SyncedFolderCleanup do let(:ui) do double("ui").tap do |result| - result.stub(:info) + allow(result).to receive(:info) end end @@ -127,9 +127,9 @@ describe Vagrant::Action::Builtin::SyncedFolderCleanup do subject.call(env) - trackers[0].clean.should be_true - trackers[1].clean.should be_true - trackers[2].clean.should be_true + expect(trackers[0].clean).to be_true + expect(trackers[1].clean).to be_true + expect(trackers[2].clean).to be_true end end end diff --git a/test/unit/vagrant/action/builtin/synced_folders_test.rb b/test/unit/vagrant/action/builtin/synced_folders_test.rb index cf5bb0434..b4dc362c6 100644 --- a/test/unit/vagrant/action/builtin/synced_folders_test.rb +++ b/test/unit/vagrant/action/builtin/synced_folders_test.rb @@ -10,7 +10,7 @@ describe Vagrant::Action::Builtin::SyncedFolders do let(:env) { { :machine => machine, :ui => ui } } let(:machine) do double("machine").tap do |machine| - machine.stub(:config).and_return(machine_config) + allow(machine).to receive(:config).and_return(machine_config) end end @@ -24,7 +24,7 @@ describe Vagrant::Action::Builtin::SyncedFolders do let(:ui) do double("ui").tap do |result| - result.stub(:info) + allow(result).to receive(:info) end end @@ -57,8 +57,8 @@ describe Vagrant::Action::Builtin::SyncedFolders do subject.call(env) - env[:root_path].join("foo").should_not be_directory - env[:root_path].join("bar").should be_directory + expect(env[:root_path].join("foo")).not_to be_directory + expect(env[:root_path].join("bar")).to be_directory end it "should invoke prepare then enable" do @@ -91,7 +91,7 @@ describe Vagrant::Action::Builtin::SyncedFolders do subject.call(env) - order.should == [:prepare, :enable] + expect(order).to eq([:prepare, :enable]) expect(ids.length).to eq(2) expect(ids[0]).to eq(ids[1]) end diff --git a/test/unit/vagrant/action/hook_test.rb b/test/unit/vagrant/action/hook_test.rb index 27b9efe54..9c6054b09 100644 --- a/test/unit/vagrant/action/hook_test.rb +++ b/test/unit/vagrant/action/hook_test.rb @@ -5,10 +5,25 @@ require "vagrant/action/hook" describe Vagrant::Action::Hook do describe "defaults" do - its("after_hooks") { should be_empty } - its("before_hooks") { should be_empty } - its("append_hooks") { should be_empty } - its("prepend_hooks") { should be_empty } + describe '#after_hooks' do + subject { super().after_hooks } + it { should be_empty } + end + + describe '#before_hooks' do + subject { super().before_hooks } + it { should be_empty } + end + + describe '#append_hooks' do + subject { super().append_hooks } + it { should be_empty } + end + + describe '#prepend_hooks' do + subject { super().prepend_hooks } + it { should be_empty } + end end describe "before hooks" do @@ -21,11 +36,11 @@ describe Vagrant::Action::Hook do subject.before(existing, 2) subject.before(existing, 3, :arg, &block) - subject.before_hooks[existing].should == [ + expect(subject.before_hooks[existing]).to eq([ [1, [], nil], [2, [], nil], [3, [:arg], block] - ] + ]) end end @@ -39,11 +54,11 @@ describe Vagrant::Action::Hook do subject.after(existing, 2) subject.after(existing, 3, :arg, &block) - subject.after_hooks[existing].should == [ + expect(subject.after_hooks[existing]).to eq([ [1, [], nil], [2, [], nil], [3, [:arg], block] - ] + ]) end end @@ -55,11 +70,11 @@ describe Vagrant::Action::Hook do subject.append(2) subject.append(3, :arg, &block) - subject.append_hooks.should == [ + expect(subject.append_hooks).to eq([ [1, [], nil], [2, [], nil], [3, [:arg], block] - ] + ]) end end @@ -71,11 +86,11 @@ describe Vagrant::Action::Hook do subject.prepend(2) subject.prepend(3, :arg, &block) - subject.prepend_hooks.should == [ + expect(subject.prepend_hooks).to eq([ [1, [], nil], [2, [], nil], [3, [:arg], block] - ] + ]) end end @@ -90,12 +105,12 @@ describe Vagrant::Action::Hook do subject.apply(builder) - builder.stack.should == [ + expect(builder.stack).to eq([ ["1", [2], nil], ["2", [], nil], ["8", [], nil], ["9", [], nil] - ] + ]) end it "should not prepend or append if disabled" do @@ -109,12 +124,12 @@ describe Vagrant::Action::Hook do subject.apply(builder, no_prepend_or_append: true) - builder.stack.should == [ + expect(builder.stack).to eq([ ["3", [], nil], ["4", [], nil], ["7", [], nil], ["8", [], nil] - ] + ]) end end end diff --git a/test/unit/vagrant/action/runner_test.rb b/test/unit/vagrant/action/runner_test.rb index 87c83aabe..bddd4a6ff 100644 --- a/test/unit/vagrant/action/runner_test.rb +++ b/test/unit/vagrant/action/runner_test.rb @@ -44,7 +44,7 @@ describe Vagrant::Action::Runner do end result = instance.run(callable) - result[:data].should == "value" + expect(result[:data]).to eq("value") end it "should pass options into hash given to callable" do @@ -54,7 +54,7 @@ describe Vagrant::Action::Runner do end instance.run(callable, "data" => "foo") - result.should == "foo" + expect(result).to eq("foo") end it "should pass global options into the hash" do @@ -65,7 +65,7 @@ describe Vagrant::Action::Runner do instance = described_class.new("data" => "bar") instance.run(callable) - result.should == "bar" + expect(result).to eq("bar") end it "should yield the block passed to the init method to get lazy loaded globals" do @@ -76,6 +76,6 @@ describe Vagrant::Action::Runner do instance = described_class.new { { "data" => "bar" } } instance.run(callable) - result.should == "bar" + expect(result).to eq("bar") end end diff --git a/test/unit/vagrant/action/warden_test.rb b/test/unit/vagrant/action/warden_test.rb index 40d03b13e..b726da3cc 100644 --- a/test/unit/vagrant/action/warden_test.rb +++ b/test/unit/vagrant/action/warden_test.rb @@ -14,7 +14,7 @@ describe Vagrant::Action::Warden do instance = described_class.new([appender_proc(1), appender_proc(2)], data) instance.call(data) - data[:data].should == [1, 2] + expect(data[:data]).to eq([1, 2]) end it "starts a recovery sequence when an exception is raised" do @@ -56,10 +56,10 @@ describe Vagrant::Action::Warden do to raise_error(RuntimeError) # Verify the recovery process goes in reverse order - data[:recover].should == [2, 1] + expect(data[:recover]).to eq([2, 1]) # Verify that the error is available in the data - data["vagrant.error"].should be_kind_of(RuntimeError) + expect(data["vagrant.error"]).to be_kind_of(RuntimeError) end it "does not do a recovery sequence if SystemExit is raised" do @@ -87,6 +87,6 @@ describe Vagrant::Action::Warden do expect { instance.call(data) }.to raise_error(SystemExit) # The recover should not have been called - data.has_key?(:recover).should_not be + expect(data.has_key?(:recover)).not_to be end end diff --git a/test/unit/vagrant/batch_action_test.rb b/test/unit/vagrant/batch_action_test.rb index 0bc940d26..18e8a149c 100644 --- a/test/unit/vagrant/batch_action_test.rb +++ b/test/unit/vagrant/batch_action_test.rb @@ -13,7 +13,7 @@ describe Vagrant::BatchAction do double("machine").tap do |m| m.stub(:provider_name => provider_name) m.stub(:provider_options => options) - m.stub(:action) do |action, opts| + allow(m).to receive(:action) do |action, opts| lock.synchronize do called_actions << [m, action, opts] end @@ -30,14 +30,14 @@ describe Vagrant::BatchAction do subject.action(machine2, "destroy") subject.run - called_actions.include?([machine, "up", nil]).should be - called_actions.include?([machine2, "destroy", nil]).should be + expect(called_actions.include?([machine, "up", nil])).to be + expect(called_actions.include?([machine2, "destroy", nil])).to be end it "should handle forks gracefully", :skip_windows do # Doesn't need to be tested on Windows since Windows doesn't # support fork(1) - machine.stub(:action) do |action, opts| + allow(machine).to receive(:action) do |action, opts| pid = fork if !pid # Child process diff --git a/test/unit/vagrant/box_collection_test.rb b/test/unit/vagrant/box_collection_test.rb index 78324e232..ffb475725 100644 --- a/test/unit/vagrant/box_collection_test.rb +++ b/test/unit/vagrant/box_collection_test.rb @@ -12,12 +12,12 @@ describe Vagrant::BoxCollection do subject { described_class.new(environment.boxes_dir) } it "should tell us the directory it is using" do - subject.directory.should == environment.boxes_dir + expect(subject.directory).to eq(environment.boxes_dir) end describe "#all" do it "should return an empty array when no boxes are there" do - subject.all.should == [] + expect(subject.all).to eq([]) end it "should return the boxes and their providers" do @@ -29,11 +29,11 @@ describe Vagrant::BoxCollection do # Verify some output results = subject.all - results.length.should == 4 - results.include?(["foo", "1.0", :virtualbox]).should be - results.include?(["foo", "1.0", :vmware]).should be - results.include?(["bar", "0", :ec2]).should be - results.include?(["foo/bar", "1.0", :virtualbox]).should be + expect(results.length).to eq(4) + expect(results.include?(["foo", "1.0", :virtualbox])).to be + expect(results.include?(["foo", "1.0", :vmware])).to be + expect(results.include?(["bar", "0", :ec2])).to be + expect(results.include?(["foo/bar", "1.0", :virtualbox])).to be end it 'does not raise an exception when a file appears in the boxes dir' do @@ -80,11 +80,11 @@ describe Vagrant::BoxCollection do environment.box3("foo", "0", :virtualbox, metadata_url: "foourl") - hook.should_receive(:call).with do |name, env| + expect(hook).to receive(:call).with { |name, env| expect(name).to eq(:authenticate_box_url) expect(env[:box_urls]).to eq(["foourl"]) true - end.and_return(box_urls: ["bar"]) + }.and_return(box_urls: ["bar"]) # Actual test result = subject.find("foo", :virtualbox, ">= 0") @@ -219,7 +219,7 @@ describe Vagrant::BoxCollection do # Attempt to add the box with the same name box_path = environment.box2_file(prev_box_provider, metadata: { "replaced" => "yes" }) box = subject.add(box_path, prev_box_name, prev_box_version, force: true) - box.metadata["replaced"].should == "yes" + expect(box.metadata["replaced"]).to eq("yes") end it "should raise an exception if the box already exists and no provider is given" do diff --git a/test/unit/vagrant/box_metadata_test.rb b/test/unit/vagrant/box_metadata_test.rb index 488effb91..0acb0ad48 100644 --- a/test/unit/vagrant/box_metadata_test.rb +++ b/test/unit/vagrant/box_metadata_test.rb @@ -38,8 +38,15 @@ describe Vagrant::BoxMetadata do subject { described_class.new(raw) } - its(:name) { should eq("foo") } - its(:description) { should eq("bar") } + describe '#name' do + subject { super().name } + it { should eq("foo") } + end + + describe '#description' do + subject { super().description } + it { should eq("bar") } + end context "with poorly formatted JSON" do let(:raw) { diff --git a/test/unit/vagrant/box_test.rb b/test/unit/vagrant/box_test.rb index 797115651..baa3e09cf 100644 --- a/test/unit/vagrant/box_test.rb +++ b/test/unit/vagrant/box_test.rb @@ -19,18 +19,21 @@ describe Vagrant::Box do let(:directory) { environment.box3("foo", "1.0", :virtualbox) } subject { described_class.new(name, provider, version, directory) } - its(:metadata_url) { should be_nil } + describe '#metadata_url' do + subject { super().metadata_url } + it { should be_nil } + end it "provides the name" do - subject.name.should == name + expect(subject.name).to eq(name) end it "provides the provider" do - subject.provider.should == provider + expect(subject.provider).to eq(provider) end it "provides the directory" do - subject.directory.should == directory + expect(subject.directory).to eq(directory) end it "provides the metadata associated with a box" do @@ -42,7 +45,7 @@ describe Vagrant::Box do end # Verify the metadata - subject.metadata.should == data + expect(subject.metadata).to eq(data) end context "with a metadata URL" do @@ -52,7 +55,10 @@ describe Vagrant::Box do metadata_url: "foo") end - its(:metadata_url) { should eq("foo") } + describe '#metadata_url' do + subject { super().metadata_url } + it { should eq("foo") } + end end context "with a corrupt metadata file" do @@ -218,13 +224,13 @@ describe Vagrant::Box do describe "destroying" do it "should destroy an existing box" do # Verify that our "box" exists - directory.exist?.should be + expect(directory.exist?).to be # Destroy it - subject.destroy!.should be + expect(subject.destroy!).to be # Verify that it is "destroyed" - directory.exist?.should_not be + expect(directory.exist?).not_to be end it "should not error destroying a non-existent box" do @@ -235,7 +241,7 @@ describe Vagrant::Box do directory.rmtree # Destroy it - box.destroy!.should be + expect(box.destroy!).to be end end @@ -256,7 +262,7 @@ describe Vagrant::Box do # Let's now add this box again under a different name, and then # verify that we get the proper result back. new_box = box_collection.add(box_output_path, "foo2", "1.0") - new_box.directory.join("test_file").read.should == test_file_contents + expect(new_box.directory.join("test_file").read).to eq(test_file_contents) end end @@ -265,7 +271,7 @@ describe Vagrant::Box do a = described_class.new("a", :foo, "1.0", directory) b = described_class.new("a", :foo, "1.0", directory) - a.should == b + expect(a).to eq(b) end it "should not be equal if name doesn't match" do @@ -295,7 +301,7 @@ describe Vagrant::Box do c = described_class.new("a", :foo2, "1.1", directory) d = described_class.new("b", :foo2, "1.0", directory) - [d, c, a, b].sort.should == [a, b, c, d] + expect([d, c, a, b].sort).to eq([a, b, c, d]) end end end diff --git a/test/unit/vagrant/cli_test.rb b/test/unit/vagrant/cli_test.rb index 0aa669c06..4848f14c9 100644 --- a/test/unit/vagrant/cli_test.rb +++ b/test/unit/vagrant/cli_test.rb @@ -17,7 +17,7 @@ describe Vagrant::CLI do describe "#execute" do it "invokes help and exits with 1 if invalid command" do subject = described_class.new(["i-dont-exist"], env) - subject.should_receive(:help).once + expect(subject).to receive(:help).once expect(subject.execute).to eql(1) end @@ -25,7 +25,7 @@ describe Vagrant::CLI do commands[:destroy] = [command_lambda("destroy", 42), {}] subject = described_class.new(["destroy"], env) - subject.should_not_receive(:help) + expect(subject).not_to receive(:help) expect(subject.execute).to eql(42) end @@ -45,11 +45,11 @@ describe Vagrant::CLI do commands[:bar] = [command_lambda("bar", 0), { primary: true }] commands[:baz] = [command_lambda("baz", 0), { primary: false }] - env.ui.should_receive(:info).with do |message, opts| + expect(env.ui).to receive(:info).with { |message, opts| expect(message).to include("foo") expect(message).to include("bar") expect(message.include?("baz")).to be_false - end + } subject.help end diff --git a/test/unit/vagrant/config/loader_test.rb b/test/unit/vagrant/config/loader_test.rb index 309d5247b..cd7a9e975 100644 --- a/test/unit/vagrant/config/loader_test.rb +++ b/test/unit/vagrant/config/loader_test.rb @@ -51,9 +51,9 @@ describe Vagrant::Config::Loader do instance.set(:proc, [[current_version, proc]]) config, warnings, errors = instance.load([:proc]) - config[:foo].should == "yep" - warnings.should == [] - errors.should == [] + expect(config[:foo]).to eq("yep") + expect(warnings).to eq([]) + expect(errors).to eq([]) end end @@ -73,8 +73,8 @@ describe Vagrant::Config::Loader do # Run the actual configuration and assert that we get the proper result instance.set(:proc, [[current_version, proc]]) config, _ = instance.load([:proc]) - config[:foo].should == "yep" - config[:finalized].should == true + expect(config[:foo]).to eq("yep") + expect(config[:finalized]).to eq(true) end end @@ -96,8 +96,8 @@ describe Vagrant::Config::Loader do proc = lambda { |config| config[:foo] = "yep" } instance.set(:proc, [["1", proc]]) config, _ = instance.load([:proc]) - config[:foo].should == "yep" - config[:v2].should == true + expect(config[:foo]).to eq("yep") + expect(config[:v2]).to eq(true) end it "should keep track of warnings and errors" do @@ -117,10 +117,10 @@ describe Vagrant::Config::Loader do proc = lambda { |config| config[:foo] = "yep" } instance.set(:proc, [["1", proc]]) config, warnings, errors = instance.load([:proc]) - config[:foo].should == "yep" - config[:v2].should == true - warnings.should == ["foo!"] - errors.should == ["bar!"] + expect(config[:foo]).to eq("yep") + expect(config[:v2]).to eq(true) + expect(warnings).to eq(["foo!"]) + expect(errors).to eq(["bar!"]) end end @@ -138,10 +138,10 @@ describe Vagrant::Config::Loader do result, _ = instance.load([:proc]) # Verify the config result - result[:foo].should == "yep" + expect(result[:foo]).to eq("yep") # Verify the count is only one - count.should == 1 + expect(count).to eq(1) end end @@ -154,7 +154,7 @@ describe Vagrant::Config::Loader do 5.times { instance.set(:file, file) } 5.times { instance.load([:file]) } - $_config_data.should == 1 + expect($_config_data).to eq(1) end it "should not clear the cache if setting to the same value multiple times" do @@ -168,7 +168,7 @@ describe Vagrant::Config::Loader do instance.set(:proc, file) 5.times { instance.load([:proc]) } - $_config_data.should == 1 + expect($_config_data).to eq(1) end it "should raise proper error if there is a syntax error in a Vagrantfile" do diff --git a/test/unit/vagrant/config/v1/dummy_config_test.rb b/test/unit/vagrant/config/v1/dummy_config_test.rb index 22a99a97b..46a3f7608 100644 --- a/test/unit/vagrant/config/v1/dummy_config_test.rb +++ b/test/unit/vagrant/config/v1/dummy_config_test.rb @@ -7,14 +7,14 @@ describe Vagrant::Config::V1::DummyConfig do end it "should allow method calls that return more DummyConfigs" do - subject.foo.should be_kind_of(described_class) + expect(subject.foo).to be_kind_of(described_class) end it "should allow hash access" do expect { subject[:foo] }. to_not raise_error - subject[:foo].should be_kind_of(described_class) + expect(subject[:foo]).to be_kind_of(described_class) end it "should allow setting hash values" do diff --git a/test/unit/vagrant/config/v1/loader_test.rb b/test/unit/vagrant/config/v1/loader_test.rb index 02a5dd5ff..deca8cf3c 100644 --- a/test/unit/vagrant/config/v1/loader_test.rb +++ b/test/unit/vagrant/config/v1/loader_test.rb @@ -13,7 +13,7 @@ describe Vagrant::Config::V1::Loader do describe "empty" do it "returns an empty configuration object" do result = described_class.init - result.should be_kind_of(Vagrant::Config::V1::Root) + expect(result).to be_kind_of(Vagrant::Config::V1::Root) end it "returns an object with all configuration keys loaded if V1" do @@ -28,8 +28,8 @@ describe Vagrant::Config::V1::Loader do # Test that we have all keys result = described_class.init - result.foo.should be_kind_of(OpenStruct) - result.bar.should be_kind_of(OpenStruct) + expect(result.foo).to be_kind_of(OpenStruct) + expect(result.bar).to be_kind_of(OpenStruct) end it "returns only upgradable config objects if not V1" do @@ -44,7 +44,7 @@ describe Vagrant::Config::V1::Loader do # Test that we have all keys result = described_class.init - result.bar.should be_kind_of(OpenStruct) + expect(result.bar).to be_kind_of(OpenStruct) end end @@ -70,11 +70,11 @@ describe Vagrant::Config::V1::Loader do # Test that it works properly config = described_class.load(config_proc) - config.foo.bar.should == "value" + expect(config.foo.bar).to eq("value") # Finalize it described_class.finalize(config) - config.foo.bar.should == "finalized" + expect(config.foo.bar).to eq("finalized") end end @@ -92,7 +92,7 @@ describe Vagrant::Config::V1::Loader do # Test that it works properly config = described_class.load(config_proc) - config.foo.bar.should == "value" + expect(config.foo.bar).to eq("value") end end @@ -101,8 +101,8 @@ describe Vagrant::Config::V1::Loader do old = Vagrant::Config::V1::Root.new({ :foo => Object }) new = Vagrant::Config::V1::Root.new({ :bar => Object }) result = described_class.merge(old, new) - result.foo.should be_kind_of(Object) - result.bar.should be_kind_of(Object) + expect(result.foo).to be_kind_of(Object) + expect(result.bar).to be_kind_of(Object) end it "should merge instantiated objects" do @@ -117,8 +117,8 @@ describe Vagrant::Config::V1::Loader do new.bar.value = "new" result = described_class.merge(old, new) - result.foo.value.should == "old" - result.bar.value.should == "new" + expect(result.foo.value).to eq("old") + expect(result.bar.value).to eq("new") end it "should merge conflicting classes by calling `merge`" do @@ -139,7 +139,7 @@ describe Vagrant::Config::V1::Loader do new.foo.value = 15 result = described_class.merge(old, new) - result.foo.value.should == 25 + expect(result.foo.value).to eq(25) end end end diff --git a/test/unit/vagrant/config/v1/root_test.rb b/test/unit/vagrant/config/v1/root_test.rb index 7c8e4061f..695d64250 100644 --- a/test/unit/vagrant/config/v1/root_test.rb +++ b/test/unit/vagrant/config/v1/root_test.rb @@ -9,23 +9,23 @@ describe Vagrant::Config::V1::Root do instance = described_class.new(map) foo = instance.foo - foo.should be_kind_of(foo_class) - instance.foo.should eql(foo) + expect(foo).to be_kind_of(foo_class) + expect(instance.foo).to eql(foo) end it "can be created with initial state" do instance = described_class.new({}, { :foo => "bar" }) - instance.foo.should == "bar" + expect(instance.foo).to eq("bar") end it "should return internal state" do map = { "foo" => Object, "bar" => Object } instance = described_class.new(map) - instance.__internal_state.should == { + expect(instance.__internal_state).to eq({ "config_map" => map, "keys" => {}, "missing_key_calls" => Set.new - } + }) end it "should record missing key calls" do @@ -33,8 +33,8 @@ describe Vagrant::Config::V1::Root do instance.foo.bar = false keys = instance.__internal_state["missing_key_calls"] - keys.should be_kind_of(Set) - keys.length.should == 1 - keys.include?("foo").should be + expect(keys).to be_kind_of(Set) + expect(keys.length).to eq(1) + expect(keys.include?("foo")).to be end end diff --git a/test/unit/vagrant/config/v2/dummy_config_test.rb b/test/unit/vagrant/config/v2/dummy_config_test.rb index 6d55f0ab0..00c8dd13d 100644 --- a/test/unit/vagrant/config/v2/dummy_config_test.rb +++ b/test/unit/vagrant/config/v2/dummy_config_test.rb @@ -7,14 +7,14 @@ describe Vagrant::Config::V2::DummyConfig do end it "should allow method calls that return more DummyConfigs" do - subject.foo.should be_kind_of(described_class) + expect(subject.foo).to be_kind_of(described_class) end it "should allow hash access" do expect { subject[:foo] }. to_not raise_error - subject[:foo].should be_kind_of(described_class) + expect(subject[:foo]).to be_kind_of(described_class) end it "should allow setting hash values" do diff --git a/test/unit/vagrant/config/v2/loader_test.rb b/test/unit/vagrant/config/v2/loader_test.rb index 564e69940..b2e020179 100644 --- a/test/unit/vagrant/config/v2/loader_test.rb +++ b/test/unit/vagrant/config/v2/loader_test.rb @@ -13,7 +13,7 @@ describe Vagrant::Config::V2::Loader do describe "empty" do it "returns an empty configuration object" do result = described_class.init - result.should be_kind_of(Vagrant::Config::V2::Root) + expect(result).to be_kind_of(Vagrant::Config::V2::Root) end end @@ -39,11 +39,11 @@ describe Vagrant::Config::V2::Loader do # Test that it works properly config = described_class.load(config_proc) - config.foo.bar.should == "value" + expect(config.foo.bar).to eq("value") # Finalize it described_class.finalize(config) - config.foo.bar.should == "finalized" + expect(config.foo.bar).to eq("finalized") end end @@ -61,7 +61,7 @@ describe Vagrant::Config::V2::Loader do # Test that it works properly config = described_class.load(config_proc) - config.foo.bar.should == "value" + expect(config.foo.bar).to eq("value") end end @@ -70,8 +70,8 @@ describe Vagrant::Config::V2::Loader do old = Vagrant::Config::V2::Root.new({ :foo => Object }) new = Vagrant::Config::V2::Root.new({ :bar => Object }) result = described_class.merge(old, new) - result.foo.should be_kind_of(Object) - result.bar.should be_kind_of(Object) + expect(result.foo).to be_kind_of(Object) + expect(result.bar).to be_kind_of(Object) end it "should merge instantiated objects" do @@ -86,8 +86,8 @@ describe Vagrant::Config::V2::Loader do new.bar.value = "new" result = described_class.merge(old, new) - result.foo.value.should == "old" - result.bar.value.should == "new" + expect(result.foo.value).to eq("old") + expect(result.bar.value).to eq("new") end it "should merge conflicting classes by calling `merge`" do @@ -108,7 +108,7 @@ describe Vagrant::Config::V2::Loader do new.foo.value = 15 result = described_class.merge(old, new) - result.foo.value.should == 25 + expect(result.foo.value).to eq(25) end end @@ -143,9 +143,9 @@ describe Vagrant::Config::V2::Loader do old.foo.value = 5 data = described_class.upgrade(old) - data[0].foo.value.should == 10 - data[1].should == ["foo"] - data[2].should == ["bar"] + expect(data[0].foo.value).to eq(10) + expect(data[1]).to eq(["foo"]) + expect(data[2]).to eq(["bar"]) end end end diff --git a/test/unit/vagrant/config/v2/root_test.rb b/test/unit/vagrant/config/v2/root_test.rb index fdd8c3d41..eaf67b038 100644 --- a/test/unit/vagrant/config/v2/root_test.rb +++ b/test/unit/vagrant/config/v2/root_test.rb @@ -11,14 +11,14 @@ describe Vagrant::Config::V2::Root do instance = described_class.new(map) foo = instance.foo - foo.should be_kind_of(foo_class) - instance.foo.should eql(foo) + expect(foo).to be_kind_of(foo_class) + expect(instance.foo).to eql(foo) end it "record a missing key call if invalid key used" do instance = described_class.new({}) expect { instance.foo }.to_not raise_error - instance.__internal_state["missing_key_calls"].include?("foo").should be + expect(instance.__internal_state["missing_key_calls"].include?("foo")).to be end it "returns a dummy config for a missing key" do @@ -28,17 +28,17 @@ describe Vagrant::Config::V2::Root do it "can be created with initial state" do instance = described_class.new({}, { :foo => "bar" }) - instance.foo.should == "bar" + expect(instance.foo).to eq("bar") end it "should return internal state" do map = { "foo" => Object, "bar" => Object } instance = described_class.new(map) - instance.__internal_state.should == { + expect(instance.__internal_state).to eq({ "config_map" => map, "keys" => {}, "missing_key_calls" => Set.new - } + }) end describe "#finalize!" do @@ -55,14 +55,14 @@ describe Vagrant::Config::V2::Root do instance = described_class.new(map) instance.finalize! - instance.foo.foo.should == "SET" + expect(instance.foo.foo).to eq("SET") end it "should call #_finalize!" do klass = Class.new(Vagrant.plugin("2", "config")) - klass.any_instance.should_receive(:finalize!) - klass.any_instance.should_receive(:_finalize!) + expect_any_instance_of(klass).to receive(:finalize!) + expect_any_instance_of(klass).to receive(:_finalize!) map = { foo: klass } instance = described_class.new(map) @@ -77,7 +77,7 @@ describe Vagrant::Config::V2::Root do end it "should return nil if valid" do - instance.validate({}).should == {} + expect(instance.validate({})).to eq({}) end it "should return errors if invalid" do @@ -88,7 +88,7 @@ describe Vagrant::Config::V2::Root do env["errors"] end - instance.validate(env).should == errors + expect(instance.validate(env)).to eq(errors) end it "should merge errors via array concat if matching keys" do @@ -109,7 +109,7 @@ describe Vagrant::Config::V2::Root do "bar" => ["bar"] } - instance.validate(env).should == expected_errors + expect(instance.validate(env)).to eq(expected_errors) end it "shouldn't count empty keys" do @@ -120,7 +120,7 @@ describe Vagrant::Config::V2::Root do env["errors"] end - instance.validate(env).should == {} + expect(instance.validate(env)).to eq({}) end end end diff --git a/test/unit/vagrant/config/v2/util_test.rb b/test/unit/vagrant/config/v2/util_test.rb index ee0d4d2f7..ff49005d0 100644 --- a/test/unit/vagrant/config/v2/util_test.rb +++ b/test/unit/vagrant/config/v2/util_test.rb @@ -15,7 +15,7 @@ describe Vagrant::Config::V2::Util do } result = described_class.merge_errors(first, second) - result.should == expected + expect(result).to eq(expected) end end end diff --git a/test/unit/vagrant/config_test.rb b/test/unit/vagrant/config_test.rb index 28f35f1f2..5f05828cb 100644 --- a/test/unit/vagrant/config_test.rb +++ b/test/unit/vagrant/config_test.rb @@ -20,14 +20,14 @@ describe Vagrant::Config do end end - procs.should be_kind_of(Array) - procs.length.should == 2 - procs[0][0].should == "1" - procs[1][0].should == "2" + expect(procs).to be_kind_of(Array) + expect(procs.length).to eq(2) + expect(procs[0][0]).to eq("1") + expect(procs[1][0]).to eq("2") # Verify the proper procs were captured - receiver.should_receive(:one).once.ordered - receiver.should_receive(:two).once.ordered + expect(receiver).to receive(:one).once.ordered + expect(receiver).to receive(:two).once.ordered procs[0][1].call procs[1][1].call end @@ -45,14 +45,14 @@ describe Vagrant::Config do end end - procs.should be_kind_of(Array) - procs.length.should == 2 - procs[0][0].should == "1" - procs[1][0].should == "2" + expect(procs).to be_kind_of(Array) + expect(procs.length).to eq(2) + expect(procs[0][0]).to eq("1") + expect(procs[1][0]).to eq("2") # Verify the proper procs were captured - receiver.should_receive(:one).once.ordered - receiver.should_receive(:two).once.ordered + expect(receiver).to receive(:one).once.ordered + expect(receiver).to receive(:two).once.ordered procs[0][1].call procs[1][1].call end @@ -67,12 +67,12 @@ describe Vagrant::Config do end # Verify the structure of the result - procs.should be_kind_of(Array) - procs.length.should == 1 + expect(procs).to be_kind_of(Array) + expect(procs.length).to eq(1) # Verify that the proper proc was captured - receiver.should_receive(:hello!).once - procs[0][0].should == "1" + expect(receiver).to receive(:hello!).once + expect(procs[0][0]).to eq("1") procs[0][1].call end @@ -83,9 +83,9 @@ describe Vagrant::Config do end # Verify the structure of the result - procs.should be_kind_of(Array) - procs.length.should == 2 - procs[0][0].should == "1" - procs[1][0].should == "2" + expect(procs).to be_kind_of(Array) + expect(procs.length).to eq(2) + expect(procs[0][0]).to eq("1") + expect(procs[1][0]).to eq("2") end end diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index b1fa74985..218e20e4a 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -29,7 +29,7 @@ describe Vagrant::Environment do it "is set to the home path given" do Dir.mktmpdir do |dir| instance = described_class.new(:home_path => dir) - instance.home_path.should == Pathname.new(dir) + expect(instance.home_path).to eq(Pathname.new(dir)) end end @@ -39,7 +39,7 @@ describe Vagrant::Environment do described_class.new end - instance.home_path.should == Pathname.new(dir) + expect(instance.home_path).to eq(Pathname.new(dir)) end end @@ -111,9 +111,9 @@ describe Vagrant::Environment do Vagrant::Environment.any_instance.stub(boxes: double("boxes")) collection = double("collection") - Vagrant::BoxCollection.should_receive(:new).with( + expect(Vagrant::BoxCollection).to receive(:new).with( env.homedir.join("boxes"), anything).and_return(collection) - collection.should_receive(:upgrade_v1_1_v1_5).once + expect(collection).to receive(:upgrade_v1_1_v1_5).once subject end end @@ -262,10 +262,10 @@ VF # Verify that we can get the machine env = isolated_env.create_vagrant_env machine = env.machine(:foo, :foo) - machine.should be_kind_of(Vagrant::Machine) - machine.name.should == :foo - machine.provider.should be_kind_of(foo_provider) - machine.provider_config.should be_nil + expect(machine).to be_kind_of(Vagrant::Machine) + expect(machine.name).to eq(:foo) + expect(machine.provider).to be_kind_of(foo_provider) + expect(machine.provider_config).to be_nil end it "should return a machine object with the machine configuration" do @@ -295,10 +295,10 @@ VF # Verify that we can get the machine env = isolated_env.create_vagrant_env machine = env.machine(:foo, :foo) - machine.should be_kind_of(Vagrant::Machine) - machine.name.should == :foo - machine.provider.should be_kind_of(foo_provider) - machine.provider_config.value.should == 100 + expect(machine).to be_kind_of(Vagrant::Machine) + expect(machine.name).to eq(:foo) + expect(machine.provider).to be_kind_of(foo_provider) + expect(machine.provider_config.value).to eq(100) end it "should cache the machine objects by name and provider" do @@ -325,10 +325,10 @@ VF vm1_bar = env.machine(:vm1, :bar) vm2_foo = env.machine(:vm2, :foo) - vm1_foo.should eql(env.machine(:vm1, :foo)) - vm1_bar.should eql(env.machine(:vm1, :bar)) - vm1_foo.should_not eql(vm1_bar) - vm2_foo.should eql(env.machine(:vm2, :foo)) + expect(vm1_foo).to eql(env.machine(:vm1, :foo)) + expect(vm1_bar).to eql(env.machine(:vm1, :bar)) + expect(vm1_foo).not_to eql(vm1_bar) + expect(vm2_foo).to eql(env.machine(:vm2, :foo)) end it "should load a machine without a box" do @@ -344,7 +344,7 @@ VF env = environment.create_vagrant_env machine = env.machine(:default, :foo) - machine.box.should be_nil + expect(machine.box).to be_nil end it "should load the machine configuration" do @@ -367,8 +367,8 @@ VF env = environment.create_vagrant_env machine = env.machine(:vm1, :foo) - machine.config.ssh.port.should == 100 - machine.config.vm.box.should == "base" + expect(machine.config.ssh.port).to eq(100) + expect(machine.config.vm.box).to eq("base") end it "should load the box configuration for a box" do @@ -390,7 +390,7 @@ VF env = environment.create_vagrant_env machine = env.machine(:default, :foo) - machine.config.ssh.port.should == 100 + expect(machine.config.ssh.port).to eq(100) end it "should load the box configuration for a box and custom Vagrantfile name" do @@ -415,7 +415,7 @@ VF end machine = env.machine(:default, :foo) - machine.config.ssh.port.should == 100 + expect(machine.config.ssh.port).to eq(100) end it "should load the box configuration for other formats for a box" do @@ -437,7 +437,7 @@ VF env = environment.create_vagrant_env machine = env.machine(:default, :foo) - machine.config.ssh.port.should == 100 + expect(machine.config.ssh.port).to eq(100) end it "prefer sooner formats when multiple box formats are available" do @@ -465,7 +465,7 @@ VF env = environment.create_vagrant_env machine = env.machine(:default, :foo) - machine.config.ssh.port.should == 100 + expect(machine.config.ssh.port).to eq(100) end it "should load the proper version of a box" do @@ -494,7 +494,7 @@ VF env = environment.create_vagrant_env machine = env.machine(:default, :foo) - machine.config.ssh.port.should == 200 + expect(machine.config.ssh.port).to eq(200) end it "should load the provider override if set" do @@ -516,8 +516,8 @@ VF env = isolated_env.create_vagrant_env foo_vm = env.machine(:default, :foo) bar_vm = env.machine(:default, :bar) - foo_vm.config.vm.box.should == "bar" - bar_vm.config.vm.box.should == "foo" + expect(foo_vm.config.vm.box).to eq("bar") + expect(bar_vm.config.vm.box).to eq("foo") end it "should reload the cache if refresh is set" do @@ -540,8 +540,8 @@ VF vm2 = env.machine(:default, :foo, true) vm3 = env.machine(:default, :foo) - vm1.should_not eql(vm2) - vm2.should eql(vm3) + expect(vm1).not_to eql(vm2) + expect(vm2).to eql(vm3) end it "should raise an error if the VM is not found" do @@ -558,9 +558,9 @@ VF describe "active machines" do it "should be empty if the machines folder doesn't exist" do folder = instance.local_data_path.join("machines") - folder.should_not be_exist + expect(folder).not_to be_exist - instance.active_machines.should be_empty + expect(instance.active_machines).to be_empty end it "should return the name and provider of active machines" do @@ -575,22 +575,22 @@ VF machine_bar = machines.join("bar/virtualbox") machine_bar.mkpath - instance.active_machines.should == [[:foo, :virtualbox]] + expect(instance.active_machines).to eq([[:foo, :virtualbox]]) end end describe "batching" do let(:batch) do double("batch") do |b| - b.stub(:run) + allow(b).to receive(:run) end end context "without the disabling env var" do it "should run without disabling parallelization" do with_temp_env("VAGRANT_NO_PARALLEL" => nil) do - Vagrant::BatchAction.should_receive(:new).with(true).and_return(batch) - batch.should_receive(:run) + expect(Vagrant::BatchAction).to receive(:new).with(true).and_return(batch) + expect(batch).to receive(:run) instance.batch {} end @@ -598,8 +598,8 @@ VF it "should run with disabling parallelization if explicit" do with_temp_env("VAGRANT_NO_PARALLEL" => nil) do - Vagrant::BatchAction.should_receive(:new).with(false).and_return(batch) - batch.should_receive(:run) + expect(Vagrant::BatchAction).to receive(:new).with(false).and_return(batch) + expect(batch).to receive(:run) instance.batch(false) {} end @@ -609,8 +609,8 @@ VF context "with the disabling env var" do it "should run with disabling parallelization" do with_temp_env("VAGRANT_NO_PARALLEL" => "yes") do - Vagrant::BatchAction.should_receive(:new).with(false).and_return(batch) - batch.should_receive(:run) + expect(Vagrant::BatchAction).to receive(:new).with(false).and_return(batch) + expect(batch).to receive(:run) instance.batch {} end @@ -623,7 +623,7 @@ VF Dir.mktmpdir do |temp_dir| Dir.chdir(temp_dir) do with_temp_env("VAGRANT_CWD" => nil) do - described_class.new.cwd.should == Pathname.new(Dir.pwd) + expect(described_class.new.cwd).to eq(Pathname.new(Dir.pwd)) end end end @@ -632,7 +632,7 @@ VF it "is set to the cwd given" do Dir.mktmpdir do |directory| instance = described_class.new(:cwd => directory) - instance.cwd.should == Pathname.new(directory) + expect(instance.cwd).to eq(Pathname.new(directory)) end end @@ -642,7 +642,7 @@ VF described_class.new end - instance.cwd.should == Pathname.new(directory) + expect(instance.cwd).to eq(Pathname.new(directory)) end end @@ -655,13 +655,13 @@ VF describe "default provider" do it "is virtualbox without any environmental variable" do with_temp_env("VAGRANT_DEFAULT_PROVIDER" => nil) do - subject.default_provider.should == :virtualbox + expect(subject.default_provider).to eq(:virtualbox) end end it "is whatever the environmental variable is if set" do with_temp_env("VAGRANT_DEFAULT_PROVIDER" => "foo") do - subject.default_provider.should == :foo + expect(subject.default_provider).to eq(:foo) end end end @@ -669,18 +669,18 @@ VF describe "local data path" do it "is set to the proper default" do default = instance.root_path.join(described_class::DEFAULT_LOCAL_DATA) - instance.local_data_path.should == default + expect(instance.local_data_path).to eq(default) end it "is expanded relative to the cwd" do instance = described_class.new(:local_data_path => "foo") - instance.local_data_path.should == instance.cwd.join("foo") + expect(instance.local_data_path).to eq(instance.cwd.join("foo")) end it "is set to the given value" do Dir.mktmpdir do |dir| instance = described_class.new(:local_data_path => dir) - instance.local_data_path.to_s.should == dir + expect(instance.local_data_path.to_s).to eq(dir) end end @@ -701,7 +701,7 @@ VF end expect { instance }.to_not raise_error - Pathname.new(local_data_path).should be_directory + expect(Pathname.new(local_data_path)).to be_directory end it "should upgrade all active VMs" do @@ -720,12 +720,12 @@ VF local_data_pathname = Pathname.new(local_data_path) foo_id_file = local_data_pathname.join("machines/foo/virtualbox/id") - foo_id_file.should be_file - foo_id_file.read.should == "foo_id" + expect(foo_id_file).to be_file + expect(foo_id_file.read).to eq("foo_id") bar_id_file = local_data_pathname.join("machines/bar/virtualbox/id") - bar_id_file.should be_file - bar_id_file.read.should == "bar_id" + expect(bar_id_file).to be_file + expect(bar_id_file.read).to eq("bar_id") end it "should raise an error if invalid JSON" do @@ -745,18 +745,18 @@ VF instance = described_class.new(:home_path => env.homedir) pk = env.homedir.join("insecure_private_key") - pk.should be_exist + expect(pk).to be_exist if !Vagrant::Util::Platform.windows? - Vagrant::Util::FileMode.from_octal(pk.stat.mode).should == "600" + expect(Vagrant::Util::FileMode.from_octal(pk.stat.mode)).to eq("600") end end end it "has a box collection pointed to the proper directory" do collection = instance.boxes - collection.should be_kind_of(Vagrant::BoxCollection) - collection.directory.should == instance.boxes_path + expect(collection).to be_kind_of(Vagrant::BoxCollection) + expect(collection.directory).to eq(instance.boxes_path) # Reach into some internal state here but not sure how else # to test this at the moment. @@ -766,7 +766,7 @@ VF describe "action runner" do it "has an action runner" do - instance.action_runner.should be_kind_of(Vagrant::Action::Runner) + expect(instance.action_runner).to be_kind_of(Vagrant::Action::Runner) end it "has a `ui` in the globals" do @@ -774,7 +774,7 @@ VF callable = lambda { |env| result = env[:ui] } instance.action_runner.run(callable) - result.should eql(instance.ui) + expect(result).to eql(instance.ui) end end @@ -782,39 +782,39 @@ VF it "should call the action runner with the proper hook" do hook_name = :foo - instance.action_runner.should_receive(:run).with do |callable, env| - env[:action_name].should == hook_name - end + expect(instance.action_runner).to receive(:run).with { |callable, env| + expect(env[:action_name]).to eq(hook_name) + } instance.hook(hook_name) end it "should return the result of the action runner run" do - instance.action_runner.should_receive(:run).and_return(:foo) + expect(instance.action_runner).to receive(:run).and_return(:foo) - instance.hook(:bar).should == :foo + expect(instance.hook(:bar)).to eq(:foo) end it "should allow passing in a custom action runner" do - instance.action_runner.should_not_receive(:run) + expect(instance.action_runner).not_to receive(:run) other_runner = double("runner") - other_runner.should_receive(:run).and_return(:foo) + expect(other_runner).to receive(:run).and_return(:foo) - instance.hook(:bar, runner: other_runner).should == :foo + expect(instance.hook(:bar, runner: other_runner)).to eq(:foo) end it "should allow passing in custom data" do - instance.action_runner.should_receive(:run).with do |callable, env| - env[:foo].should == :bar - end + expect(instance.action_runner).to receive(:run).with { |callable, env| + expect(env[:foo]).to eq(:bar) + } instance.hook(:foo, foo: :bar) end it "should allow passing a custom callable" do - instance.action_runner.should_receive(:run).with do |callable, env| - callable.should == :what - end + expect(instance.action_runner).to receive(:run).with { |callable, env| + expect(callable).to eq(:what) + } instance.hook(:foo, callable: :what) end @@ -822,7 +822,7 @@ VF describe "primary machine name" do it "should be the only machine if not a multi-machine environment" do - instance.primary_machine_name.should == instance.machine_names.first + expect(instance.primary_machine_name).to eq(instance.machine_names.first) end it "should be the machine marked as the primary" do @@ -839,7 +839,7 @@ VF end env = environment.create_vagrant_env - env.primary_machine_name.should == :bar + expect(env.primary_machine_name).to eq(:bar) end it "should be nil if no primary is specified in a multi-machine environment" do @@ -856,7 +856,7 @@ VF end env = environment.create_vagrant_env - env.primary_machine_name.should be_nil + expect(env.primary_machine_name).to be_nil end end @@ -871,7 +871,7 @@ VF end env = environment.create_vagrant_env - env.vagrantfile.config.ssh.port.should == 200 + expect(env.vagrantfile.config.ssh.port).to eq(200) end it "should load from a custom Vagrantfile" do @@ -884,7 +884,7 @@ VF end env = environment.create_vagrant_env(:vagrantfile_name => "non_standard_name") - env.vagrantfile.config.ssh.port.should == 200 + expect(env.vagrantfile.config.ssh.port).to eq(200) end it "should load from a custom Vagrantfile specified by env var" do @@ -900,13 +900,13 @@ VF environment.create_vagrant_env end - env.vagrantfile.config.ssh.port.should == 400 + expect(env.vagrantfile.config.ssh.port).to eq(400) end end describe "ui" do it "should be a silent UI by default" do - described_class.new.ui.should be_kind_of(Vagrant::UI::Silent) + expect(described_class.new.ui).to be_kind_of(Vagrant::UI::Silent) end it "should be a UI given in the constructor" do @@ -914,13 +914,13 @@ VF class CustomUI < Vagrant::UI::Interface; end instance = described_class.new(:ui_class => CustomUI) - instance.ui.should be_kind_of(CustomUI) + expect(instance.ui).to be_kind_of(CustomUI) end end describe "#unload" do it "should run the unload hook" do - instance.should_receive(:hook).with(:environment_unload).once + expect(instance).to receive(:hook).with(:environment_unload).once instance.unload end end @@ -936,7 +936,7 @@ VF end env = isolated_env.create_vagrant_env - env.machine_names.should == [:default] + expect(env.machine_names).to eq([:default]) end it "should return the machine names in order" do @@ -951,7 +951,7 @@ VF end env = isolated_env.create_vagrant_env - env.machine_names.should == [:foo, :bar] + expect(env.machine_names).to eq([:foo, :bar]) end end end diff --git a/test/unit/vagrant/errors_test.rb b/test/unit/vagrant/errors_test.rb index fb5423bd0..7f71f4872 100644 --- a/test/unit/vagrant/errors_test.rb +++ b/test/unit/vagrant/errors_test.rb @@ -11,17 +11,20 @@ describe Vagrant::Errors::VagrantError do subject { klass.new } it "should use the translation for the message" do - subject.to_s.should == "test value" + expect(subject.to_s).to eq("test value") end - its("status_code") { should eq(1) } + describe '#status_code' do + subject { super().status_code } + it { should eq(1) } + end end describe "passing error key through options" do subject { described_class.new(_key: "test_key") } it "should use the translation for the message" do - subject.to_s.should == "test value" + expect(subject.to_s).to eq("test value") end end @@ -35,7 +38,7 @@ describe Vagrant::Errors::VagrantError do subject { klass.new(data: "yep") } it "should use the translation for the message" do - subject.to_s.should == "foo" + expect(subject.to_s).to eq("foo") end it "should expose translation keys to the user" do diff --git a/test/unit/vagrant/guest_test.rb b/test/unit/vagrant/guest_test.rb index b41f584a2..07d60f298 100644 --- a/test/unit/vagrant/guest_test.rb +++ b/test/unit/vagrant/guest_test.rb @@ -48,7 +48,7 @@ describe Vagrant::Guest do describe "#detect!" do it "auto-detects if no explicit guest name given" do machine.config.vm.stub(guest: nil) - subject.should_receive(:initialize_capabilities!). + expect(subject).to receive(:initialize_capabilities!). with(nil, guests, capabilities, machine) subject.detect! @@ -56,7 +56,7 @@ describe Vagrant::Guest do it "uses the explicit guest name if specified" do machine.config.vm.stub(guest: :foo) - subject.should_receive(:initialize_capabilities!). + expect(subject).to receive(:initialize_capabilities!). with(:foo, guests, capabilities, machine) subject.detect! @@ -91,12 +91,12 @@ describe Vagrant::Guest do end it "should not be ready by default" do - subject.ready?.should_not be + expect(subject.ready?).not_to be end it "should be ready after detecting" do subject.detect! - subject.ready?.should be + expect(subject.ready?).to be end end end diff --git a/test/unit/vagrant/host_test.rb b/test/unit/vagrant/host_test.rb index 9b4c2d40c..b0f3d65f9 100644 --- a/test/unit/vagrant/host_test.rb +++ b/test/unit/vagrant/host_test.rb @@ -10,7 +10,7 @@ describe Vagrant::Host do let(:env) { Object.new } it "initializes the capabilities" do - described_class.any_instance.should_receive(:initialize_capabilities!). + expect_any_instance_of(described_class).to receive(:initialize_capabilities!). with(:foo, hosts, capabilities, env) described_class.new(:foo, hosts, capabilities, env) diff --git a/test/unit/vagrant/machine_state_test.rb b/test/unit/vagrant/machine_state_test.rb index 7b40fd720..6c53845c7 100644 --- a/test/unit/vagrant/machine_state_test.rb +++ b/test/unit/vagrant/machine_state_test.rb @@ -11,16 +11,16 @@ describe Vagrant::MachineState do it "should give access to the id" do instance = described_class.new(id, short, long) - instance.id.should == id + expect(instance.id).to eq(id) end it "should give access to the short description" do instance = described_class.new(id, short, long) - instance.short_description.should == short + expect(instance.short_description).to eq(short) end it "should give access to the long description" do instance = described_class.new(id, short, long) - instance.long_description.should == long + expect(instance.long_description).to eq(long) end end diff --git a/test/unit/vagrant/machine_test.rb b/test/unit/vagrant/machine_test.rb index 0691454fa..08efef37e 100644 --- a/test/unit/vagrant/machine_test.rb +++ b/test/unit/vagrant/machine_test.rb @@ -62,25 +62,25 @@ describe Vagrant::Machine do end provider_cls = double("provider_cls") - provider_cls.should_receive(:new) do |machine| + expect(provider_cls).to receive(:new) { |machine| # Store this for later so we can verify that it is the # one we expected to receive. received_machine = machine # Sanity check - machine.should be + expect(machine).to be # Yield our machine if we want to do additional tests yield machine if block_given? true - end.and_return(instance) + }.and_return(instance) # Initialize a new machine and verify that we properly receive # the machine we expect. instance = described_class.new(name, provider_name, provider_cls, provider_config, provider_options, config, data_dir, box, env, env.vagrantfile) - received_machine.should eql(instance) + expect(received_machine).to eql(instance) end it "should initialize with the machine object" do @@ -90,25 +90,25 @@ describe Vagrant::Machine do it "should have the machine name setup" do provider_init_test do |machine| - machine.name.should == name + expect(machine.name).to eq(name) end end it "should have the machine configuration" do provider_init_test do |machine| - machine.config.should eql(config) + expect(machine.config).to eql(config) end end it "should have the box" do provider_init_test do |machine| - machine.box.should eql(box) + expect(machine.box).to eql(box) end end it "should have the environment" do provider_init_test do |machine| - machine.env.should eql(env) + expect(machine.env).to eql(env) end end @@ -120,29 +120,29 @@ describe Vagrant::Machine do it "should have access to the ID" do # Stub this because #id= calls it. - provider.stub(:machine_id_changed) + allow(provider).to receive(:machine_id_changed) # Set the ID on the previous instance so that it is persisted instance.id = "foo" provider_init_test do |machine| - machine.id.should == "foo" + expect(machine.id).to eq("foo") end end it "should NOT have access to the provider" do provider_init_test do |machine| - machine.provider.should be_nil + expect(machine.provider).to be_nil end end it "should initialize the capabilities" do instance = double("instance") - instance.should_receive(:_initialize).with do |p, m| + expect(instance).to receive(:_initialize).with { |p, m| expect(p).to eq(provider_name) expect(m.name).to eq(name) true - end + } provider_init_test(instance) end @@ -150,13 +150,40 @@ describe Vagrant::Machine do end describe "attributes" do - its(:name) { should eq(name) } - its(:config) { should eql(config) } - its(:box) { should eql(box) } - its(:env) { should eql(env) } - its(:provider) { should eql(provider) } - its(:provider_config) { should eql(provider_config) } - its(:provider_options) { should eq(provider_options) } + describe '#name' do + subject { super().name } + it { should eq(name) } + end + + describe '#config' do + subject { super().config } + it { should eql(config) } + end + + describe '#box' do + subject { super().box } + it { should eql(box) } + end + + describe '#env' do + subject { super().env } + it { should eql(env) } + end + + describe '#provider' do + subject { super().provider } + it { should eql(provider) } + end + + describe '#provider_config' do + subject { super().provider_config } + it { should eql(provider_config) } + end + + describe '#provider_options' do + subject { super().provider_options } + it { should eq(provider_options) } + end end describe "actions" do @@ -165,9 +192,9 @@ describe Vagrant::Machine do called = false callable = lambda { |_env| called = true } - provider.should_receive(:action).with(action_name).and_return(callable) + expect(provider).to receive(:action).with(action_name).and_return(callable) instance.action(:up) - called.should be + expect(called).to be end it "should provide the machine in the environment" do @@ -175,10 +202,10 @@ describe Vagrant::Machine do machine = nil callable = lambda { |env| machine = env[:machine] } - provider.stub(:action).with(action_name).and_return(callable) + allow(provider).to receive(:action).with(action_name).and_return(callable) instance.action(:up) - machine.should eql(instance) + expect(machine).to eql(instance) end it "should pass any extra options to the environment" do @@ -186,26 +213,26 @@ describe Vagrant::Machine do foo = nil callable = lambda { |env| foo = env[:foo] } - provider.stub(:action).with(action_name).and_return(callable) + allow(provider).to receive(:action).with(action_name).and_return(callable) instance.action(:up, :foo => :bar) - foo.should == :bar + expect(foo).to eq(:bar) end it "should return the environment as a result" do action_name = :up callable = lambda { |env| env[:result] = "FOO" } - provider.stub(:action).with(action_name).and_return(callable) + allow(provider).to receive(:action).with(action_name).and_return(callable) result = instance.action(action_name) - result[:result].should == "FOO" + expect(result[:result]).to eq("FOO") end it "should raise an exception if the action is not implemented" do action_name = :up - provider.stub(:action).with(action_name).and_return(nil) + allow(provider).to receive(:action).with(action_name).and_return(nil) expect { instance.action(action_name) }. to raise_error(Vagrant::Errors::UnimplementedProviderAction) @@ -214,20 +241,20 @@ describe Vagrant::Machine do describe "communicator" do it "should always return the SSH communicator" do - instance.communicate.should be_kind_of(VagrantPlugins::CommunicatorSSH::Communicator) + expect(instance.communicate).to be_kind_of(VagrantPlugins::CommunicatorSSH::Communicator) end it "should memoize the result" do obj = instance.communicate - instance.communicate.should eql(obj) + expect(instance.communicate).to eql(obj) end end describe "guest implementation" do let(:communicator) do result = double("communicator") - result.stub(:ready?).and_return(true) - result.stub(:test).and_return(false) + allow(result).to receive(:ready?).and_return(true) + allow(result).to receive(:test).and_return(false) result end @@ -242,11 +269,11 @@ describe Vagrant::Machine do p.guest(:test) { test_guest } end - instance.stub(:communicate).and_return(communicator) + allow(instance).to receive(:communicate).and_return(communicator) end it "should raise an exception if communication is not ready" do - communicator.should_receive(:ready?).and_return(false) + expect(communicator).to receive(:ready?).and_return(false) expect { instance.guest }. to raise_error(Vagrant::Errors::MachineGuestNotReady) @@ -254,7 +281,7 @@ describe Vagrant::Machine do it "should return the configured guest" do result = instance.guest - result.should be_kind_of(Vagrant::Guest) + expect(result).to be_kind_of(Vagrant::Guest) expect(result).to be_ready expect(result.capability_host_chain[0][0]).to eql(:test) end @@ -262,47 +289,47 @@ describe Vagrant::Machine do describe "setting the ID" do before(:each) do - provider.stub(:machine_id_changed) + allow(provider).to receive(:machine_id_changed) end it "should not have an ID by default" do - instance.id.should be_nil + expect(instance.id).to be_nil end it "should set an ID" do instance.id = "bar" - instance.id.should == "bar" + expect(instance.id).to eq("bar") end it "should notify the machine that the ID changed" do - provider.should_receive(:machine_id_changed).once + expect(provider).to receive(:machine_id_changed).once instance.id = "bar" end it "should persist the ID" do instance.id = "foo" - new_instance.id.should == "foo" + expect(new_instance.id).to eq("foo") end it "should delete the ID" do instance.id = "foo" second = new_instance - second.id.should == "foo" + expect(second.id).to eq("foo") second.id = nil expect(second.id).to be_nil third = new_instance - third.id.should be_nil + expect(third.id).to be_nil end end describe "ssh info" do describe "with the provider returning nil" do it "should return nil if the provider returns nil" do - provider.should_receive(:ssh_info).and_return(nil) - instance.ssh_info.should be_nil + expect(provider).to receive(:ssh_info).and_return(nil) + expect(instance.ssh_info).to be_nil end end @@ -310,7 +337,7 @@ describe Vagrant::Machine do let(:provider_ssh_info) { {} } before(:each) do - provider.stub(:ssh_info).and_return(provider_ssh_info) + allow(provider).to receive(:ssh_info).and_return(provider_ssh_info) end [:host, :port, :username].each do |type| @@ -318,14 +345,14 @@ describe Vagrant::Machine do provider_ssh_info[type] = "foo" instance.config.ssh.send("#{type}=", nil) - instance.ssh_info[type].should == "foo" + expect(instance.ssh_info[type]).to eq("foo") end it "should return the Vagrantfile value if provider data not given" do provider_ssh_info[type] = nil instance.config.ssh.send("#{type}=", "bar") - instance.ssh_info[type].should == "bar" + expect(instance.ssh_info[type]).to eq("bar") end it "should use the default if no override and no provider" do @@ -333,7 +360,7 @@ describe Vagrant::Machine do instance.config.ssh.send("#{type}=", nil) instance.config.ssh.default.send("#{type}=", "foo") - instance.ssh_info[type].should == "foo" + expect(instance.ssh_info[type]).to eq("foo") end it "should use the override if set even with a provider" do @@ -341,7 +368,7 @@ describe Vagrant::Machine do instance.config.ssh.send("#{type}=", "bar") instance.config.ssh.default.send("#{type}=", "foo") - instance.ssh_info[type].should == "bar" + expect(instance.ssh_info[type]).to eq("bar") end end @@ -349,53 +376,55 @@ describe Vagrant::Machine do provider_ssh_info[:forward_agent] = true instance.config.ssh.forward_agent = false - instance.ssh_info[:forward_agent].should == false + expect(instance.ssh_info[:forward_agent]).to eq(false) end it "should set the configured forward X11 settings" do provider_ssh_info[:forward_x11] = true instance.config.ssh.forward_x11 = false - instance.ssh_info[:forward_x11].should == false + expect(instance.ssh_info[:forward_x11]).to eq(false) end it "should return the provider private key if given" do provider_ssh_info[:private_key_path] = "/foo" - instance.ssh_info[:private_key_path].should == [File.expand_path("/foo", env.root_path)] + expect(instance.ssh_info[:private_key_path]).to eq([File.expand_path("/foo", env.root_path)]) end it "should return the configured SSH key path if set" do provider_ssh_info[:private_key_path] = nil instance.config.ssh.private_key_path = "/bar" - instance.ssh_info[:private_key_path].should == [File.expand_path("/bar", env.root_path)] + expect(instance.ssh_info[:private_key_path]).to eq([File.expand_path("/bar", env.root_path)]) end it "should return the array of SSH keys if set" do provider_ssh_info[:private_key_path] = nil instance.config.ssh.private_key_path = ["/foo", "/bar"] - instance.ssh_info[:private_key_path].should == [ + expect(instance.ssh_info[:private_key_path]).to eq([ File.expand_path("/foo", env.root_path), File.expand_path("/bar", env.root_path), - ] + ]) end context "expanding path relative to the root path" do it "should with the provider key path" do provider_ssh_info[:private_key_path] = "~/foo" - instance.ssh_info[:private_key_path].should == + expect(instance.ssh_info[:private_key_path]).to eq( [File.expand_path("~/foo", env.root_path)] + ) end it "should with the config private key path" do provider_ssh_info[:private_key_path] = nil instance.config.ssh.private_key_path = "~/bar" - instance.ssh_info[:private_key_path].should == + expect(instance.ssh_info[:private_key_path]).to eq( [File.expand_path("~/bar", env.root_path)] + ) end end @@ -403,8 +432,9 @@ describe Vagrant::Machine do provider_ssh_info[:private_key_path] = nil instance.config.ssh.private_key_path = nil - instance.ssh_info[:private_key_path].should == + expect(instance.ssh_info[:private_key_path]).to eq( [instance.env.default_private_key_path.to_s] + ) end it "should not set any default private keys if a password is specified" do @@ -436,12 +466,12 @@ describe Vagrant::Machine do it "should query state from the provider" do state = Vagrant::MachineState.new(:id, "short", "long") - provider.should_receive(:state).and_return(state) - instance.state.id.should == :id + expect(provider).to receive(:state).and_return(state) + expect(instance.state.id).to eq(:id) end it "should raise an exception if a MachineState is not returned" do - provider.should_receive(:state).and_return(:old_school) + expect(provider).to receive(:state).and_return(:old_school) expect { instance.state }. to raise_error(Vagrant::Errors::MachineStateInvalid) end diff --git a/test/unit/vagrant/plugin/manager_test.rb b/test/unit/vagrant/plugin/manager_test.rb index f893f06c5..62cbc8785 100644 --- a/test/unit/vagrant/plugin/manager_test.rb +++ b/test/unit/vagrant/plugin/manager_test.rb @@ -34,10 +34,10 @@ describe Vagrant::Plugin::Manager do it "installs the plugin and adds it to the state file" do specs = Array.new(5) { Gem::Specification.new } specs[3].name = "foo" - bundler.should_receive(:install).once.with do |plugins, local| + expect(bundler).to receive(:install).once.with { |plugins, local| expect(plugins).to have_key("foo") expect(local).to be_false - end.and_return(specs) + }.and_return(specs) result = subject.install_plugin("foo") @@ -49,14 +49,14 @@ describe Vagrant::Plugin::Manager do end it "masks GemNotFound with our error" do - bundler.should_receive(:install).and_raise(Bundler::GemNotFound) + expect(bundler).to receive(:install).and_raise(Bundler::GemNotFound) expect { subject.install_plugin("foo") }. to raise_error(Vagrant::Errors::PluginGemNotFound) end it "masks bundler errors with our own error" do - bundler.should_receive(:install).and_raise(Bundler::InstallError) + expect(bundler).to receive(:install).and_raise(Bundler::InstallError) expect { subject.install_plugin("foo") }. to raise_error(Vagrant::Errors::BundlerError) @@ -70,14 +70,14 @@ describe Vagrant::Plugin::Manager do local_spec.name = "bar" local_spec.version = version - bundler.should_receive(:install_local).with(name). + expect(bundler).to receive(:install_local).with(name). ordered.and_return(local_spec) - bundler.should_receive(:install).once.with do |plugins, local| + expect(bundler).to receive(:install).once.with { |plugins, local| expect(plugins).to have_key("bar") expect(plugins["bar"]["gem_version"]).to eql("#{version}") expect(local).to be_true - end.ordered.and_return([local_spec]) + }.ordered.and_return([local_spec]) subject.install_plugin(name) @@ -94,15 +94,15 @@ describe Vagrant::Plugin::Manager do end before do - bundler.stub(:install).and_return(specs) + allow(bundler).to receive(:install).and_return(specs) end it "installs a version with constraints" do - bundler.should_receive(:install).once.with do |plugins, local| + expect(bundler).to receive(:install).once.with { |plugins, local| expect(plugins).to have_key("foo") expect(plugins["foo"]["gem_version"]).to eql(">= 0.1.0") expect(local).to be_false - end.and_return(specs) + }.and_return(specs) subject.install_plugin("foo", version: ">= 0.1.0") @@ -112,11 +112,11 @@ describe Vagrant::Plugin::Manager do end it "installs with an exact version but doesn't constrain" do - bundler.should_receive(:install).once.with do |plugins, local| + expect(bundler).to receive(:install).once.with { |plugins, local| expect(plugins).to have_key("foo") expect(plugins["foo"]["gem_version"]).to eql("0.1.0") expect(local).to be_false - end.and_return(specs) + }.and_return(specs) subject.install_plugin("foo", version: "0.1.0") @@ -136,7 +136,7 @@ describe Vagrant::Plugin::Manager do expect(subject.installed_plugins).to have_key("foo") # Test - bundler.should_receive(:clean).once.with({}) + expect(bundler).to receive(:clean).once.with({}) # Remove it subject.uninstall_plugin("foo") @@ -144,7 +144,7 @@ describe Vagrant::Plugin::Manager do end it "masks bundler errors with our own error" do - bundler.should_receive(:clean).and_raise(Bundler::InstallError) + expect(bundler).to receive(:clean).and_raise(Bundler::InstallError) expect { subject.uninstall_plugin("foo") }. to raise_error(Vagrant::Errors::BundlerError) @@ -168,7 +168,7 @@ describe Vagrant::Plugin::Manager do sf.add_plugin("bar") # Test - bundler.should_receive(:clean).once.with(anything) + expect(bundler).to receive(:clean).once.with(anything) # Remove it subject.uninstall_plugin("bar") @@ -186,7 +186,7 @@ describe Vagrant::Plugin::Manager do describe "#update_plugins" do it "masks bundler errors with our own error" do - bundler.should_receive(:update).and_raise(Bundler::InstallError) + expect(bundler).to receive(:update).and_raise(Bundler::InstallError) expect { subject.update_plugins([]) }. to raise_error(Vagrant::Errors::BundlerError) diff --git a/test/unit/vagrant/plugin/v1/command_test.rb b/test/unit/vagrant/plugin/v1/command_test.rb index 7aad4a65e..91fb61643 100644 --- a/test/unit/vagrant/plugin/v1/command_test.rb +++ b/test/unit/vagrant/plugin/v1/command_test.rb @@ -21,20 +21,20 @@ describe Vagrant::Plugin::V1::Command do result = klass.new(["-f", "foo"], nil).parse_options(opts) # Check the results - options[:f].should be - result.should == ["foo"] + expect(options[:f]).to be + expect(result).to eq(["foo"]) end it "creates an option parser if none is given" do result = klass.new(["foo"], nil).parse_options(nil) - result.should == ["foo"] + expect(result).to eq(["foo"]) end ["-h", "--help"].each do |help_string| it "returns nil and prints the help if '#{help_string}' is given" do instance = klass.new([help_string], nil) - instance.should_receive(:safe_puts) - instance.parse_options(OptionParser.new).should be_nil + expect(instance).to receive(:safe_puts) + expect(instance.parse_options(OptionParser.new)).to be_nil end end @@ -70,10 +70,10 @@ describe Vagrant::Plugin::V1::Command do it "should yield every VM in order is no name is given" do foo_vm = double("foo") - foo_vm.stub(:name).and_return("foo") + allow(foo_vm).to receive(:name).and_return("foo") bar_vm = double("bar") - bar_vm.stub(:name).and_return("bar") + allow(bar_vm).to receive(:name).and_return("bar") environment.stub(:multivm? => true, :vms => { "foo" => foo_vm, "bar" => bar_vm }, @@ -84,7 +84,7 @@ describe Vagrant::Plugin::V1::Command do vms << vm end - vms.should == [foo_vm, bar_vm] + expect(vms).to eq([foo_vm, bar_vm]) end it "raises an exception if the named VM doesn't exist" do @@ -96,14 +96,14 @@ describe Vagrant::Plugin::V1::Command do it "yields the given VM if a name is given" do foo_vm = double("foo") - foo_vm.stub(:name).and_return(:foo) + allow(foo_vm).to receive(:name).and_return(:foo) environment.stub(:multivm? => true, :vms => { :foo => foo_vm, :bar => nil }) vms = [] instance.with_target_vms("foo") { |vm| vms << vm } - vms.should == [foo_vm] + expect(vms).to eq([foo_vm]) end end @@ -117,27 +117,27 @@ describe Vagrant::Plugin::V1::Command do it "should work when given all 3 parts" do result = instance.split_main_and_subcommand(["-v", "status", "-h", "-v"]) - result.should == [["-v"], "status", ["-h", "-v"]] + expect(result).to eq([["-v"], "status", ["-h", "-v"]]) end it "should work when given only a subcommand and args" do result = instance.split_main_and_subcommand(["status", "-h"]) - result.should == [[], "status", ["-h"]] + expect(result).to eq([[], "status", ["-h"]]) end it "should work when given only main flags" do result = instance.split_main_and_subcommand(["-v", "-h"]) - result.should == [["-v", "-h"], nil, []] + expect(result).to eq([["-v", "-h"], nil, []]) end it "should work when given only a subcommand" do result = instance.split_main_and_subcommand(["status"]) - result.should == [[], "status", []] + expect(result).to eq([[], "status", []]) end it "works when there are other non-flag args after the subcommand" do result = instance.split_main_and_subcommand(["-v", "box", "add", "-h"]) - result.should == [["-v"], "box", ["add", "-h"]] + expect(result).to eq([["-v"], "box", ["add", "-h"]]) end end end diff --git a/test/unit/vagrant/plugin/v1/communicator_test.rb b/test/unit/vagrant/plugin/v1/communicator_test.rb index a10e5a88d..904e76a34 100644 --- a/test/unit/vagrant/plugin/v1/communicator_test.rb +++ b/test/unit/vagrant/plugin/v1/communicator_test.rb @@ -4,6 +4,6 @@ describe Vagrant::Plugin::V1::Communicator do let(:machine) { Object.new } it "should not match by default" do - described_class.match?(machine).should_not be + expect(described_class.match?(machine)).not_to be end end diff --git a/test/unit/vagrant/plugin/v1/config_test.rb b/test/unit/vagrant/plugin/v1/config_test.rb index 425984794..5e4846775 100644 --- a/test/unit/vagrant/plugin/v1/config_test.rb +++ b/test/unit/vagrant/plugin/v1/config_test.rb @@ -12,8 +12,8 @@ describe Vagrant::Plugin::V1::Config do it "has an UNSET_VALUE constant" do value = described_class.const_get("UNSET_VALUE") - value.should be_kind_of Object - value.should eql(described_class.const_get("UNSET_VALUE")) + expect(value).to be_kind_of Object + expect(value).to eql(described_class.const_get("UNSET_VALUE")) end describe "merging" do @@ -26,8 +26,8 @@ describe Vagrant::Plugin::V1::Config do two.two = 5 result = one.merge(two) - result.one.should == 2 - result.two.should == 5 + expect(result.one).to eq(2) + expect(result.two).to eq(5) end it "doesn't merge values that start with a double underscore" do @@ -42,9 +42,9 @@ describe Vagrant::Plugin::V1::Config do # Merge and verify result = one.merge(two) - result.one.should == 1 - result.two.should == 2 - result.instance_variable_get(:@__bar).should be_nil + expect(result.one).to eq(1) + expect(result.two).to eq(2) + expect(result.instance_variable_get(:@__bar)).to be_nil end end end diff --git a/test/unit/vagrant/plugin/v1/manager_test.rb b/test/unit/vagrant/plugin/v1/manager_test.rb index f20a625eb..6b609cc22 100644 --- a/test/unit/vagrant/plugin/v1/manager_test.rb +++ b/test/unit/vagrant/plugin/v1/manager_test.rb @@ -23,9 +23,9 @@ describe Vagrant::Plugin::V1::Manager do instance.register(pA) instance.register(pB) - instance.communicators.length.should == 2 - instance.communicators[:foo].should == "bar" - instance.communicators[:bar].should == "baz" + expect(instance.communicators.length).to eq(2) + expect(instance.communicators[:foo]).to eq("bar") + expect(instance.communicators[:bar]).to eq("baz") end it "should enumerate registered configuration classes" do @@ -40,9 +40,9 @@ describe Vagrant::Plugin::V1::Manager do instance.register(pA) instance.register(pB) - instance.config.length.should == 2 - instance.config[:foo].should == "bar" - instance.config[:bar].should == "baz" + expect(instance.config.length).to eq(2) + expect(instance.config[:foo]).to eq("bar") + expect(instance.config[:bar]).to eq("baz") end it "should enumerate registered upgrade safe config classes" do @@ -57,8 +57,8 @@ describe Vagrant::Plugin::V1::Manager do instance.register(pA) instance.register(pB) - instance.config_upgrade_safe.length.should == 1 - instance.config_upgrade_safe[:foo].should == "bar" + expect(instance.config_upgrade_safe.length).to eq(1) + expect(instance.config_upgrade_safe[:foo]).to eq("bar") end it "should enumerate registered guest classes" do @@ -73,9 +73,9 @@ describe Vagrant::Plugin::V1::Manager do instance.register(pA) instance.register(pB) - instance.guests.length.should == 2 - instance.guests[:foo].should == "bar" - instance.guests[:bar].should == "baz" + expect(instance.guests.length).to eq(2) + expect(instance.guests[:foo]).to eq("bar") + expect(instance.guests[:bar]).to eq("baz") end it "should enumerate registered host classes" do @@ -90,9 +90,9 @@ describe Vagrant::Plugin::V1::Manager do instance.register(pA) instance.register(pB) - instance.hosts.length.should == 2 - instance.hosts[:foo].should == "bar" - instance.hosts[:bar].should == "baz" + expect(instance.hosts.length).to eq(2) + expect(instance.hosts[:foo]).to eq("bar") + expect(instance.hosts[:bar]).to eq("baz") end it "should enumerate registered provider classes" do @@ -107,8 +107,8 @@ describe Vagrant::Plugin::V1::Manager do instance.register(pA) instance.register(pB) - instance.providers.length.should == 2 - instance.providers[:foo].should == "bar" - instance.providers[:bar].should == "baz" + expect(instance.providers.length).to eq(2) + expect(instance.providers[:foo]).to eq("bar") + expect(instance.providers[:bar]).to eq("baz") end end diff --git a/test/unit/vagrant/plugin/v1/plugin_test.rb b/test/unit/vagrant/plugin/v1/plugin_test.rb index 2a3af0e6e..4c1bda782 100644 --- a/test/unit/vagrant/plugin/v1/plugin_test.rb +++ b/test/unit/vagrant/plugin/v1/plugin_test.rb @@ -12,7 +12,7 @@ describe Vagrant::Plugin::V1::Plugin do name "foo" end - plugin.name.should == "foo" + expect(plugin.name).to eq("foo") end it "should be able to set and get the description" do @@ -20,7 +20,7 @@ describe Vagrant::Plugin::V1::Plugin do description "bar" end - plugin.description.should == "bar" + expect(plugin.description).to eq("bar") end describe "action hooks" do @@ -30,8 +30,8 @@ describe Vagrant::Plugin::V1::Plugin do end hooks = plugin.action_hook("foo") - hooks.length.should == 1 - hooks[0].call.should == "bar" + expect(hooks.length).to eq(1) + expect(hooks[0].call).to eq("bar") end end @@ -41,7 +41,7 @@ describe Vagrant::Plugin::V1::Plugin do command("foo") { "bar" } end - plugin.command[:foo].should == "bar" + expect(plugin.command[:foo]).to eq("bar") end ["spaces bad", "sym^bols"].each do |bad| @@ -78,7 +78,7 @@ describe Vagrant::Plugin::V1::Plugin do communicator("foo") { "bar" } end - plugin.communicator[:foo].should == "bar" + expect(plugin.communicator[:foo]).to eq("bar") end it "should lazily register communicator classes" do @@ -106,7 +106,7 @@ describe Vagrant::Plugin::V1::Plugin do config("foo") { "bar" } end - plugin.config[:foo].should == "bar" + expect(plugin.config[:foo]).to eq("bar") end it "should lazily register configuration classes" do @@ -134,7 +134,7 @@ describe Vagrant::Plugin::V1::Plugin do guest("foo") { "bar" } end - plugin.guest[:foo].should == "bar" + expect(plugin.guest[:foo]).to eq("bar") end it "should lazily register guest classes" do @@ -162,7 +162,7 @@ describe Vagrant::Plugin::V1::Plugin do host("foo") { "bar" } end - plugin.host[:foo].should == "bar" + expect(plugin.host[:foo]).to eq("bar") end it "should lazily register host classes" do @@ -190,7 +190,7 @@ describe Vagrant::Plugin::V1::Plugin do provider("foo") { "bar" } end - plugin.provider[:foo].should == "bar" + expect(plugin.provider[:foo]).to eq("bar") end it "should lazily register provider classes" do @@ -218,7 +218,7 @@ describe Vagrant::Plugin::V1::Plugin do provisioner("foo") { "bar" } end - plugin.provisioner[:foo].should == "bar" + expect(plugin.provisioner[:foo]).to eq("bar") end it "should lazily register provisioner classes" do @@ -244,7 +244,7 @@ describe Vagrant::Plugin::V1::Plugin do let(:manager) { described_class.manager } it "should have no registered plugins" do - manager.registered.should be_empty + expect(manager.registered).to be_empty end it "should register a plugin when a name is set" do @@ -252,7 +252,7 @@ describe Vagrant::Plugin::V1::Plugin do name "foo" end - manager.registered.should == [plugin] + expect(manager.registered).to eq([plugin]) end it "should register a plugin only once" do @@ -261,7 +261,7 @@ describe Vagrant::Plugin::V1::Plugin do name "bar" end - manager.registered.should == [plugin] + expect(manager.registered).to eq([plugin]) end end end diff --git a/test/unit/vagrant/plugin/v1/provider_test.rb b/test/unit/vagrant/plugin/v1/provider_test.rb index 2950d9bbf..b30248e5c 100644 --- a/test/unit/vagrant/plugin/v1/provider_test.rb +++ b/test/unit/vagrant/plugin/v1/provider_test.rb @@ -5,14 +5,14 @@ describe Vagrant::Plugin::V1::Provider do let(:instance) { described_class.new(machine) } it "should return nil by default for actions" do - instance.action(:whatever).should be_nil + expect(instance.action(:whatever)).to be_nil end it "should return nil by default for ssh info" do - instance.ssh_info.should be_nil + expect(instance.ssh_info).to be_nil end it "should return nil by default for state" do - instance.state.should be_nil + expect(instance.state).to be_nil end end diff --git a/test/unit/vagrant/plugin/v2/command_test.rb b/test/unit/vagrant/plugin/v2/command_test.rb index a5b9da1ad..58a28a007 100644 --- a/test/unit/vagrant/plugin/v2/command_test.rb +++ b/test/unit/vagrant/plugin/v2/command_test.rb @@ -21,20 +21,20 @@ describe Vagrant::Plugin::V2::Command do result = klass.new(["-f", "foo"], nil).parse_options(opts) # Check the results - options[:f].should be - result.should == ["foo"] + expect(options[:f]).to be + expect(result).to eq(["foo"]) end it "creates an option parser if none is given" do result = klass.new(["foo"], nil).parse_options(nil) - result.should == ["foo"] + expect(result).to eq(["foo"]) end ["-h", "--help"].each do |help_string| it "returns nil and prints the help if '#{help_string}' is given" do instance = klass.new([help_string], nil) - instance.should_receive(:safe_puts) - instance.parse_options(OptionParser.new).should be_nil + expect(instance).to receive(:safe_puts) + expect(instance.parse_options(OptionParser.new)).to be_nil end end @@ -82,20 +82,20 @@ describe Vagrant::Plugin::V2::Command do bar_vm.stub(ui: Vagrant::UI::Silent.new) environment.stub(:machine_names => [:foo, :bar]) - environment.stub(:machine).with(:foo, default_provider).and_return(foo_vm) - environment.stub(:machine).with(:bar, default_provider).and_return(bar_vm) + allow(environment).to receive(:machine).with(:foo, default_provider).and_return(foo_vm) + allow(environment).to receive(:machine).with(:bar, default_provider).and_return(bar_vm) vms = [] instance.with_target_vms do |vm| vms << vm end - vms.should == [foo_vm, bar_vm] + expect(vms).to eq([foo_vm, bar_vm]) end it "raises an exception if the named VM doesn't exist" do environment.stub(:machine_names => [:default]) - environment.stub(:machine).with(:foo, anything).and_return(nil) + allow(environment).to receive(:machine).with(:foo, anything).and_return(nil) expect { instance.with_target_vms("foo") }. to raise_error(Vagrant::Errors::VMNotFoundError) @@ -106,11 +106,11 @@ describe Vagrant::Plugin::V2::Command do foo_vm.stub(:name => "foo", :provider => :foobarbaz) foo_vm.stub(ui: Vagrant::UI::Silent.new) - environment.stub(:machine).with(:foo, default_provider).and_return(foo_vm) + allow(environment).to receive(:machine).with(:foo, default_provider).and_return(foo_vm) vms = [] instance.with_target_vms("foo") { |vm| vms << vm } - vms.should == [foo_vm] + expect(vms).to eq([foo_vm]) end it "yields the given VM with proper provider if given" do @@ -119,11 +119,11 @@ describe Vagrant::Plugin::V2::Command do foo_vm.stub(:name => "foo", :provider => provider) foo_vm.stub(ui: Vagrant::UI::Silent.new) - environment.stub(:machine).with(:foo, provider).and_return(foo_vm) + allow(environment).to receive(:machine).with(:foo, provider).and_return(foo_vm) vms = [] instance.with_target_vms("foo", :provider => provider) { |vm| vms << vm } - vms.should == [foo_vm] + expect(vms).to eq([foo_vm]) end it "should raise an exception if an active machine exists with a different provider" do @@ -140,13 +140,13 @@ describe Vagrant::Plugin::V2::Command do vmware_vm = double("vmware_vm") environment.stub(:active_machines => [[name, provider]]) - environment.stub(:machine).with(name, provider).and_return(vmware_vm) + allow(environment).to receive(:machine).with(name, provider).and_return(vmware_vm) vmware_vm.stub(:name => name, :provider => provider) vmware_vm.stub(ui: Vagrant::UI::Silent.new) vms = [] instance.with_target_vms(name.to_s) { |vm| vms << vm } - vms.should == [vmware_vm] + expect(vms).to eq([vmware_vm]) end it "should use the explicit provider if it maches the active machine" do @@ -155,25 +155,25 @@ describe Vagrant::Plugin::V2::Command do vmware_vm = double("vmware_vm") environment.stub(:active_machines => [[name, provider]]) - environment.stub(:machine).with(name, provider).and_return(vmware_vm) + allow(environment).to receive(:machine).with(name, provider).and_return(vmware_vm) vmware_vm.stub(:name => name, :provider => provider, ui: Vagrant::UI::Silent.new) vms = [] instance.with_target_vms(name.to_s, :provider => provider) { |vm| vms << vm } - vms.should == [vmware_vm] + expect(vms).to eq([vmware_vm]) end it "should use the default provider if none is given and none are active" do name = :foo machine = double("machine") - environment.stub(:machine).with(name, default_provider).and_return(machine) + allow(environment).to receive(:machine).with(name, default_provider).and_return(machine) machine.stub(:name => name, :provider => default_provider) machine.stub(ui: Vagrant::UI::Silent.new) results = [] instance.with_target_vms(name.to_s) { |m| results << m } - results.should == [machine] + expect(results).to eq([machine]) end it "should use the primary machine with the active provider" do @@ -182,7 +182,7 @@ describe Vagrant::Plugin::V2::Command do vmware_vm = double("vmware_vm") environment.stub(:active_machines => [[name, provider]]) - environment.stub(:machine).with(name, provider).and_return(vmware_vm) + allow(environment).to receive(:machine).with(name, provider).and_return(vmware_vm) environment.stub(:machine_names => []) environment.stub(:primary_machine_name => name) vmware_vm.stub(:name => name, :provider => provider) @@ -190,7 +190,7 @@ describe Vagrant::Plugin::V2::Command do vms = [] instance.with_target_vms(nil, :single_target => true) { |vm| vms << vm } - vms.should == [vmware_vm] + expect(vms).to eq([vmware_vm]) end it "should use the primary machine with the default provider" do @@ -198,7 +198,7 @@ describe Vagrant::Plugin::V2::Command do machine = double("machine") environment.stub(:active_machines => []) - environment.stub(:machine).with(name, default_provider).and_return(machine) + allow(environment).to receive(:machine).with(name, default_provider).and_return(machine) environment.stub(:machine_names => []) environment.stub(:primary_machine_name => name) machine.stub(:name => name, :provider => default_provider) @@ -206,7 +206,7 @@ describe Vagrant::Plugin::V2::Command do vms = [] instance.with_target_vms(nil, :single_target => true) { |vm| vms << machine } - vms.should == [machine] + expect(vms).to eq([machine]) end end @@ -220,27 +220,27 @@ describe Vagrant::Plugin::V2::Command do it "should work when given all 3 parts" do result = instance.split_main_and_subcommand(["-v", "status", "-h", "-v"]) - result.should == [["-v"], "status", ["-h", "-v"]] + expect(result).to eq([["-v"], "status", ["-h", "-v"]]) end it "should work when given only a subcommand and args" do result = instance.split_main_and_subcommand(["status", "-h"]) - result.should == [[], "status", ["-h"]] + expect(result).to eq([[], "status", ["-h"]]) end it "should work when given only main flags" do result = instance.split_main_and_subcommand(["-v", "-h"]) - result.should == [["-v", "-h"], nil, []] + expect(result).to eq([["-v", "-h"], nil, []]) end it "should work when given only a subcommand" do result = instance.split_main_and_subcommand(["status"]) - result.should == [[], "status", []] + expect(result).to eq([[], "status", []]) end it "works when there are other non-flag args after the subcommand" do result = instance.split_main_and_subcommand(["-v", "box", "add", "-h"]) - result.should == [["-v"], "box", ["add", "-h"]] + expect(result).to eq([["-v"], "box", ["add", "-h"]]) end end end diff --git a/test/unit/vagrant/plugin/v2/communicator_test.rb b/test/unit/vagrant/plugin/v2/communicator_test.rb index 7abf2abc1..2d916ad5e 100644 --- a/test/unit/vagrant/plugin/v2/communicator_test.rb +++ b/test/unit/vagrant/plugin/v2/communicator_test.rb @@ -4,6 +4,6 @@ describe Vagrant::Plugin::V2::Communicator do let(:machine) { Object.new } it "should not match by default" do - described_class.match?(machine).should_not be + expect(described_class.match?(machine)).not_to be end end diff --git a/test/unit/vagrant/plugin/v2/components_test.rb b/test/unit/vagrant/plugin/v2/components_test.rb index b8dd1837c..b0c0a8737 100644 --- a/test/unit/vagrant/plugin/v2/components_test.rb +++ b/test/unit/vagrant/plugin/v2/components_test.rb @@ -6,16 +6,16 @@ describe Vagrant::Plugin::V2::Components do subject { described_class.new } it "should have synced folders" do - subject.synced_folders.should be_kind_of(Vagrant::Registry) + expect(subject.synced_folders).to be_kind_of(Vagrant::Registry) end describe "configs" do it "should have configs" do - subject.configs.should be_kind_of(Hash) + expect(subject.configs).to be_kind_of(Hash) end it "should default the values to registries" do - subject.configs[:i_probably_dont_exist].should be_kind_of(Vagrant::Registry) + expect(subject.configs[:i_probably_dont_exist]).to be_kind_of(Vagrant::Registry) end end end diff --git a/test/unit/vagrant/plugin/v2/config_test.rb b/test/unit/vagrant/plugin/v2/config_test.rb index cf4a0ced6..68b0d7ae8 100644 --- a/test/unit/vagrant/plugin/v2/config_test.rb +++ b/test/unit/vagrant/plugin/v2/config_test.rb @@ -24,8 +24,8 @@ describe Vagrant::Plugin::V2::Config do two.two = 5 result = one.merge(two) - result.one.should == 2 - result.two.should == 5 + expect(result.one).to eq(2) + expect(result.two).to eq(5) end it "prefers any set value over an UNSET_VALUE" do @@ -38,8 +38,8 @@ describe Vagrant::Plugin::V2::Config do two.two = 5 result = one.merge(two) - result.one.should == 1 - result.two.should == 5 + expect(result.one).to eq(1) + expect(result.two).to eq(5) end it "doesn't merge values that start with a double underscore" do @@ -54,9 +54,9 @@ describe Vagrant::Plugin::V2::Config do # Merge and verify result = one.merge(two) - result.one.should == 1 - result.two.should == 2 - result.instance_variable_get(:@__bar).should be_nil + expect(result.one).to eq(1) + expect(result.two).to eq(2) + expect(result.instance_variable_get(:@__bar)).to be_nil end end diff --git a/test/unit/vagrant/plugin/v2/manager_test.rb b/test/unit/vagrant/plugin/v2/manager_test.rb index 4dca40cb1..9d9903e6e 100644 --- a/test/unit/vagrant/plugin/v2/manager_test.rb +++ b/test/unit/vagrant/plugin/v2/manager_test.rb @@ -25,9 +25,9 @@ describe Vagrant::Plugin::V2::Manager do instance.register(pB) result = instance.action_hooks(nil) - result.length.should == 2 - result[0].call.should == "bar" - result[1].call.should == "baz" + expect(result.length).to eq(2) + expect(result[0].call).to eq("bar") + expect(result[1].call).to eq("baz") end it "should contain specific hooks with globally registered hooks" do @@ -45,10 +45,10 @@ describe Vagrant::Plugin::V2::Manager do instance.register(pB) result = instance.action_hooks(:foo) - result.length.should == 3 - result[0].call.should == "bar" - result[1].call.should == "bar_foo" - result[2].call.should == "baz" + expect(result.length).to eq(3) + expect(result[0].call).to eq("bar") + expect(result[1].call).to eq("bar_foo") + expect(result[2].call).to eq("baz") end end @@ -64,9 +64,9 @@ describe Vagrant::Plugin::V2::Manager do instance.register(pA) instance.register(pB) - instance.communicators.to_hash.length.should == 2 - instance.communicators[:foo].should == "bar" - instance.communicators[:bar].should == "baz" + expect(instance.communicators.to_hash.length).to eq(2) + expect(instance.communicators[:foo]).to eq("bar") + expect(instance.communicators[:bar]).to eq("baz") end it "should enumerate registered configuration classes" do @@ -81,9 +81,9 @@ describe Vagrant::Plugin::V2::Manager do instance.register(pA) instance.register(pB) - instance.config.to_hash.length.should == 2 - instance.config[:foo].should == "bar" - instance.config[:bar].should == "baz" + expect(instance.config.to_hash.length).to eq(2) + expect(instance.config[:foo]).to eq("bar") + expect(instance.config[:bar]).to eq("baz") end it "should enumerate registered guest classes" do @@ -98,9 +98,9 @@ describe Vagrant::Plugin::V2::Manager do instance.register(pA) instance.register(pB) - instance.guests.to_hash.length.should == 2 - instance.guests[:foo].should == ["bar", nil] - instance.guests[:bar].should == ["baz", :foo] + expect(instance.guests.to_hash.length).to eq(2) + expect(instance.guests[:foo]).to eq(["bar", nil]) + expect(instance.guests[:bar]).to eq(["baz", :foo]) end it "should enumerate registered guest capabilities" do @@ -115,9 +115,9 @@ describe Vagrant::Plugin::V2::Manager do instance.register(pA) instance.register(pB) - instance.guest_capabilities.length.should == 2 - instance.guest_capabilities[:foo][:foo].should == "bar" - instance.guest_capabilities[:bar][:foo].should == "baz" + expect(instance.guest_capabilities.length).to eq(2) + expect(instance.guest_capabilities[:foo][:foo]).to eq("bar") + expect(instance.guest_capabilities[:bar][:foo]).to eq("baz") end it "should enumerate registered host classes" do @@ -132,9 +132,9 @@ describe Vagrant::Plugin::V2::Manager do instance.register(pA) instance.register(pB) - instance.hosts.to_hash.length.should == 2 - instance.hosts[:foo].should == ["bar", nil] - instance.hosts[:bar].should == ["baz", :foo] + expect(instance.hosts.to_hash.length).to eq(2) + expect(instance.hosts[:foo]).to eq(["bar", nil]) + expect(instance.hosts[:bar]).to eq(["baz", :foo]) end it "should enumerate registered host capabilities" do @@ -149,9 +149,9 @@ describe Vagrant::Plugin::V2::Manager do instance.register(pA) instance.register(pB) - instance.host_capabilities.length.should == 2 - instance.host_capabilities[:foo][:foo].should == "bar" - instance.host_capabilities[:bar][:foo].should == "baz" + expect(instance.host_capabilities.length).to eq(2) + expect(instance.host_capabilities[:foo][:foo]).to eq("bar") + expect(instance.host_capabilities[:bar][:foo]).to eq("baz") end it "should enumerate registered provider classes" do @@ -166,9 +166,9 @@ describe Vagrant::Plugin::V2::Manager do instance.register(pA) instance.register(pB) - instance.providers.to_hash.length.should == 2 - instance.providers[:foo].should == ["bar", {}] - instance.providers[:bar].should == ["baz", { foo: "bar" }] + expect(instance.providers.to_hash.length).to eq(2) + expect(instance.providers[:foo]).to eq(["bar", {}]) + expect(instance.providers[:bar]).to eq(["baz", { foo: "bar" }]) end it "provides the collection of registered provider configs" do @@ -184,9 +184,9 @@ describe Vagrant::Plugin::V2::Manager do instance.register(pA) instance.register(pB) - instance.provider_configs.to_hash.length.should == 2 - instance.provider_configs[:foo].should == "foo" - instance.provider_configs[:bar].should == "bar" + expect(instance.provider_configs.to_hash.length).to eq(2) + expect(instance.provider_configs[:foo]).to eq("foo") + expect(instance.provider_configs[:bar]).to eq("bar") end it "should enumerate all registered synced folder implementations" do @@ -201,8 +201,8 @@ describe Vagrant::Plugin::V2::Manager do instance.register(pA) instance.register(pB) - instance.synced_folders.to_hash.length.should == 2 - instance.synced_folders[:foo].should == ["bar", 10] - instance.synced_folders[:bar].should == ["baz", 50] + expect(instance.synced_folders.to_hash.length).to eq(2) + expect(instance.synced_folders[:foo]).to eq(["bar", 10]) + expect(instance.synced_folders[:bar]).to eq(["baz", 50]) end end diff --git a/test/unit/vagrant/plugin/v2/plugin_test.rb b/test/unit/vagrant/plugin/v2/plugin_test.rb index 3341bf87d..a8b3159e6 100644 --- a/test/unit/vagrant/plugin/v2/plugin_test.rb +++ b/test/unit/vagrant/plugin/v2/plugin_test.rb @@ -10,7 +10,7 @@ describe Vagrant::Plugin::V2::Plugin do name "foo" end - plugin.name.should == "foo" + expect(plugin.name).to eq("foo") end it "should be able to set and get the description" do @@ -18,7 +18,7 @@ describe Vagrant::Plugin::V2::Plugin do description "bar" end - plugin.description.should == "bar" + expect(plugin.description).to eq("bar") end describe "action hooks" do @@ -29,8 +29,8 @@ describe Vagrant::Plugin::V2::Plugin do hooks_registry = plugin.components.action_hooks hooks = hooks_registry[described_class.const_get("ALL_ACTIONS")] - hooks.length.should == 1 - hooks[0].call.should == "bar" + expect(hooks.length).to eq(1) + expect(hooks[0].call).to eq("bar") end it "should register for a specific action by default" do @@ -40,8 +40,8 @@ describe Vagrant::Plugin::V2::Plugin do hooks_registry = plugin.components.action_hooks hooks = hooks_registry[:bar] - hooks.length.should == 1 - hooks[0].call.should == "bar" + expect(hooks.length).to eq(1) + expect(hooks[0].call).to eq("bar") end end @@ -109,7 +109,7 @@ describe Vagrant::Plugin::V2::Plugin do communicator("foo") { "bar" } end - plugin.communicator[:foo].should == "bar" + expect(plugin.communicator[:foo]).to eq("bar") end it "should lazily register communicator classes" do @@ -137,7 +137,7 @@ describe Vagrant::Plugin::V2::Plugin do config("foo") { "bar" } end - plugin.components.configs[:top][:foo].should == "bar" + expect(plugin.components.configs[:top][:foo]).to eq("bar") end it "should lazily register configuration classes" do @@ -163,7 +163,7 @@ describe Vagrant::Plugin::V2::Plugin do config("foo", :provider) { "bar" } end - plugin.components.configs[:provider][:foo].should == "bar" + expect(plugin.components.configs[:provider][:foo]).to eq("bar") end end @@ -173,7 +173,7 @@ describe Vagrant::Plugin::V2::Plugin do guest("foo") { "bar" } end - plugin.components.guests[:foo].should == ["bar", nil] + expect(plugin.components.guests[:foo]).to eq(["bar", nil]) end it "should lazily register guest classes" do @@ -201,7 +201,7 @@ describe Vagrant::Plugin::V2::Plugin do guest_capability("foo", "bar") { "baz" } end - plugin.components.guest_capabilities[:foo][:bar].should == "baz" + expect(plugin.components.guest_capabilities[:foo][:bar]).to eq("baz") end end @@ -211,7 +211,7 @@ describe Vagrant::Plugin::V2::Plugin do host("foo") { "bar" } end - plugin.components.hosts[:foo].should == ["bar", nil] + expect(plugin.components.hosts[:foo]).to eq(["bar", nil]) end it "should lazily register host classes" do @@ -239,7 +239,7 @@ describe Vagrant::Plugin::V2::Plugin do host_capability("foo", "bar") { "baz" } end - plugin.components.host_capabilities[:foo][:bar].should == "baz" + expect(plugin.components.host_capabilities[:foo][:bar]).to eq("baz") end end @@ -249,7 +249,7 @@ describe Vagrant::Plugin::V2::Plugin do provider("foo") { "bar" } end - plugin.components.providers[:foo].should == ["bar", {}] + expect(plugin.components.providers[:foo]).to eq(["bar", {}]) end it "should register provider classes with options" do @@ -257,7 +257,7 @@ describe Vagrant::Plugin::V2::Plugin do provider("foo", foo: "yep") { "bar" } end - plugin.components.providers[:foo].should == ["bar", { foo: "yep" }] + expect(plugin.components.providers[:foo]).to eq(["bar", { foo: "yep" }]) end it "should lazily register provider classes" do @@ -285,7 +285,7 @@ describe Vagrant::Plugin::V2::Plugin do provider_capability("foo", "bar") { "baz" } end - plugin.components.provider_capabilities[:foo][:bar].should == "baz" + expect(plugin.components.provider_capabilities[:foo][:bar]).to eq("baz") end end @@ -295,7 +295,7 @@ describe Vagrant::Plugin::V2::Plugin do provisioner("foo") { "bar" } end - plugin.provisioner[:foo].should == "bar" + expect(plugin.provisioner[:foo]).to eq("bar") end it "should lazily register provisioner classes" do @@ -323,7 +323,7 @@ describe Vagrant::Plugin::V2::Plugin do synced_folder("foo") { "bar" } end - plugin.components.synced_folders[:foo].should == ["bar", 10] + expect(plugin.components.synced_folders[:foo]).to eq(["bar", 10]) end it "should be able to specify priorities" do @@ -331,7 +331,7 @@ describe Vagrant::Plugin::V2::Plugin do synced_folder("foo", 50) { "bar" } end - plugin.components.synced_folders[:foo].should == ["bar", 50] + expect(plugin.components.synced_folders[:foo]).to eq(["bar", 50]) end it "should lazily register implementations" do @@ -357,7 +357,7 @@ describe Vagrant::Plugin::V2::Plugin do let(:manager) { described_class.manager } it "should have no registered plugins" do - manager.registered.should be_empty + expect(manager.registered).to be_empty end it "should register a plugin when a name is set" do @@ -365,7 +365,7 @@ describe Vagrant::Plugin::V2::Plugin do name "foo" end - manager.registered.should == [plugin] + expect(manager.registered).to eq([plugin]) end it "should register a plugin only once" do @@ -374,7 +374,7 @@ describe Vagrant::Plugin::V2::Plugin do name "bar" end - manager.registered.should == [plugin] + expect(manager.registered).to eq([plugin]) end end end diff --git a/test/unit/vagrant/plugin/v2/provider_test.rb b/test/unit/vagrant/plugin/v2/provider_test.rb index 489a3ba94..77b7ab5d7 100644 --- a/test/unit/vagrant/plugin/v2/provider_test.rb +++ b/test/unit/vagrant/plugin/v2/provider_test.rb @@ -9,15 +9,15 @@ describe Vagrant::Plugin::V2::Provider do subject { instance } it "should return nil by default for actions" do - instance.action(:whatever).should be_nil + expect(instance.action(:whatever)).to be_nil end it "should return nil by default for ssh info" do - instance.ssh_info.should be_nil + expect(instance.ssh_info).to be_nil end it "should return nil by default for state" do - instance.state.should be_nil + expect(instance.state).to be_nil end context "capabilities" do diff --git a/test/unit/vagrant/registry_test.rb b/test/unit/vagrant/registry_test.rb index b6aa8c6eb..d12f46ffe 100644 --- a/test/unit/vagrant/registry_test.rb +++ b/test/unit/vagrant/registry_test.rb @@ -4,12 +4,12 @@ describe Vagrant::Registry do let(:instance) { described_class.new } it "should return nil for nonexistent items" do - instance.get("foo").should be_nil + expect(instance.get("foo")).to be_nil end it "should register a simple key/value" do instance.register("foo") { "value" } - instance.get("foo").should == "value" + expect(instance.get("foo")).to eq("value") end it "should register an item without calling the block yet" do @@ -31,21 +31,21 @@ describe Vagrant::Registry do object end - instance.get("foo").should eql(object) + expect(instance.get("foo")).to eql(object) end it "should be able to get the item with []" do object = Object.new instance.register("foo") { object } - instance["foo"].should eql(object) + expect(instance["foo"]).to eql(object) end it "should be able to get keys with #keys" do instance.register("foo") { "bar" } instance.register("baz") { raise "BOOM" } - instance.keys.sort.should == [ 'baz', 'foo' ] + expect(instance.keys.sort).to eq([ 'baz', 'foo' ]) end it "should cache the result of the item so they can be modified" do @@ -54,15 +54,15 @@ describe Vagrant::Registry do # Test that modifying the result modifies the actual cached # value. This verifies we're caching. - instance.get("foo").should == [] + expect(instance.get("foo")).to eq([]) instance.get("foo") << "value" - instance.get("foo").should == ["value"] + expect(instance.get("foo")).to eq(["value"]) end it "should be able to check if a key exists" do instance.register("foo") { "bar" } - instance.should have_key("foo") - instance.should_not have_key("bar") + expect(instance).to have_key("foo") + expect(instance).not_to have_key("bar") end it "should be enumerable" do @@ -76,8 +76,8 @@ describe Vagrant::Registry do values << value end - keys.sort.should == ["bar", "foo"] - values.sort.should == ["barvalue", "foovalue"] + expect(keys.sort).to eq(["bar", "foo"]) + expect(values.sort).to eq(["barvalue", "foovalue"]) end it "should be able to convert to a hash" do @@ -85,9 +85,9 @@ describe Vagrant::Registry do instance.register("bar") { "barvalue" } result = instance.to_hash - result.should be_a(Hash) - result["foo"].should == "foovalue" - result["bar"].should == "barvalue" + expect(result).to be_a(Hash) + expect(result["foo"]).to eq("foovalue") + expect(result["bar"]).to eq("barvalue") end describe "merging" do @@ -114,8 +114,8 @@ describe Vagrant::Registry do two["bar"] << 2 three = one.merge(two) - three["foo"].should == [] - three["bar"].should == [] + expect(three["foo"]).to eq([]) + expect(three["bar"]).to eq([]) end end @@ -128,8 +128,8 @@ describe Vagrant::Registry do two.register("bar") { "bar" } one.merge!(two) - one["foo"].should == "foo" - one["bar"].should == "bar" + expect(one["foo"]).to eq("foo") + expect(one["bar"]).to eq("bar") end end end diff --git a/test/unit/vagrant/ui_test.rb b/test/unit/vagrant/ui_test.rb index c7c75d158..074f6ee49 100644 --- a/test/unit/vagrant/ui_test.rb +++ b/test/unit/vagrant/ui_test.rb @@ -5,55 +5,55 @@ describe Vagrant::UI::Basic do it "outputs within the a new thread" do current = Thread.current.object_id - subject.should_receive(:safe_puts).with do |*args| + expect(subject).to receive(:safe_puts).with { |*args| expect(Thread.current.object_id).to_not eq(current) true - end + } subject.output("foo") end it "outputs using `puts` by default" do - subject.should_receive(:safe_puts).with do |message, **opts| + expect(subject).to receive(:safe_puts).with { |message, **opts| expect(opts[:printer]).to eq(:puts) true - end + } subject.output("foo") end it "outputs using `print` if new_line is false" do - subject.should_receive(:safe_puts).with do |message, **opts| + expect(subject).to receive(:safe_puts).with { |message, **opts| expect(opts[:printer]).to eq(:print) true - end + } subject.output("foo", new_line: false) end it "outputs using `print` if new_line is false" do - subject.should_receive(:safe_puts).with do |message, **opts| + expect(subject).to receive(:safe_puts).with { |message, **opts| expect(opts[:printer]).to eq(:print) true - end + } subject.output("foo", new_line: false) end it "outputs to stdout" do - subject.should_receive(:safe_puts).with do |message, **opts| + expect(subject).to receive(:safe_puts).with { |message, **opts| expect(opts[:io]).to be($stdout) true - end + } subject.output("foo") end it "outputs to stderr for errors" do - subject.should_receive(:safe_puts).with do |message, **opts| + expect(subject).to receive(:safe_puts).with { |message, **opts| expect(opts[:io]).to be($stderr) true - end + } subject.error("foo") end @@ -61,16 +61,16 @@ describe Vagrant::UI::Basic do context "#detail" do it "outputs details" do - subject.should_receive(:safe_puts).with do |message, **opts| + expect(subject).to receive(:safe_puts).with { |message, **opts| expect(message).to eq("foo") true - end + } subject.detail("foo") end it "doesn't output details if disabled" do - subject.should_receive(:safe_puts).never + expect(subject).to receive(:safe_puts).never subject.opts[:hide_detail] = true subject.detail("foo") @@ -83,15 +83,15 @@ describe Vagrant::UI::Colored do describe "#detail" do it "colors output nothing by default" do - subject.should_receive(:safe_puts).with("\033[0mfoo\033[0m", anything) + expect(subject).to receive(:safe_puts).with("\033[0mfoo\033[0m", anything) subject.detail("foo") end it "does not bold by default with a color" do - subject.should_receive(:safe_puts).with do |message, *args| + expect(subject).to receive(:safe_puts).with { |message, *args| expect(message).to start_with("\033[0;31m") expect(message).to end_with("\033[0m") - end + } subject.detail("foo", color: :red) end @@ -99,10 +99,10 @@ describe Vagrant::UI::Colored do describe "#error" do it "colors red" do - subject.should_receive(:safe_puts).with do |message, *args| + expect(subject).to receive(:safe_puts).with { |message, *args| expect(message).to start_with("\033[0;31m") expect(message).to end_with("\033[0m") - end + } subject.error("foo") end @@ -110,27 +110,27 @@ describe Vagrant::UI::Colored do describe "#output" do it "colors output nothing by default, no bold" do - subject.should_receive(:safe_puts).with("\033[0mfoo\033[0m", anything) + expect(subject).to receive(:safe_puts).with("\033[0mfoo\033[0m", anything) subject.output("foo") end it "doesn't use a color if default color" do - subject.should_receive(:safe_puts).with("\033[0mfoo\033[0m", anything) + expect(subject).to receive(:safe_puts).with("\033[0mfoo\033[0m", anything) subject.output("foo", color: :default) end it "bolds output without color if specified" do - subject.should_receive(:safe_puts).with("\033[1mfoo\033[0m", anything) + expect(subject).to receive(:safe_puts).with("\033[1mfoo\033[0m", anything) subject.output("foo", bold: true) end it "colors output to color specified in global opts" do subject.opts[:color] = :red - subject.should_receive(:safe_puts).with do |message, *args| + expect(subject).to receive(:safe_puts).with { |message, *args| expect(message).to start_with("\033[0;31m") expect(message).to end_with("\033[0m") - end + } subject.output("foo") end @@ -138,10 +138,10 @@ describe Vagrant::UI::Colored do it "colors output to specified color over global opts" do subject.opts[:color] = :red - subject.should_receive(:safe_puts).with do |message, *args| + expect(subject).to receive(:safe_puts).with { |message, *args| expect(message).to start_with("\033[0;32m") expect(message).to end_with("\033[0m") - end + } subject.output("foo", color: :green) end @@ -149,10 +149,10 @@ describe Vagrant::UI::Colored do it "bolds the output if specified" do subject.opts[:color] = :red - subject.should_receive(:safe_puts).with do |message, *args| + expect(subject).to receive(:safe_puts).with { |message, *args| expect(message).to start_with("\033[1;31m") expect(message).to end_with("\033[0m") - end + } subject.output("foo", bold: true) end @@ -160,10 +160,10 @@ describe Vagrant::UI::Colored do describe "#success" do it "colors green" do - subject.should_receive(:safe_puts).with do |message, *args| + expect(subject).to receive(:safe_puts).with { |message, *args| expect(message).to start_with("\033[0;32m") expect(message).to end_with("\033[0m") - end + } subject.success("foo") end @@ -171,10 +171,10 @@ describe Vagrant::UI::Colored do describe "#warn" do it "colors yellow" do - subject.should_receive(:safe_puts).with do |message, *args| + expect(subject).to receive(:safe_puts).with { |message, *args| expect(message).to start_with("\033[0;33m") expect(message).to end_with("\033[0m") - end + } subject.warn("foo") end @@ -191,7 +191,7 @@ describe Vagrant::UI::MachineReadable do describe "#machine" do it "is formatted properly" do - subject.should_receive(:safe_puts).with do |message| + expect(subject).to receive(:safe_puts).with { |message| parts = message.split(",") expect(parts.length).to eq(5) expect(parts[1]).to eq("") @@ -199,42 +199,42 @@ describe Vagrant::UI::MachineReadable do expect(parts[3]).to eq("data") expect(parts[4]).to eq("another") true - end + } subject.machine(:type, "data", "another") end it "includes a target if given" do - subject.should_receive(:safe_puts).with do |message| + expect(subject).to receive(:safe_puts).with { |message| parts = message.split(",") expect(parts.length).to eq(4) expect(parts[1]).to eq("boom") expect(parts[2]).to eq("type") expect(parts[3]).to eq("data") true - end + } subject.machine(:type, "data", target: "boom") end it "replaces commas" do - subject.should_receive(:safe_puts).with do |message| + expect(subject).to receive(:safe_puts).with { |message| parts = message.split(",") expect(parts.length).to eq(4) expect(parts[3]).to eq("foo%!(VAGRANT_COMMA)bar") true - end + } subject.machine(:type, "foo,bar") end it "replaces newlines" do - subject.should_receive(:safe_puts).with do |message| + expect(subject).to receive(:safe_puts).with { |message| parts = message.split(",") expect(parts.length).to eq(4) expect(parts[3]).to eq("foo\\nbar\\r") true - end + } subject.machine(:type, "foo\nbar\r") end @@ -242,12 +242,12 @@ describe Vagrant::UI::MachineReadable do # This is for a bug where JSON parses are frozen and an # exception was being raised. it "works properly with frozen string arguments" do - subject.should_receive(:safe_puts).with do |message| + expect(subject).to receive(:safe_puts).with { |message| parts = message.split(",") expect(parts.length).to eq(4) expect(parts[3]).to eq("foo\\nbar\\r") true - end + } subject.machine(:type, "foo\nbar\r".freeze) end @@ -269,36 +269,36 @@ describe Vagrant::UI::Prefixed do describe "#ask" do it "does not request bolding" do - ui.should_receive(:ask).with(" #{prefix}: foo", bold: false) + expect(ui).to receive(:ask).with(" #{prefix}: foo", bold: false) subject.ask("foo") end end describe "#detail" do it "prefixes with spaces and the message" do - ui.should_receive(:safe_puts).with(" #{prefix}: foo", anything) + expect(ui).to receive(:safe_puts).with(" #{prefix}: foo", anything) subject.detail("foo") end it "prefixes every line" do - ui.should_receive(:detail).with(" #{prefix}: foo\n #{prefix}: bar", bold: false) + expect(ui).to receive(:detail).with(" #{prefix}: foo\n #{prefix}: bar", bold: false) subject.detail("foo\nbar") end it "doesn't prefix if requested" do - ui.should_receive(:detail).with("foo", prefix: false, bold: false) + expect(ui).to receive(:detail).with("foo", prefix: false, bold: false) subject.detail("foo", prefix: false) end end describe "#machine" do it "sets the target option" do - ui.should_receive(:machine).with(:foo, target: prefix) + expect(ui).to receive(:machine).with(:foo, target: prefix) subject.machine(:foo) end it "preserves existing options" do - ui.should_receive(:machine).with(:foo, :bar, foo: :bar, target: prefix) + expect(ui).to receive(:machine).with(:foo, :bar, foo: :bar, target: prefix) subject.machine(:foo, :bar, foo: :bar) end end @@ -312,33 +312,33 @@ describe Vagrant::UI::Prefixed do describe "#output" do it "prefixes with an arrow and the message" do - ui.should_receive(:output).with("==> #{prefix}: foo", anything) + expect(ui).to receive(:output).with("==> #{prefix}: foo", anything) subject.output("foo") end it "prefixes with spaces if requested" do - ui.should_receive(:output).with(" #{prefix}: foo", anything) + expect(ui).to receive(:output).with(" #{prefix}: foo", anything) subject.output("foo", prefix_spaces: true) end it "prefixes every line" do - ui.should_receive(:output).with("==> #{prefix}: foo\n==> #{prefix}: bar", anything) + expect(ui).to receive(:output).with("==> #{prefix}: foo\n==> #{prefix}: bar", anything) subject.output("foo\nbar") end it "doesn't prefix if requestsed" do - ui.should_receive(:output).with("foo", prefix: false, bold: true) + expect(ui).to receive(:output).with("foo", prefix: false, bold: true) subject.output("foo", prefix: false) end it "requests bolding" do - ui.should_receive(:output).with("==> #{prefix}: foo", bold: true) + expect(ui).to receive(:output).with("==> #{prefix}: foo", bold: true) subject.output("foo") end it "does not request bolding if class-level disabled" do ui.opts[:bold] = false - ui.should_receive(:output).with("==> #{prefix}: foo", {}) + expect(ui).to receive(:output).with("==> #{prefix}: foo", {}) subject.output("foo") end end diff --git a/test/unit/vagrant/util/ansi_escape_code_remover_test.rb b/test/unit/vagrant/util/ansi_escape_code_remover_test.rb index 8c6e3bcfd..5b08f92e4 100644 --- a/test/unit/vagrant/util/ansi_escape_code_remover_test.rb +++ b/test/unit/vagrant/util/ansi_escape_code_remover_test.rb @@ -10,7 +10,7 @@ describe Vagrant::Util::ANSIEscapeCodeRemover do end it "should remove ANSI escape codes" do - klass.remove_ansi_escape_codes("\e[Hyo").should == "yo" + expect(klass.remove_ansi_escape_codes("\e[Hyo")).to eq("yo") end end diff --git a/test/unit/vagrant/util/downloader_test.rb b/test/unit/vagrant/util/downloader_test.rb index 999eb4b97..ad0f95ab3 100644 --- a/test/unit/vagrant/util/downloader_test.rb +++ b/test/unit/vagrant/util/downloader_test.rb @@ -17,7 +17,7 @@ describe Vagrant::Util::Downloader do subject { described_class.new(source, destination) } before :each do - Vagrant::Util::Subprocess.stub(:execute).and_return(subprocess_result) + allow(Vagrant::Util::Subprocess).to receive(:execute).and_return(subprocess_result) end describe "#download!" do @@ -31,11 +31,11 @@ describe Vagrant::Util::Downloader do let(:exit_code) { 0 } it "downloads the file and returns true" do - Vagrant::Util::Subprocess.should_receive(:execute). + expect(Vagrant::Util::Subprocess).to receive(:execute). with("curl", *curl_options). and_return(subprocess_result) - subject.download!.should be + expect(subject.download!).to be end end @@ -43,7 +43,7 @@ describe Vagrant::Util::Downloader do let(:exit_code) { 1 } it "raises an exception" do - Vagrant::Util::Subprocess.should_receive(:execute). + expect(Vagrant::Util::Subprocess).to receive(:execute). with("curl", *curl_options). and_return(subprocess_result) @@ -65,7 +65,7 @@ describe Vagrant::Util::Downloader do curl_options.insert(i, "foo:bar") curl_options.insert(i, "-u") - Vagrant::Util::Subprocess.should_receive(:execute). + expect(Vagrant::Util::Subprocess).to receive(:execute). with("curl", *curl_options). and_return(subprocess_result) @@ -85,7 +85,7 @@ describe Vagrant::Util::Downloader do options = curl_options.dup options.unshift("-I") - Vagrant::Util::Subprocess.should_receive(:execute). + expect(Vagrant::Util::Subprocess).to receive(:execute). with("curl", *options).and_return(subprocess_result) expect(subject.head).to eq("foo") diff --git a/test/unit/vagrant/util/file_checksum_test.rb b/test/unit/vagrant/util/file_checksum_test.rb index fa20d800b..6812d02a9 100644 --- a/test/unit/vagrant/util/file_checksum_test.rb +++ b/test/unit/vagrant/util/file_checksum_test.rb @@ -15,9 +15,9 @@ describe FileChecksum do # Check multiple digests instance = described_class.new(file, Digest::MD5) - instance.checksum.should == "9ac96c64417b5976a58839eceaa77956" + expect(instance.checksum).to eq("9ac96c64417b5976a58839eceaa77956") instance = described_class.new(file, Digest::SHA1) - instance.checksum.should == "264b207c7913e461c43d0f63d2512f4017af4755" + expect(instance.checksum).to eq("264b207c7913e461c43d0f63d2512f4017af4755") end end diff --git a/test/unit/vagrant/util/hash_with_indifferent_access_test.rb b/test/unit/vagrant/util/hash_with_indifferent_access_test.rb index 82356dc00..397773eed 100644 --- a/test/unit/vagrant/util/hash_with_indifferent_access_test.rb +++ b/test/unit/vagrant/util/hash_with_indifferent_access_test.rb @@ -6,25 +6,25 @@ describe Vagrant::Util::HashWithIndifferentAccess do let(:instance) { described_class.new } it "is a Hash" do - instance.should be_kind_of(Hash) + expect(instance).to be_kind_of(Hash) end it "allows indifferent access when setting with a string" do instance["foo"] = "bar" - instance[:foo].should == "bar" + expect(instance[:foo]).to eq("bar") end it "allows indifferent access when setting with a symbol" do instance[:foo] = "bar" - instance["foo"].should == "bar" + expect(instance["foo"]).to eq("bar") end it "allows indifferent key lookup" do instance["foo"] = "bar" - instance.key?(:foo).should be - instance.has_key?(:foo).should be - instance.include?(:foo).should be - instance.member?(:foo).should be + expect(instance.key?(:foo)).to be + expect(instance.has_key?(:foo)).to be + expect(instance.include?(:foo)).to be + expect(instance.member?(:foo)).to be end it "allows for defaults to be passed in via an initializer block" do @@ -32,7 +32,7 @@ describe Vagrant::Util::HashWithIndifferentAccess do h[k] = "foo" end - instance[:foo].should == "foo" - instance["bar"].should == "foo" + expect(instance[:foo]).to eq("foo") + expect(instance["bar"]).to eq("foo") end end diff --git a/test/unit/vagrant/util/is_port_open_test.rb b/test/unit/vagrant/util/is_port_open_test.rb index 113294b60..71ee1db3b 100644 --- a/test/unit/vagrant/util/is_port_open_test.rb +++ b/test/unit/vagrant/util/is_port_open_test.rb @@ -36,7 +36,7 @@ describe Vagrant::Util::IsPortOpen do end # Verify that we report the port is open - klass.is_port_open?("localhost", open_port).should be + expect(klass.is_port_open?("localhost", open_port)).to be # Kill the thread thr[:die] = true @@ -47,7 +47,7 @@ describe Vagrant::Util::IsPortOpen do # This CAN fail, since port 52811 might actually be in use, but I'm # not sure what to do except choose some random port and hope for the # best, really. - klass.is_port_open?("localhost", closed_port).should_not be + expect(klass.is_port_open?("localhost", closed_port)).not_to be end end diff --git a/test/unit/vagrant/util/line_endings_helper_test.rb b/test/unit/vagrant/util/line_endings_helper_test.rb index 29454a323..c1b5bdf27 100644 --- a/test/unit/vagrant/util/line_endings_helper_test.rb +++ b/test/unit/vagrant/util/line_endings_helper_test.rb @@ -10,7 +10,7 @@ describe Vagrant::Util::LineEndingHelpers do end it "should convert DOS to unix-style line endings" do - klass.dos_to_unix("foo\r\nbar\r\n").should == "foo\nbar\n" + expect(klass.dos_to_unix("foo\r\nbar\r\n")).to eq("foo\nbar\n") end end diff --git a/test/unit/vagrant/util/network_ip_test.rb b/test/unit/vagrant/util/network_ip_test.rb index 0100f6f78..a4ff8944c 100644 --- a/test/unit/vagrant/util/network_ip_test.rb +++ b/test/unit/vagrant/util/network_ip_test.rb @@ -11,7 +11,7 @@ describe Vagrant::Util::NetworkIP do describe "network address" do it "calculates it properly" do - klass.network_address("192.168.2.234", "255.255.255.0").should == "192.168.2.0" + expect(klass.network_address("192.168.2.234", "255.255.255.0")).to eq("192.168.2.0") end end end diff --git a/test/unit/vagrant/util/retryable_test.rb b/test/unit/vagrant/util/retryable_test.rb index d312a429b..ba7a86460 100644 --- a/test/unit/vagrant/util/retryable_test.rb +++ b/test/unit/vagrant/util/retryable_test.rb @@ -22,7 +22,7 @@ describe Vagrant::Util::Retryable do to raise_error(RuntimeError) # It should've tried once - tries.should == 1 + expect(tries).to eq(1) end it "retries the set number of times" do @@ -38,7 +38,7 @@ describe Vagrant::Util::Retryable do to raise_error(RuntimeError) # It should've tried all specified times - tries.should == 5 + expect(tries).to eq(5) end it "only retries on the given exception" do @@ -54,7 +54,7 @@ describe Vagrant::Util::Retryable do to raise_error(StandardError) # It should've never tried since it was a different kind of error - tries.should == 1 + expect(tries).to eq(1) end it "can retry on multiple types of errors" do @@ -75,7 +75,7 @@ describe Vagrant::Util::Retryable do to raise_error(RuntimeError) # It should've never tried since it was a different kind of error - tries.should == 3 + expect(tries).to eq(3) end it "doesn't sleep between tries by default" do @@ -84,7 +84,7 @@ describe Vagrant::Util::Retryable do end # Sleep should never be called - klass.should_not_receive(:sleep) + expect(klass).not_to receive(:sleep) # Run it. expect { klass.retryable(:tries => 5, &block) }. @@ -97,7 +97,7 @@ describe Vagrant::Util::Retryable do end # Sleep should be called between each retry - klass.should_receive(:sleep).with(10).exactly(4).times + expect(klass).to receive(:sleep).with(10).exactly(4).times # Run it. expect { klass.retryable(:tries => 5, :sleep => 10, &block) }. diff --git a/test/unit/vagrant/util/safe_chdir_test.rb b/test/unit/vagrant/util/safe_chdir_test.rb index ae022a420..d1025a905 100644 --- a/test/unit/vagrant/util/safe_chdir_test.rb +++ b/test/unit/vagrant/util/safe_chdir_test.rb @@ -18,7 +18,7 @@ describe Vagrant::Util::SafeChdir do result = Dir.pwd end - result.should == expected + expect(result).to eq(expected) end it "should allow recursive chdir" do @@ -38,6 +38,6 @@ describe Vagrant::Util::SafeChdir do end end.to_not raise_error - result.should == expected + expect(result).to eq(expected) end end diff --git a/test/unit/vagrant/util/scoped_hash_override_test.rb b/test/unit/vagrant/util/scoped_hash_override_test.rb index bdf277503..246e187e3 100644 --- a/test/unit/vagrant/util/scoped_hash_override_test.rb +++ b/test/unit/vagrant/util/scoped_hash_override_test.rb @@ -15,7 +15,7 @@ describe Vagrant::Util::ScopedHashOverride do :another_value => "foo" } - klass.scoped_hash_override(original, "foo").should == original + expect(klass.scoped_hash_override(original, "foo")).to eq(original) end it "should override if the scope matches" do @@ -28,7 +28,7 @@ describe Vagrant::Util::ScopedHashOverride do :key => "replaced" } - klass.scoped_hash_override(original, "scope").should == expected + expect(klass.scoped_hash_override(original, "scope")).to eq(expected) end it "should ignore non-matching scopes" do @@ -43,6 +43,6 @@ describe Vagrant::Util::ScopedHashOverride do :another__key => "value" } - klass.scoped_hash_override(original, "scope").should == expected + expect(klass.scoped_hash_override(original, "scope")).to eq(expected) end end diff --git a/test/unit/vagrant/util/ssh_test.rb b/test/unit/vagrant/util/ssh_test.rb index 76da0ea6d..b2f2f853a 100644 --- a/test/unit/vagrant/util/ssh_test.rb +++ b/test/unit/vagrant/util/ssh_test.rb @@ -10,21 +10,21 @@ describe Vagrant::Util::SSH do let(:key_path) { temporary_file } it "should do nothing on Windows" do - Vagrant::Util::Platform.stub(:windows?).and_return(true) + allow(Vagrant::Util::Platform).to receive(:windows?).and_return(true) key_path.chmod(0700) # Get the mode now and verify that it is untouched afterwards mode = key_path.stat.mode described_class.check_key_permissions(key_path) - key_path.stat.mode.should == mode + expect(key_path.stat.mode).to eq(mode) end it "should fix the permissions", :skip_windows do key_path.chmod(0644) described_class.check_key_permissions(key_path) - key_path.stat.mode.should == 0100600 + expect(key_path.stat.mode).to eq(0100600) end end end diff --git a/test/unit/vagrant/util/string_block_editor_test.rb b/test/unit/vagrant/util/string_block_editor_test.rb index f7b1f9221..b31368b9c 100644 --- a/test/unit/vagrant/util/string_block_editor_test.rb +++ b/test/unit/vagrant/util/string_block_editor_test.rb @@ -15,7 +15,7 @@ content # VAGRANT-END: bar DATA - described_class.new(data).keys.should == ["foo", "bar"] + expect(described_class.new(data).keys).to eq(["foo", "bar"]) end end @@ -25,7 +25,7 @@ DATA instance = described_class.new(data) instance.delete("key") - instance.value.should == data + expect(instance.value).to eq(data) end it "should delete the matching blocks if they exist" do @@ -51,7 +51,7 @@ DATA instance = described_class.new(data) instance.delete("foo") - instance.value.should == new_data + expect(instance.value).to eq(new_data) end end @@ -70,16 +70,16 @@ DATA subject { described_class.new(data) } it "should get the value" do - subject.get("bar").should == "content" + expect(subject.get("bar")).to eq("content") end it "should get nil for nonexistent values" do - subject.get("baz").should be_nil + expect(subject.get("baz")).to be_nil end it "should get complicated keys" do result = subject.get("/Users/studio/Projects (studio)/tubes/.vagrant/machines/web/vmware_fusion/vm.vmwarevm") - result.should == "complex" + expect(result).to eq("complex") end end @@ -100,7 +100,7 @@ DATA instance = described_class.new(data) instance.insert("foo", "value") - instance.value.should == new_data + expect(instance.value).to eq(new_data) end end end diff --git a/test/unit/vagrant/util/which_test.rb b/test/unit/vagrant/util/which_test.rb index 759f8f8a6..7a7d17b87 100644 --- a/test/unit/vagrant/util/which_test.rb +++ b/test/unit/vagrant/util/which_test.rb @@ -23,21 +23,21 @@ describe Vagrant::Util::Which do it "should return a path for an executable file" do tester '.bat', '.bat', 0755 do |name| - described_class.which(name).should_not be_nil + expect(described_class.which(name)).not_to be_nil end end if Vagrant::Util::Platform.windows? it "should return a path for a Windows executable file" do tester '.bat', '', 0755 do |name| - described_class.which(name).should_not be_nil + expect(described_class.which(name)).not_to be_nil end end end it "should return nil for a non-executable file" do tester '.txt', '.txt', 0644 do |name| - described_class.which(name).should be_nil + expect(described_class.which(name)).to be_nil end end end diff --git a/test/unit/vagrant/vagrantfile_test.rb b/test/unit/vagrant/vagrantfile_test.rb index 7fbaa085e..c9b9b913f 100644 --- a/test/unit/vagrant/vagrantfile_test.rb +++ b/test/unit/vagrant/vagrantfile_test.rb @@ -79,12 +79,35 @@ describe Vagrant::Vagrantfile do VF end - its(:data_dir) { should eq(data_path) } - its(:env) { should equal(env) } - its(:name) { should eq(:default) } - its(:provider) { should be_kind_of(@provider_cls) } - its(:provider_name) { should eq(:foo) } - its(:vagrantfile) { should equal(vagrantfile) } + describe '#data_dir' do + subject { super().data_dir } + it { should eq(data_path) } + end + + describe '#env' do + subject { super().env } + it { should equal(env) } + end + + describe '#name' do + subject { super().name } + it { should eq(:default) } + end + + describe '#provider' do + subject { super().provider } + it { should be_kind_of(@provider_cls) } + end + + describe '#provider_name' do + subject { super().provider_name } + it { should eq(:foo) } + end + + describe '#vagrantfile' do + subject { super().vagrantfile } + it { should equal(vagrantfile) } + end it "has the proper box" do expect(subject.box.name).to eq("foo") diff --git a/test/unit/vagrant_test.rb b/test/unit/vagrant_test.rb index 80fb0046f..adc42175e 100644 --- a/test/unit/vagrant_test.rb +++ b/test/unit/vagrant_test.rb @@ -4,40 +4,40 @@ describe Vagrant do include_context "unit" it "has the path to the source root" do - described_class.source_root.should == Pathname.new(File.expand_path("../../../", __FILE__)) + expect(described_class.source_root).to eq(Pathname.new(File.expand_path("../../../", __FILE__))) end describe "plugin superclass" do describe "v1" do it "returns the proper class for version 1" do - described_class.plugin("1").should == Vagrant::Plugin::V1::Plugin + expect(described_class.plugin("1")).to eq(Vagrant::Plugin::V1::Plugin) end it "returns the proper components for version 1" do - described_class.plugin("1", :command).should == Vagrant::Plugin::V1::Command - described_class.plugin("1", :communicator).should == Vagrant::Plugin::V1::Communicator - described_class.plugin("1", :config).should == Vagrant::Plugin::V1::Config - described_class.plugin("1", :guest).should == Vagrant::Plugin::V1::Guest - described_class.plugin("1", :host).should == Vagrant::Plugin::V1::Host - described_class.plugin("1", :provider).should == Vagrant::Plugin::V1::Provider - described_class.plugin("1", :provisioner).should == Vagrant::Plugin::V1::Provisioner + expect(described_class.plugin("1", :command)).to eq(Vagrant::Plugin::V1::Command) + expect(described_class.plugin("1", :communicator)).to eq(Vagrant::Plugin::V1::Communicator) + expect(described_class.plugin("1", :config)).to eq(Vagrant::Plugin::V1::Config) + expect(described_class.plugin("1", :guest)).to eq(Vagrant::Plugin::V1::Guest) + expect(described_class.plugin("1", :host)).to eq(Vagrant::Plugin::V1::Host) + expect(described_class.plugin("1", :provider)).to eq(Vagrant::Plugin::V1::Provider) + expect(described_class.plugin("1", :provisioner)).to eq(Vagrant::Plugin::V1::Provisioner) end end describe "v2" do it "returns the proper class for version 2" do - described_class.plugin("2").should == Vagrant::Plugin::V2::Plugin + expect(described_class.plugin("2")).to eq(Vagrant::Plugin::V2::Plugin) end it "returns the proper components for version 2" do - described_class.plugin("2", :command).should == Vagrant::Plugin::V2::Command - described_class.plugin("2", :communicator).should == Vagrant::Plugin::V2::Communicator - described_class.plugin("2", :config).should == Vagrant::Plugin::V2::Config - described_class.plugin("2", :guest).should == Vagrant::Plugin::V2::Guest - described_class.plugin("2", :host).should == Vagrant::Plugin::V2::Host - described_class.plugin("2", :provider).should == Vagrant::Plugin::V2::Provider - described_class.plugin("2", :provisioner).should == Vagrant::Plugin::V2::Provisioner - described_class.plugin("2", :synced_folder).should == Vagrant::Plugin::V2::SyncedFolder + expect(described_class.plugin("2", :command)).to eq(Vagrant::Plugin::V2::Command) + expect(described_class.plugin("2", :communicator)).to eq(Vagrant::Plugin::V2::Communicator) + expect(described_class.plugin("2", :config)).to eq(Vagrant::Plugin::V2::Config) + expect(described_class.plugin("2", :guest)).to eq(Vagrant::Plugin::V2::Guest) + expect(described_class.plugin("2", :host)).to eq(Vagrant::Plugin::V2::Host) + expect(described_class.plugin("2", :provider)).to eq(Vagrant::Plugin::V2::Provider) + expect(described_class.plugin("2", :provisioner)).to eq(Vagrant::Plugin::V2::Provisioner) + expect(described_class.plugin("2", :synced_folder)).to eq(Vagrant::Plugin::V2::SyncedFolder) end end