diff --git a/Gemfile b/Gemfile index 15f245819..56ced29a7 100644 --- a/Gemfile +++ b/Gemfile @@ -2,8 +2,9 @@ source "https://rubygems.org" gemspec -if File.exist?(File.expand_path("../../vagrant-spec", __FILE__)) - gem 'vagrant-spec', path: "../vagrant-spec" -else - gem 'vagrant-spec', git: "https://github.com/mitchellh/vagrant-spec.git" -end +# Disable until vagrant-spec rspec is pulled up +# if File.exist?(File.expand_path("../../vagrant-spec", __FILE__)) +# gem 'vagrant-spec', path: "../vagrant-spec" +# else +# gem 'vagrant-spec', git: "https://github.com/mitchellh/vagrant-spec.git" +# end diff --git a/test/unit/base.rb b/test/unit/base.rb index 0ec219ae3..b049198ab 100644 --- a/test/unit/base.rb +++ b/test/unit/base.rb @@ -3,8 +3,8 @@ require "rubygems" # Gems require "checkpoint" -require "rspec/autorun" require "webmock/rspec" +require "rspec/its" # Require Vagrant itself so we can reference the proper # classes to test. @@ -33,8 +33,6 @@ VAGRANT_TEST_CWD = Dir.mktmpdir("vagrant-test-cwd") # Configure RSpec RSpec.configure do |c| - c.treat_symbols_as_metadata_keys_with_true_values = true - if Vagrant::Util::Platform.windows? c.filter_run_excluding :skip_windows else diff --git a/test/unit/plugins/commands/box/command/add_test.rb b/test/unit/plugins/commands/box/command/add_test.rb index e874ab487..77cf7d1ac 100644 --- a/test/unit/plugins/commands/box/command/add_test.rb +++ b/test/unit/plugins/commands/box/command/add_test.rb @@ -18,7 +18,7 @@ describe VagrantPlugins::CommandBox::Command::Add do let(:action_runner) { double("action_runner") } before do - iso_env.stub(action_runner: action_runner) + allow(iso_env).to receive(:action_runner).and_return(action_runner) end context "with no arguments" do @@ -32,7 +32,7 @@ describe VagrantPlugins::CommandBox::Command::Add do let(:argv) { ["foo"] } it "executes the runner with the proper actions" do - expect(action_runner).to receive(:run).with { |action, **opts| + expect(action_runner).to receive(:run).with(any_args) { |action, **opts| expect(opts[:box_name]).to be_nil expect(opts[:box_url]).to eq("foo") true @@ -46,7 +46,7 @@ describe VagrantPlugins::CommandBox::Command::Add do let(:argv) { ["foo", "bar"] } it "executes the runner with the proper actions" do - expect(action_runner).to receive(:run).with { |action, **opts| + expect(action_runner).to receive(:run).with(any_args) { |action, **opts| expect(opts[:box_name]).to eq("foo") expect(opts[:box_url]).to eq("bar") true diff --git a/test/unit/plugins/commands/box/command/remove_test.rb b/test/unit/plugins/commands/box/command/remove_test.rb index 923d920b5..0ba3d36e4 100644 --- a/test/unit/plugins/commands/box/command/remove_test.rb +++ b/test/unit/plugins/commands/box/command/remove_test.rb @@ -18,7 +18,7 @@ describe VagrantPlugins::CommandBox::Command::Remove do let(:action_runner) { double("action_runner") } before do - iso_env.stub(action_runner: action_runner) + allow(iso_env).to receive(:action_runner).and_return(action_runner) end context "with no arguments" do @@ -32,9 +32,9 @@ describe VagrantPlugins::CommandBox::Command::Remove do let(:argv) { ["foo"] } it "invokes the action runner" do - expect(action_runner).to receive(:run).with { |action, opts| + expect(action_runner).to receive(:run).with(any_args) { |action, opts| expect(opts[:box_name]).to eq("foo") - expect(opts[:force_confirm_box_remove]).to be_false + expect(opts[:force_confirm_box_remove]).to be(false) true } @@ -45,9 +45,9 @@ describe VagrantPlugins::CommandBox::Command::Remove do let(:argv) { super() + ["--force"] } it "invokes the action runner with force option" do - expect(action_runner).to receive(:run).with { |action, opts| + expect(action_runner).to receive(:run).with(any_args) { |action, opts| expect(opts[:box_name]).to eq("foo") - expect(opts[:force_confirm_box_remove]).to be_true + expect(opts[:force_confirm_box_remove]).to be(true) true } @@ -60,7 +60,7 @@ describe VagrantPlugins::CommandBox::Command::Remove do let(:argv) { ["foo", "bar"] } it "uses the 2nd arg as a provider" do - expect(action_runner).to receive(:run).with { |action, opts| + expect(action_runner).to receive(:run).with(any_args) { |action, opts| expect(opts[:box_name]).to eq("foo") expect(opts[:box_provider]).to eq("bar") true diff --git a/test/unit/plugins/commands/box/command/repackage_test.rb b/test/unit/plugins/commands/box/command/repackage_test.rb index 337226418..ce21dd941 100644 --- a/test/unit/plugins/commands/box/command/repackage_test.rb +++ b/test/unit/plugins/commands/box/command/repackage_test.rb @@ -18,7 +18,7 @@ describe VagrantPlugins::CommandBox::Command::Repackage do let(:action_runner) { double("action_runner") } before do - iso_env.stub(action_runner: action_runner) + allow(iso_env).to receive(:action_runner).and_return(action_runner) end context "with no arguments" do @@ -47,9 +47,7 @@ describe VagrantPlugins::CommandBox::Command::Repackage do end context "with three arguments" do - it "repackages the box with the given provider" do - pending - end + it "repackages the box with the given provider" end context "with more than three arguments" do diff --git a/test/unit/plugins/commands/box/command/update_test.rb b/test/unit/plugins/commands/box/command/update_test.rb index 35d84c791..d64d286f7 100644 --- a/test/unit/plugins/commands/box/command/update_test.rb +++ b/test/unit/plugins/commands/box/command/update_test.rb @@ -27,7 +27,7 @@ describe VagrantPlugins::CommandBox::Command::Update do subject { described_class.new(argv, iso_env) } before do - iso_env.stub(action_runner: action_runner) + allow(iso_env).to receive(:action_runner).and_return(action_runner) machine.config.vm.box = "foo" end @@ -64,7 +64,7 @@ describe VagrantPlugins::CommandBox::Command::Update do subject.execute - expect(called).to be_false + expect(called).to be(false) end it "does update if there is an update" do @@ -108,7 +108,7 @@ describe VagrantPlugins::CommandBox::Command::Update do subject.execute - expect(action_called).to be_true + expect(action_called).to be(true) end it "raises an error if there are multiple providers" do @@ -162,7 +162,7 @@ describe VagrantPlugins::CommandBox::Command::Update do subject.execute - expect(action_called).to be_true + expect(action_called).to be(true) end it "raises an error if that provider doesn't exist" do @@ -206,14 +206,14 @@ describe VagrantPlugins::CommandBox::Command::Update do expect(opts[:box_download_ca_cert]).to eq("foo") expect(opts[:box_download_ca_path]).to eq("bar") expect(opts[:box_client_cert]).to eq("baz") - expect(opts[:box_download_insecure]).to be_true + expect(opts[:box_download_insecure]).to be(true) end opts end subject.execute - expect(action_called).to be_true + expect(action_called).to be(true) end end @@ -238,7 +238,7 @@ describe VagrantPlugins::CommandBox::Command::Update do box_dir = test_iso_env.box3("foo", "1.0", :virtualbox) box = Vagrant::Box.new( "foo", :virtualbox, "1.0", box_dir, metadata_url: "foo") - box.stub(has_update?: nil) + allow(box).to receive(:has_update?).and_return(nil) box end @@ -249,7 +249,7 @@ describe VagrantPlugins::CommandBox::Command::Update do end it "doesn't update boxes if they're up-to-date" do - machine.stub(box: box) + allow(machine).to receive(:box).and_return(box) expect(box).to receive(:has_update?). with(machine.config.vm.box_version, {download_options: @@ -285,7 +285,7 @@ describe VagrantPlugins::CommandBox::Command::Update do RAW } - before { machine.stub(box: box) } + before { allow(machine).to receive(:box).and_return(box) } it "updates boxes" do expect(box).to receive(:has_update?). @@ -295,7 +295,7 @@ describe VagrantPlugins::CommandBox::Command::Update do insecure: false}}). and_return([md, md.version("1.1"), md.version("1.1").provider("virtualbox")]) - expect(action_runner).to receive(:run).with { |action, opts| + expect(action_runner).to receive(:run).with(any_args) { |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") @@ -322,11 +322,11 @@ describe VagrantPlugins::CommandBox::Command::Update do insecure: false}}). and_return([md, md.version("1.1"), md.version("1.1").provider("virtualbox")]) - expect(action_runner).to receive(:run).with { |action, opts| + expect(action_runner).to receive(:run).with(any_args) { |action, opts| expect(opts[:box_download_ca_cert]).to eq("oof") expect(opts[:box_download_ca_path]).to eq("rab") expect(opts[:box_client_cert]).to eq("zab") - expect(opts[:box_download_insecure]).to be_false + expect(opts[:box_download_insecure]).to be(false) true } @@ -345,11 +345,11 @@ describe VagrantPlugins::CommandBox::Command::Update do and_return([md, md.version("1.1"), md.version("1.1").provider("virtualbox")]) - expect(action_runner).to receive(:run).with { |action, opts| + expect(action_runner).to receive(:run).with(any_args) { |action, opts| expect(opts[:box_download_ca_cert]).to eq("foo") expect(opts[:box_download_ca_path]).to eq("bar") expect(opts[:box_client_cert]).to eq("baz") - expect(opts[:box_download_insecure]).to be_true + expect(opts[:box_download_insecure]).to be(true) true } diff --git a/test/unit/plugins/commands/init/command_test.rb b/test/unit/plugins/commands/init/command_test.rb index 4b20b0e9a..3bbafa8d6 100644 --- a/test/unit/plugins/commands/init/command_test.rb +++ b/test/unit/plugins/commands/init/command_test.rb @@ -16,7 +16,7 @@ describe VagrantPlugins::CommandInit::Command do let(:vagrantfile_path) { File.join(env.cwd, "Vagrantfile") } before do - Vagrant.plugin("2").manager.stub(commands: {}) + allow(Vagrant.plugin("2").manager).to receive(:commands).and_return({}) end after do diff --git a/test/unit/plugins/commands/list-commands/command_test.rb b/test/unit/plugins/commands/list-commands/command_test.rb index e8cc4ba56..8e42f17c9 100644 --- a/test/unit/plugins/commands/list-commands/command_test.rb +++ b/test/unit/plugins/commands/list-commands/command_test.rb @@ -28,7 +28,7 @@ describe VagrantPlugins::CommandListCommands::Command do commands[:bar] = [command_lambda("bar", 0), { primary: true }] commands[:baz] = [command_lambda("baz", 0), { primary: false }] - expect(iso_env.ui).to receive(:info).with { |message, opts| + expect(iso_env.ui).to receive(:info).with(any_args) { |message, opts| expect(message).to include("foo") expect(message).to include("bar") expect(message).to include("baz") 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 e038d6595..2e3ecc1c6 100644 --- a/test/unit/plugins/commands/plugin/action/install_gem_test.rb +++ b/test/unit/plugins/commands/plugin/action/install_gem_test.rb @@ -84,7 +84,7 @@ describe VagrantPlugins::CommandPlugin::Action::InstallGem do end it "should uninstall the plugin" do - expect(action_runner).to receive(:run).with { |action, newenv| + expect(action_runner).to receive(:run).with(any_args) { |action, newenv| expect(newenv[:plugin_name]).to eql("foo") } diff --git a/test/unit/plugins/commands/port/command_test.rb b/test/unit/plugins/commands/port/command_test.rb index 23abf5d7b..2bf2eeca6 100644 --- a/test/unit/plugins/commands/port/command_test.rb +++ b/test/unit/plugins/commands/port/command_test.rb @@ -53,7 +53,7 @@ describe VagrantPlugins::CommandPort::Command do it "ensures the vm is running" do allow(state).to receive(:id).and_return(:stopped) - expect(env.ui).to receive(:error).with { |message, _| + expect(env.ui).to receive(:error).with(any_args) { |message, _| expect(message).to include("does not support listing forwarded ports") } @@ -62,7 +62,7 @@ describe VagrantPlugins::CommandPort::Command do it "shows a friendly error when the capability is not supported" do allow(machine.provider).to receive(:capability?).and_return(false) - expect(env.ui).to receive(:error).with { |message, _| + expect(env.ui).to receive(:error).with(any_args) { |message, _| expect(message).to include("does not support listing forwarded ports") } @@ -74,7 +74,7 @@ describe VagrantPlugins::CommandPort::Command do allow(machine.provider).to receive(:capability).with(:forwarded_ports) .and_return([]) - expect(env.ui).to receive(:info).with { |message, _| + expect(env.ui).to receive(:info).with(any_args) { |message, _| expect(message).to include("there are no forwarded ports") } diff --git a/test/unit/plugins/commands/snapshot/command/list_test.rb b/test/unit/plugins/commands/snapshot/command/list_test.rb index a812aa40f..ea6412356 100644 --- a/test/unit/plugins/commands/snapshot/command/list_test.rb +++ b/test/unit/plugins/commands/snapshot/command/list_test.rb @@ -52,9 +52,8 @@ describe VagrantPlugins::CommandSnapshot::Command::List do it "prints a message if the vm does not exist" do machine.id = nil - expect(iso_env.ui).to receive(:info).with { |message, _| - expect(message).to include("VM not created") - } + expect(iso_env.ui).to receive(:info).with("==> default: VM not created. Moving on...", anything) + .and_return({}) expect(machine).to_not receive(:action) expect(subject.execute).to eq(0) end diff --git a/test/unit/plugins/commands/up/command_test.rb b/test/unit/plugins/commands/up/command_test.rb index 5a260764b..2d744eea1 100644 --- a/test/unit/plugins/commands/up/command_test.rb +++ b/test/unit/plugins/commands/up/command_test.rb @@ -47,7 +47,7 @@ describe VagrantPlugins::CommandUp::Command do end it "should attempt to use dummy provider" do - expect{ subject.execute }.to raise_error + expect{ subject.execute }.to raise_error(Vagrant::Errors::ProviderNotFound) end context "with --provider set" do diff --git a/test/unit/plugins/commands/validate/command_test.rb b/test/unit/plugins/commands/validate/command_test.rb index 79a5463d3..66941d72c 100644 --- a/test/unit/plugins/commands/validate/command_test.rb +++ b/test/unit/plugins/commands/validate/command_test.rb @@ -30,7 +30,7 @@ describe VagrantPlugins::CommandValidate::Command do end EOH - expect(env.ui).to receive(:info).with { |message, _| + expect(env.ui).to receive(:info).with(any_args) { |message, _| expect(message).to include("Vagrantfile validated successfully.") } diff --git a/test/unit/plugins/communicators/ssh/communicator_test.rb b/test/unit/plugins/communicators/ssh/communicator_test.rb index 0a2f67195..dc569201d 100644 --- a/test/unit/plugins/communicators/ssh/communicator_test.rb +++ b/test/unit/plugins/communicators/ssh/communicator_test.rb @@ -109,7 +109,7 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do describe ".ready?" do before(&connection_setup) it "returns true if shell test is successful" do - expect(communicator.ready?).to be_true + expect(communicator.ready?).to be(true) end context "with an invalid shell test" do @@ -268,7 +268,7 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do before(&connection_setup) context "with exit code as zero" do it "returns true" do - expect(communicator.test("ls")).to be_true + expect(communicator.test("ls")).to be(true) end end @@ -278,7 +278,7 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do end it "returns false" do - expect(communicator.test("/bin/false")).to be_false + expect(communicator.test("/bin/false")).to be(false) end end end @@ -585,14 +585,14 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do describe ".generate_environment_export" do it "should generate bourne shell compatible export" do - communicator.send(:generate_environment_export, "TEST", "value").should eq("export TEST=\"value\"\n") + expect(communicator.send(:generate_environment_export, "TEST", "value")).to eq("export TEST=\"value\"\n") end context "with custom template defined" do let(:export_command_template){ "setenv %ENV_KEY% %ENV_VALUE%" } it "should generate custom export based on template" do - communicator.send(:generate_environment_export, "TEST", "value").should eq("setenv TEST value\n") + expect(communicator.send(:generate_environment_export, "TEST", "value")).to eq("setenv TEST value\n") end end end diff --git a/test/unit/plugins/communicators/winrm/communicator_test.rb b/test/unit/plugins/communicators/winrm/communicator_test.rb index 719167590..ae5cbc7bb 100644 --- a/test/unit/plugins/communicators/winrm/communicator_test.rb +++ b/test/unit/plugins/communicators/winrm/communicator_test.rb @@ -60,12 +60,12 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do describe ".ready?" do it "returns true if hostname command executes without error" do expect(shell).to receive(:cmd).with("hostname").and_return({ exitcode: 0 }) - expect(subject.ready?).to be_true + expect(subject.ready?).to be(true) end it "returns false if hostname command fails with a transient error" do expect(shell).to receive(:cmd).with("hostname").and_raise(VagrantPlugins::CommunicatorWinRM::Errors::TransientError) - expect(subject.ready?).to be_false + expect(subject.ready?).to be(false) end it "raises an error if hostname command fails with an unknown error" do @@ -112,12 +112,12 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do describe ".test" do it "returns true when exit code is zero" do expect(shell).to receive(:powershell).with(kind_of(String)).and_return(good_output) - expect(subject.test("test -d c:/windows")).to be_true + expect(subject.test("test -d c:/windows")).to be(true) end it "returns false when exit code is non-zero" do expect(shell).to receive(:powershell).with(kind_of(String)).and_return(bad_output) - expect(subject.test("test -d /tmp/foobar")).to be_false + expect(subject.test("test -d /tmp/foobar")).to be(false) end it "returns false when stderr contains output" do @@ -125,11 +125,11 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do output.exitcode = 1 output << { stderr: 'this is an error' } expect(shell).to receive(:powershell).with(kind_of(String)).and_return(output) - expect(subject.test("[-x stuff] && foo")).to be_false + expect(subject.test("[-x stuff] && foo")).to be(false) end it "returns false when command is testing for linux OS" do - expect(subject.test("uname -s | grep Debian")).to be_false + expect(subject.test("uname -s | grep Debian")).to be(false) end end diff --git a/test/unit/plugins/communicators/winssh/communicator_test.rb b/test/unit/plugins/communicators/winssh/communicator_test.rb index 34812ac72..2110dd913 100644 --- a/test/unit/plugins/communicators/winssh/communicator_test.rb +++ b/test/unit/plugins/communicators/winssh/communicator_test.rb @@ -127,7 +127,7 @@ describe VagrantPlugins::CommunicatorWinSSH::Communicator do describe ".ready?" do before(&connection_setup) it "returns true if shell test is successful" do - expect(communicator.ready?).to be_true + expect(communicator.ready?).to be_truthy end context "with an invalid shell test" do @@ -209,7 +209,7 @@ describe VagrantPlugins::CommunicatorWinSSH::Communicator do before(&connection_setup) context "with exit code as zero" do it "returns true" do - expect(communicator.test("dir")).to be_true + expect(communicator.test("dir")).to be_truthy end end @@ -219,7 +219,7 @@ describe VagrantPlugins::CommunicatorWinSSH::Communicator do end it "returns false" do - expect(communicator.test("false.exe")).to be_false + expect(communicator.test("false.exe")).to be_falsey end end end @@ -512,14 +512,14 @@ describe VagrantPlugins::CommunicatorWinSSH::Communicator do describe ".generate_environment_export" do it "should generate bourne shell compatible export" do - communicator.send(:generate_environment_export, "TEST", "value").should eq("export TEST=\"value\"\n") + expect(communicator.send(:generate_environment_export, "TEST", "value")).to eq("export TEST=\"value\"\n") end context "with custom template defined" do let(:export_command_template){ "setenv %ENV_KEY% %ENV_VALUE%" } it "should generate custom export based on template" do - communicator.send(:generate_environment_export, "TEST", "value").should eq("setenv TEST value\n") + expect(communicator.send(:generate_environment_export, "TEST", "value")).to eq("setenv TEST value\n") end end end diff --git a/test/unit/plugins/guests/omnios/cap/mount_nfs_folder_test.rb b/test/unit/plugins/guests/omnios/cap/mount_nfs_folder_test.rb index ec5b2cf9f..48bc2a225 100644 --- a/test/unit/plugins/guests/omnios/cap/mount_nfs_folder_test.rb +++ b/test/unit/plugins/guests/omnios/cap/mount_nfs_folder_test.rb @@ -40,8 +40,6 @@ describe "VagrantPlugins::GuestOmniOS::Cap:RSync" do expect(comm.received_commands[0]).to match(/'1.2.3.4:#{hostpath}' '#{guestpath}'/) end - it "mounts with options" do - pending "not yet implemented" - end + it "mounts with options" end end diff --git a/test/unit/plugins/guests/windows/config_test.rb b/test/unit/plugins/guests/windows/config_test.rb index ee43fc8ac..dae493cf2 100644 --- a/test/unit/plugins/guests/windows/config_test.rb +++ b/test/unit/plugins/guests/windows/config_test.rb @@ -23,7 +23,7 @@ describe VagrantPlugins::GuestWindows::Config do it "should not default #{attribute} if overridden" do subject.send("#{attribute}=".to_sym, 10) subject.finalize! - subject.send(attribute).should == 10 + expect(subject.send(attribute)).to be(10) end it "should return error #{attribute} if nil" do diff --git a/test/unit/plugins/guests/windows/guest_network_test.rb b/test/unit/plugins/guests/windows/guest_network_test.rb index dd0f4f546..19efacaee 100644 --- a/test/unit/plugins/guests/windows/guest_network_test.rb +++ b/test/unit/plugins/guests/windows/guest_network_test.rb @@ -12,14 +12,14 @@ describe "VagrantPlugins::GuestWindows::GuestNetwork" do expect(communicator).to receive(:test).with( /.+Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=7 and DHCPEnabled=True"/). and_return(true) - expect(subject.is_dhcp_enabled(7)).to be_true + expect(subject.is_dhcp_enabled(7)).to be(true) end it "should return false for non-DHCP NICs" do expect(communicator).to receive(:test).with( /.+Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=8 and DHCPEnabled=True"/). and_return(false) - expect(subject.is_dhcp_enabled(8)).to be_false + expect(subject.is_dhcp_enabled(8)).to be(false) end end diff --git a/test/unit/plugins/hosts/linux/cap/nfs_test.rb b/test/unit/plugins/hosts/linux/cap/nfs_test.rb index 144e9c8fd..eed8b7221 100644 --- a/test/unit/plugins/hosts/linux/cap/nfs_test.rb +++ b/test/unit/plugins/hosts/linux/cap/nfs_test.rb @@ -147,10 +147,12 @@ EOH it "should retain existing file owner and group IDs" do pending("investigate using a simulated FS to test") + test_with_simulated_fs end it "should raise custom exception when chown fails" do pending("investigate using a simulated FS to test") + test_with_simulated_fs end end end diff --git a/test/unit/plugins/kernel_v2/config/push_test.rb b/test/unit/plugins/kernel_v2/config/push_test.rb index e1c67996f..367a46b2c 100644 --- a/test/unit/plugins/kernel_v2/config/push_test.rb +++ b/test/unit/plugins/kernel_v2/config/push_test.rb @@ -71,7 +71,7 @@ describe VagrantPlugins::Kernel_V2::PushConfig do describe "#__compiled_pushes" do it "raises an exception if not finalized" do subject.instance_variable_set(:@__finalized, false) - expect { subject.__compiled_pushes }.to raise_error + expect { subject.__compiled_pushes }.to raise_error(RuntimeError) end it "returns a copy of the compiled pushes" do diff --git a/test/unit/plugins/kernel_v2/config/vm_test.rb b/test/unit/plugins/kernel_v2/config/vm_test.rb index ef3734898..e629ab974 100644 --- a/test/unit/plugins/kernel_v2/config/vm_test.rb +++ b/test/unit/plugins/kernel_v2/config/vm_test.rb @@ -356,7 +356,7 @@ describe VagrantPlugins::Kernel_V2::VMConfig do config = subject.get_provider_config(:virtualbox) expect(config.name).to eq("foo") - expect(config.gui).to be_true + expect(config.gui).to be(true) end it "raises an exception if there is a problem loading" do @@ -543,7 +543,7 @@ describe VagrantPlugins::Kernel_V2::VMConfig do sf = subject.synced_folders expect(sf.length).to eq(1) expect(sf).to have_key("/vagrant") - expect(sf["/vagrant"][:disabled]).to be_true + expect(sf["/vagrant"][:disabled]).to be(true) end it "allows overriding previously set options" do @@ -553,7 +553,7 @@ describe VagrantPlugins::Kernel_V2::VMConfig do sf = subject.synced_folders expect(sf.length).to eq(1) expect(sf).to have_key("/vagrant") - expect(sf["/vagrant"][:disabled]).to be_false + expect(sf["/vagrant"][:disabled]).to be(false) expect(sf["/vagrant"][:foo]).to eq(:bar) end diff --git a/test/unit/plugins/providers/docker/config_test.rb b/test/unit/plugins/providers/docker/config_test.rb index 5dc59bcc4..62258aed2 100644 --- a/test/unit/plugins/providers/docker/config_test.rb +++ b/test/unit/plugins/providers/docker/config_test.rb @@ -46,11 +46,11 @@ describe VagrantPlugins::DockerProvider::Config do its(:expose) { should eq([]) } its(:cmd) { should eq([]) } its(:env) { should eq({}) } - its(:force_host_vm) { should be_false } + its(:force_host_vm) { should be(false) } its(:host_vm_build_dir_options) { should be_nil } its(:image) { should be_nil } its(:name) { should be_nil } - its(:privileged) { should be_false } + its(:privileged) { should be(false) } its(:stop_timeout) { should eq(1) } its(:vagrant_machine) { should be_nil } its(:vagrant_vagrantfile) { should be_nil } diff --git a/test/unit/plugins/providers/docker/driver_compose_test.rb b/test/unit/plugins/providers/docker/driver_compose_test.rb index fa1cada06..3c3b1fe90 100644 --- a/test/unit/plugins/providers/docker/driver_compose_test.rb +++ b/test/unit/plugins/providers/docker/driver_compose_test.rb @@ -47,7 +47,7 @@ describe VagrantPlugins::DockerProvider::Driver::Compose do allow(Tempfile).to receive(:new).with("vagrant-docker-compose").and_return(docker_yml) allow(docker_yml).to receive(:write) allow(docker_yml).to receive(:close) - subject.stub(:execute) do |*args| + allow(subject).to receive(:execute) do |*args| args.delete_if{|i| i.is_a?(Hash) } @cmd = args.join(' ') end @@ -115,19 +115,21 @@ describe VagrantPlugins::DockerProvider::Driver::Compose do end context 'when container exists' do - before { subject.stub(execute: "foo\n#{cid}\nbar") } - it { expect(result).to be_true } + before { allow(subject).to receive(:execute) + .and_return("foo\n#{cid}\nbar") } + it { expect(result).to be_truthy } end context 'when container does not exist' do - before { subject.stub(execute: "foo\n#{cid}extra\nbar") } - it { expect(result).to be_false } + before { allow(subject).to receive(:execute) + .and_return("foo\n#{cid}extra\nbar") } + it { expect(result).to be_falsey } end end describe '#pull' do it 'should pull images' do - subject.should_receive(:execute).with('docker', 'pull', 'foo') + expect(subject).to receive(:execute).with('docker', 'pull', 'foo') subject.pull('foo') end end @@ -142,43 +144,47 @@ describe VagrantPlugins::DockerProvider::Driver::Compose do end context 'when container exists' do - before { subject.stub(execute: "foo\n#{cid}\nbar") } - it { expect(result).to be_true } + before { allow(subject).to receive(:execute) + .and_return("foo\n#{cid}\nbar") } + it { expect(result).to be_truthy } end context 'when container does not exist' do - before { subject.stub(execute: "foo\n#{cid}extra\nbar") } - it { expect(result).to be_false } + before { allow(subject).to receive(:execute) + .and_return("foo\n#{cid}extra\nbar") } + it { expect(result).to be_falsey } end end describe '#privileged?' do it 'identifies privileged containers' do - subject.stub(inspect_container: {'HostConfig' => {"Privileged" => true}}) + allow(subject).to receive(:inspect_container) + .and_return({'HostConfig' => {"Privileged" => true}}) expect(subject).to be_privileged(cid) end it 'identifies unprivileged containers' do - subject.stub(inspect_container: {'HostConfig' => {"Privileged" => false}}) + allow(subject).to receive(:inspect_container) + .and_return({'HostConfig' => {"Privileged" => false}}) expect(subject).to_not be_privileged(cid) end end describe '#start' do context 'when container is running' do - before { subject.stub(running?: true) } + before { allow(subject).to receive(:running?).and_return(true) } it 'does not start the container' do - subject.should_not_receive(:execute).with('docker', 'start', cid) + expect(subject).not_to receive(:execute).with('docker', 'start', cid) subject.start(cid) end end context 'when container is not running' do - before { subject.stub(running?: false) } + before { allow(subject).to receive(:running?).and_return(false) } it 'starts the container' do - subject.should_receive(:execute).with('docker', 'start', cid) + expect(subject).to receive(:execute).with('docker', 'start', cid) subject.start(cid) end end @@ -186,24 +192,24 @@ describe VagrantPlugins::DockerProvider::Driver::Compose do describe '#stop' do context 'when container is running' do - before { subject.stub(running?: true) } + before { allow(subject).to receive(:running?).and_return(true) } it 'stops the container' do - subject.should_receive(:execute).with('docker', 'stop', '-t', '1', cid) + expect(subject).to receive(:execute).with('docker', 'stop', '-t', '1', cid) subject.stop(cid, 1) end it "stops the container with the set timeout" do - subject.should_receive(:execute).with('docker', 'stop', '-t', '5', cid) + expect(subject).to receive(:execute).with('docker', 'stop', '-t', '5', cid) subject.stop(cid, 5) end end context 'when container is not running' do - before { subject.stub(running?: false) } + before { allow(subject).to receive(:running?).and_return(false) } it 'does not stop container' do - subject.should_not_receive(:execute).with('docker', 'stop', '-t', '1', cid) + expect(subject).not_to receive(:execute).with('docker', 'stop', '-t', '1', cid) subject.stop(cid, 1) end end @@ -211,7 +217,7 @@ describe VagrantPlugins::DockerProvider::Driver::Compose do describe '#rm' do context 'when container has been created' do - before { subject.stub(created?: true) } + before { allow(subject).to receive(:created?).and_return(true) } it 'removes the container' do expect(subject).to receive(:execute).with("docker-compose", "-f", "docker-compose.yml", "-p", "cwd", "rm", "-f", "docker_1", {}) @@ -220,7 +226,7 @@ describe VagrantPlugins::DockerProvider::Driver::Compose do end context 'when container has not been created' do - before { subject.stub(created?: false) } + before { allow(subject).to receive(:created?).and_return(false) } it 'does not attempt to remove the container' do expect(subject).not_to receive(:execute).with("docker-compose", "-f", "docker-compose.yml", "-p", "cwd", "rm", "-f", "docker_1", {}) @@ -232,10 +238,10 @@ describe VagrantPlugins::DockerProvider::Driver::Compose do describe '#inspect_container' do let(:data) { '[{"json": "value"}]' } - before { subject.stub(execute: data) } + before { allow(subject).to receive(:execute).and_return(data) } it 'inspects the container' do - subject.should_receive(:execute).with('docker', 'inspect', cid) + expect(subject).to receive(:execute).with('docker', 'inspect', cid) subject.inspect_container(cid) end @@ -247,10 +253,10 @@ describe VagrantPlugins::DockerProvider::Driver::Compose do describe '#all_containers' do let(:containers) { "container1\ncontainer2" } - before { subject.stub(execute: containers) } + before { allow(subject).to receive(:execute).and_return(containers) } it 'returns an array of all known containers' do - subject.should_receive(:execute).with('docker', 'ps', '-a', '-q', '--no-trunc') + expect(subject).to receive(:execute).with('docker', 'ps', '-a', '-q', '--no-trunc') expect(subject.all_containers).to eq(['container1', 'container2']) end end @@ -258,10 +264,10 @@ describe VagrantPlugins::DockerProvider::Driver::Compose do describe '#docker_bridge_ip' do let(:containers) { " inet 123.456.789.012/16 " } - before { subject.stub(execute: containers) } + before { allow(subject).to receive(:execute).and_return(containers) } it 'returns an array of all known containers' do - subject.should_receive(:execute).with('/sbin/ip', '-4', 'addr', 'show', 'scope', 'global', 'docker0') + expect(subject).to receive(:execute).with('/sbin/ip', '-4', 'addr', 'show', 'scope', 'global', 'docker0') expect(subject.docker_bridge_ip).to eq('123.456.789.012') end end diff --git a/test/unit/plugins/providers/docker/driver_test.rb b/test/unit/plugins/providers/docker/driver_test.rb index dbfde3595..189b06164 100644 --- a/test/unit/plugins/providers/docker/driver_test.rb +++ b/test/unit/plugins/providers/docker/driver_test.rb @@ -75,12 +75,12 @@ describe VagrantPlugins::DockerProvider::Driver do context 'when container exists' do before { subject.stub(execute: "foo\n#{cid}\nbar") } - it { expect(result).to be_true } + it { expect(result).to be_truthy } end context 'when container does not exist' do before { subject.stub(execute: "foo\n#{cid}extra\nbar") } - it { expect(result).to be_false } + it { expect(result).to be_falsey } end end @@ -102,12 +102,12 @@ describe VagrantPlugins::DockerProvider::Driver do context 'when container exists' do before { subject.stub(execute: "foo\n#{cid}\nbar") } - it { expect(result).to be_true } + it { expect(result).to be_truthy } end context 'when container does not exist' do before { subject.stub(execute: "foo\n#{cid}extra\nbar") } - it { expect(result).to be_false } + it { expect(result).to be_falsey } end end diff --git a/test/unit/plugins/providers/virtualbox/config_test.rb b/test/unit/plugins/providers/virtualbox/config_test.rb index 237eaa415..ea044247c 100644 --- a/test/unit/plugins/providers/virtualbox/config_test.rb +++ b/test/unit/plugins/providers/virtualbox/config_test.rb @@ -39,10 +39,10 @@ describe VagrantPlugins::ProviderVirtualBox::Config do context "defaults" do before { subject.finalize! } - it { expect(subject.check_guest_additions).to be_true } - it { expect(subject.gui).to be_false } + it { expect(subject.check_guest_additions).to be(true) } + it { expect(subject.gui).to be(false) } it { expect(subject.name).to be_nil } - it { expect(subject.functional_vboxsf).to be_true } + it { expect(subject.functional_vboxsf).to be(true) } it "should have one NAT adapter" do expect(subject.network_adapters).to eql({ diff --git a/test/unit/plugins/providers/virtualbox/synced_folder_test.rb b/test/unit/plugins/providers/virtualbox/synced_folder_test.rb index cbe93d573..e97280806 100644 --- a/test/unit/plugins/providers/virtualbox/synced_folder_test.rb +++ b/test/unit/plugins/providers/virtualbox/synced_folder_test.rb @@ -42,8 +42,6 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do machine.stub(driver: driver) end - it "should share the folders" do - pending - end + it "should share the folders" end end diff --git a/test/unit/plugins/provisioners/ansible/config/guest_test.rb b/test/unit/plugins/provisioners/ansible/config/guest_test.rb index 1b08182e6..92b7851c5 100644 --- a/test/unit/plugins/provisioners/ansible/config/guest_test.rb +++ b/test/unit/plugins/provisioners/ansible/config/guest_test.rb @@ -51,7 +51,7 @@ describe VagrantPlugins::Ansible::Config::Guest do it "assigns default values to unset guest-specific options" do subject.finalize! - expect(subject.install).to be_true + expect(subject.install).to be(true) expect(subject.install_mode).to eql(:default) expect(subject.provisioning_path).to eql("/vagrant") expect(subject.tmp_path).to eql("/tmp/vagrant-ansible") diff --git a/test/unit/plugins/provisioners/ansible/config/host_test.rb b/test/unit/plugins/provisioners/ansible/config/host_test.rb index e8d7bc27a..1a23fecfe 100644 --- a/test/unit/plugins/provisioners/ansible/config/host_test.rb +++ b/test/unit/plugins/provisioners/ansible/config/host_test.rb @@ -47,10 +47,10 @@ describe VagrantPlugins::Ansible::Config::Host, :skip_windows => true do it "assigns default values to unset host-specific options" do subject.finalize! - expect(subject.ask_sudo_pass).to be_false - expect(subject.ask_vault_pass).to be_false - expect(subject.force_remote_user).to be_true - expect(subject.host_key_checking).to be_false + expect(subject.ask_sudo_pass).to be(false) + expect(subject.ask_vault_pass).to be(false) + expect(subject.force_remote_user).to be(true) + expect(subject.host_key_checking).to be(false) expect(subject.raw_ssh_args).to be_nil end end diff --git a/test/unit/plugins/provisioners/ansible/config/shared.rb b/test/unit/plugins/provisioners/ansible/config/shared.rb index 92b2e0d90..d9bd8cca3 100644 --- a/test/unit/plugins/provisioners/ansible/config/shared.rb +++ b/test/unit/plugins/provisioners/ansible/config/shared.rb @@ -17,11 +17,11 @@ shared_examples_for 'options shared by both Ansible provisioners' do expect(subject.raw_arguments).to be_nil expect(subject.skip_tags).to be_nil expect(subject.start_at_task).to be_nil - expect(subject.sudo).to be_false + expect(subject.sudo).to be(false) expect(subject.sudo_user).to be_nil expect(subject.tags).to be_nil expect(subject.vault_password_file).to be_nil - expect(subject.verbose).to be_false + expect(subject.verbose).to be(false) end end diff --git a/test/unit/plugins/provisioners/ansible/provisioner_test.rb b/test/unit/plugins/provisioners/ansible/provisioner_test.rb index 699480eaf..a9eb51a01 100644 --- a/test/unit/plugins/provisioners/ansible/provisioner_test.rb +++ b/test/unit/plugins/provisioners/ansible/provisioner_test.rb @@ -45,20 +45,22 @@ VF host: '127.0.0.1', port: 2223 }} + let(:default_execute_result) { Vagrant::Util::Subprocess::Result.new(0, "", "") } let(:existing_file) { File.expand_path(__FILE__) } let(:generated_inventory_dir) { File.join(machine.env.local_data_path, %w(provisioners ansible inventory)) } let(:generated_inventory_file) { File.join(generated_inventory_dir, 'vagrant_ansible_inventory') } before do - Vagrant::Util::Platform.stub(solaris?: false) + allow(Vagrant::Util::Platform).to receive(:solaris?).and_return(false) - machine.stub(ssh_info: ssh_info) - machine.env.stub(active_machines: [[iso_env.machine_names[0], :dummy], [iso_env.machine_names[1], :dummy]]) + allow(machine).to receive(:ssh_info).and_return(ssh_info) + allow(machine.env).to receive(:active_machines) + .and_return([[iso_env.machine_names[0], :dummy], [iso_env.machine_names[1], :dummy]]) stubbed_ui = Vagrant::UI::Colored.new - stubbed_ui.stub(detail: "") - machine.env.stub(ui: stubbed_ui) + allow(stubbed_ui).to receive(:detail).and_return("") + allow(machine.env).to receive(:ui).and_return(stubbed_ui) config.playbook = 'playbook.yml' end @@ -74,7 +76,7 @@ VF expected_transport_mode = "ssh") it "sets implicit arguments in a specific order" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args[0]).to eq("ansible-playbook") expect(args[1]).to eq("--connection=ssh") @@ -84,11 +86,11 @@ VF expect(inventory_count).to be > 0 expect(args[args.length-2]).to eq("playbook.yml") - } + }.and_return(default_execute_result) end it "sets --limit argument" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| all_limits = args.select { |x| x =~ /^(--limit=|-l)/ } if config.raw_arguments raw_limits = config.raw_arguments.select { |x| x =~ /^(--limit=|-l)/ } @@ -102,11 +104,11 @@ VF expect(all_limits.first).to eq("--limit=#{machine.name}") end end - } + }.and_return(default_execute_result) end it "exports environment variables" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last if expected_host_key_checking @@ -119,30 +121,30 @@ VF expect(cmd_opts[:env]).to_not include("ANSIBLE_NOCOLOR") expect(cmd_opts[:env]['ANSIBLE_HOST_KEY_CHECKING']).to eql(expected_host_key_checking.to_s) expect(cmd_opts[:env]['PYTHONUNBUFFERED']).to eql(1) - } + }.and_return(default_execute_result) end # "roughly" verify that only expected args/vars have been defined by the provisioner it "sets the expected number of arguments and environment variables" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args.length-2).to eq(expected_args_count) expect(args.last[:env].length).to eq(expected_vars_count) - } + }.and_return(default_execute_result) end it "enables '#{expected_transport_mode}' as default transport mode" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| index = args.rindex("--connection=#{expected_transport_mode}") expect(index).to be > 0 - expect(find_last_argument_after(index, args, /--connection=\w+/)).to be_false - } + expect(find_last_argument_after(index, args, /--connection=\w+/)).to be(false) + }.and_return(default_execute_result) end end def self.it_should_set_optional_arguments(arg_map) it "sets optional arguments" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| arg_map.each_pair do |vagrant_option, ansible_argument| index = args.index(ansible_argument) if config.send(vagrant_option) @@ -151,25 +153,25 @@ VF expect(index).to be_nil end end - } + }.and_return(default_execute_result) end end def self.it_should_explicitly_enable_ansible_ssh_control_persist_defaults it "configures ControlPersist (like Ansible defaults) via ANSIBLE_SSH_ARGS" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o ControlMaster=auto") expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o ControlPersist=60s") - } + }.and_return(default_execute_result) end end def self.it_should_create_and_use_generated_inventory(with_ssh_user = true) it "generates an inventory with all active machines" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(config.inventory_path).to be_nil - expect(File.exists?(generated_inventory_file)).to be_true + expect(File.exists?(generated_inventory_file)).to be(true) inventory_content = File.read(generated_inventory_file) if with_ssh_user expect(inventory_content).to include("#{machine.name} ansible_ssh_host=#{machine.ssh_info[:host]} ansible_ssh_port=#{machine.ssh_info[:port]} ansible_ssh_user='#{machine.ssh_info[:username]}' ansible_ssh_private_key_file='#{machine.ssh_info[:private_key_path][0]}'\n") @@ -177,31 +179,32 @@ VF expect(inventory_content).to include("#{machine.name} ansible_ssh_host=#{machine.ssh_info[:host]} ansible_ssh_port=#{machine.ssh_info[:port]} ansible_ssh_private_key_file='#{machine.ssh_info[:private_key_path][0]}'\n") end expect(inventory_content).to include("# MISSING: '#{iso_env.machine_names[1]}' machine was probably removed without using Vagrant. This machine should be recreated.\n") - } + }.and_return(default_execute_result) end it "sets as ansible inventory the directory containing the auto-generated inventory file" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| inventory_index = args.rindex("--inventory-file=#{generated_inventory_dir}") expect(inventory_index).to be > 0 - expect(find_last_argument_after(inventory_index, args, /--inventory-file=\w+/)).to be_false - } + expect(find_last_argument_after(inventory_index, args, /--inventory-file=\w+/)).to be(false) + }.and_return(default_execute_result) end end describe "#provision" do before do - unless example.metadata[:skip_before] + unless RSpec.current_example.metadata[:skip_before] config.finalize! - Vagrant::Util::Subprocess.stub(execute: Vagrant::Util::Subprocess::Result.new(0, "", "")) - subject.stub(:check_path) + allow(Vagrant::Util::Subprocess).to receive(:execute) + .and_return(Vagrant::Util::Subprocess::Result.new(0, "", "")) + allow(subject).to receive(:check_path) end end after do - unless example.metadata[:skip_after] + unless RSpec.current_example.metadata[:skip_after] subject.provision end end @@ -211,7 +214,7 @@ VF STUBBED_INVALID_PATH = "/test/239nfmd/invalid_path".freeze it 'raises an error when the `playbook` file does not exist', skip_before: true, skip_after: true do - subject.stub(:check_path).and_raise(VagrantPlugins::Ansible::Errors::AnsibleError, + allow(subject).to receive(:check_path).and_raise(VagrantPlugins::Ansible::Errors::AnsibleError, _key: :config_file_not_found, config_option: "playbook", path: STUBBED_INVALID_PATH, @@ -226,7 +229,8 @@ VF %w(config_file extra_vars inventory_path galaxy_role_file vault_password_file).each do |option_name| it "raises an error when the '#{option_name}' does not exist", skip_before: true, skip_after: true do - Vagrant::Util::Subprocess.stub(execute: Vagrant::Util::Subprocess::Result.new(0, "", "")) + allow(Vagrant::Util::Subprocess).to receive(:execute) + .and_return( Vagrant::Util::Subprocess::Result.new(0, "", "")) config.playbook = existing_file config.send(option_name + '=', STUBBED_INVALID_PATH) @@ -247,8 +251,8 @@ VF it "raises an error", skip_before: true, skip_after: true do config.finalize! - subject.stub(:check_path) - Vagrant::Util::Subprocess.stub(execute: Vagrant::Util::Subprocess::Result.new(1, "", "")) + allow(subject).to receive(:check_path) + allow(Vagrant::Util::Subprocess).to receive(:execute).and_return(Vagrant::Util::Subprocess::Result.new(1, "", "")) expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleCommandFailed) end @@ -259,18 +263,18 @@ VF it_should_create_and_use_generated_inventory it "does not add any group section to the generated inventory" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| inventory_content = File.read(generated_inventory_file) expect(inventory_content).to_not match(/^\s*\[^\\+\]\s*$/) # Ending this block with a negative expectation (to_not / not_to) # would lead to a failure of the above expectation. true - } + }.and_return(default_execute_result) end it "doesn't show the ansible-playbook command" do - expect(machine.env.ui).not_to receive(:detail).with { |full_command| + expect(machine.env.ui).not_to receive(:detail).with(any_args) { |full_command| expect(full_command).to include("ansible-playbook") } end @@ -282,9 +286,9 @@ VF end it "uses custom playbook_command to run playbooks" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args[0]).to eq("custom-ansible-playbook") - } + }.and_return(default_execute_result) end end @@ -295,40 +299,40 @@ VF config.host_vars = { machine1: {"http_port" => 80, "comments" => "'some text with spaces'"} } - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| inventory_content = File.read(generated_inventory_file) expect(inventory_content).to match("^" + Regexp.quote(machine.name) + ".+http_port=80 comments='some text with spaces'$") - } + }.and_return(default_execute_result) end it "adds host variables (given in Array format) to the generated inventory" do config.host_vars = { machine1: ["http_port=80", "maxRequestsPerChild=808"] } - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| inventory_content = File.read(generated_inventory_file) expect(inventory_content).to match("^" + Regexp.quote(machine.name) + ".+http_port=80 maxRequestsPerChild=808") - } + }.and_return(default_execute_result) end it "adds host variables (given in String format) to the generated inventory " do config.host_vars = { :machine1 => "http_port=80 maxRequestsPerChild=808" } - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| inventory_content = File.read(generated_inventory_file) expect(inventory_content).to match("^" + Regexp.quote(machine.name) + ".+http_port=80 maxRequestsPerChild=808") - } + }.and_return(default_execute_result) end it "retrieves the host variables by machine name, also in String format" do config.host_vars = { "machine1" => "http_port=80 maxRequestsPerChild=808" } - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| inventory_content = File.read(generated_inventory_file) expect(inventory_content).to match("^" + Regexp.quote(machine.name) + ".+http_port=80 maxRequestsPerChild=808") - } + }.and_return(default_execute_result) end end @@ -347,7 +351,7 @@ VF "bar:children" => ["group1", "group2", "group3", "group5"], } - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| inventory_content = File.read(generated_inventory_file) # Accept String instead of Array for group member list @@ -372,7 +376,7 @@ VF # A group of groups only includes declared groups expect(inventory_content).not_to include("group5") expect(inventory_content).to match(Regexp.quote("[bar:children]\ngroup1\ngroup2\ngroup3\n") + "$") - } + }.and_return(default_execute_result) end it "adds group vars to the generated inventory" do @@ -385,7 +389,7 @@ VF "group3:vars" => "stringvar1=stringvalue1 stringvar2=stringvalue2", } - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| inventory_content = File.read(generated_inventory_file) # Hash syntax @@ -396,7 +400,7 @@ VF # Single string syntax expect(inventory_content).to include("[group3:vars]\nstringvar1=stringvalue1\nstringvar2=stringvalue2\n") - } + }.and_return(default_execute_result) end end @@ -421,11 +425,11 @@ VF it_should_set_optional_arguments({ "sudo_user" => "--sudo-user=root" }) it "it does not set boolean flag when corresponding option is set to false" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args.index("--sudo")).to be_nil expect(args.index("--ask-sudo-pass")).to be_nil expect(args.index("--ask-vault-pass")).to be_nil - } + }.and_return(default_execute_result) end end @@ -450,26 +454,26 @@ VF it_should_set_arguments_and_environment_variables 17, 4, false, "paramiko" it "sets all raw arguments" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| config.raw_arguments.each do |raw_arg| expect(args).to include(raw_arg) end - } + }.and_return(default_execute_result) end it "sets raw arguments after arguments related to supported options" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args.index("--user=lion")).to be > args.index("--user=testuser") expect(args.index("--inventory-file=/forget/it/my/friend")).to be > args.index("--inventory-file=#{generated_inventory_dir}") expect(args.index("--limit=bar")).to be > args.index("--limit=all") expect(args.index("--skip-tags=ignored")).to be > args.index("--skip-tags=foo,bar") - } + }.and_return(default_execute_result) end it "sets boolean flag (e.g. --sudo) defined in raw_arguments, even if corresponding option is set to false" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args).to include('--sudo') - } + }.and_return(default_execute_result) end end @@ -492,10 +496,10 @@ VF it_should_set_arguments_and_environment_variables 6 it "uses a --user argument to set a default remote user" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args).not_to include("--extra-vars=ansible_ssh_user='#{machine.ssh_info[:username]}'") expect(args).to include("--user=#{machine.ssh_info[:username]}") - } + }.and_return(default_execute_result) end end @@ -524,13 +528,13 @@ VF it "generates an inventory with winrm connection settings" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(config.inventory_path).to be_nil - expect(File.exists?(generated_inventory_file)).to be_true + expect(File.exists?(generated_inventory_file)).to be(true) inventory_content = File.read(generated_inventory_file) expect(inventory_content).to include("machine1 ansible_connection=winrm ansible_ssh_host=127.0.0.1 ansible_ssh_port=55986 ansible_ssh_user='winner' ansible_ssh_pass='winword'\n") - } + }.and_return(default_execute_result) end describe "with force_remote_user option disabled" do @@ -539,12 +543,12 @@ VF end it "doesn't set the ansible remote user in inventory and use '--user' argument with the vagrant ssh username" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| inventory_content = File.read(generated_inventory_file) expect(inventory_content).to include("machine1 ansible_connection=winrm ansible_ssh_host=127.0.0.1 ansible_ssh_port=55986 ansible_ssh_pass='winword'\n") expect(args).to include("--user=testuser") - } + }.and_return(default_execute_result) end end end @@ -557,18 +561,18 @@ VF it_should_set_arguments_and_environment_variables 6 it "does not generate the inventory and uses given inventory path instead" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args).to include("--inventory-file=#{existing_file}") expect(args).not_to include("--inventory-file=#{generated_inventory_file}") - expect(File.exists?(generated_inventory_file)).to be_false - } + expect(File.exists?(generated_inventory_file)).to be(false) + }.and_return(default_execute_result) end it "uses an --extra-vars argument to force ansible_ssh_user parameter" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args).not_to include("--user=#{machine.ssh_info[:username]}") expect(args).to include("--extra-vars=ansible_ssh_user='#{machine.ssh_info[:username]}'") - } + }.and_return(default_execute_result) end describe "with force_remote_user option disabled" do @@ -577,10 +581,10 @@ VF end it "uses a --user argument to set a default remote user" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args).not_to include("--extra-vars=ansible_ssh_user='#{machine.ssh_info[:username]}'") expect(args).to include("--user=#{machine.ssh_info[:username]}") - } + }.and_return(default_execute_result) end end end @@ -591,11 +595,11 @@ VF end it "sets ANSIBLE_CONFIG environment variable" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last expect(cmd_opts[:env]).to include("ANSIBLE_CONFIG") expect(cmd_opts[:env]['ANSIBLE_CONFIG']).to eql(existing_file) - } + }.and_return(default_execute_result) end end @@ -607,9 +611,9 @@ VF it_should_set_arguments_and_environment_variables 6 it "should ask the vault password" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args).to include("--ask-vault-pass") - } + }.and_return(default_execute_result) end end @@ -621,9 +625,9 @@ VF it_should_set_arguments_and_environment_variables 6 it "uses the given vault password file" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args).to include("--vault-password-file=#{existing_file}") - } + }.and_return(default_execute_result) end end @@ -636,12 +640,12 @@ VF it_should_explicitly_enable_ansible_ssh_control_persist_defaults it "passes custom SSH options via ANSIBLE_SSH_ARGS with the highest priority" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last raw_opt_index = cmd_opts[:env]['ANSIBLE_SSH_ARGS'].index("-o ControlMaster=no") default_opt_index = cmd_opts[:env]['ANSIBLE_SSH_ARGS'].index("-o ControlMaster=auto") expect(raw_opt_index).to be < default_opt_index - } + }.and_return(default_execute_result) end describe "and with ssh forwarding enabled" do @@ -650,12 +654,12 @@ VF end it "sets '-o ForwardAgent=yes' via ANSIBLE_SSH_ARGS with higher priority than raw_ssh_args values" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last forwardAgentYes = cmd_opts[:env]['ANSIBLE_SSH_ARGS'].index("-o ForwardAgent=yes") forwardAgentNo = cmd_opts[:env]['ANSIBLE_SSH_ARGS'].index("-o ForwardAgent=no") expect(forwardAgentYes).to be < forwardAgentNo - } + }.and_return(default_execute_result) end end @@ -670,10 +674,11 @@ VF it_should_explicitly_enable_ansible_ssh_control_persist_defaults it "passes additional Identity Files via ANSIBLE_SSH_ARGS" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o IdentityFile=/an/other/identity") expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o IdentityFile=/yet/an/other/key") + default_execute_result } end end @@ -682,13 +687,14 @@ VF before do ssh_info[:private_key_path] = ['/foo%bar/key', '/bar%%buz/key'] end - + it "replaces `%` with `%%`" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) do |*args| cmd_opts = args.last expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o IdentityFile=/foo%%bar/key") expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o IdentityFile=/bar%%%%buz/key") - } + default_execute_result + end end end @@ -701,10 +707,10 @@ VF it_should_explicitly_enable_ansible_ssh_control_persist_defaults it "enables SSH-Forwarding via ANSIBLE_SSH_ARGS" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o ForwardAgent=yes") - } + }.and_return(default_execute_result) end end @@ -714,10 +720,10 @@ VF end it "sets '-o ProxyCommand' via ANSIBLE_SSH_ARGS" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o ProxyCommand='ssh -W %h:%p -q user@remote_libvirt_host'") - } + }.and_return(default_execute_result) end end @@ -733,7 +739,7 @@ VF it_should_set_optional_arguments({ "verbose" => "-#{verbose_option}" }) it "shows the ansible-playbook command and set verbosity to '-#{verbose_option}' level" do - expect(machine.env.ui).to receive(:detail).with { |full_command| + expect(machine.env.ui).to receive(:detail).with(any_args) { |full_command| expect(full_command).to eq("PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --limit=\"machine1\" --inventory-file=#{generated_inventory_dir} -#{verbose_option} playbook.yml") } end @@ -748,7 +754,7 @@ VF it_should_set_optional_arguments({ "verbose" => "-#{verbose_option}" }) it "shows the ansible-playbook command and set verbosity to '-#{verbose_option}' level" do - expect(machine.env.ui).to receive(:detail).with { |full_command| + expect(machine.env.ui).to receive(:detail).with(any_args) { |full_command| expect(full_command).to eq("PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --limit=\"machine1\" --inventory-file=#{generated_inventory_dir} -#{verbose_option} playbook.yml") } end @@ -764,7 +770,7 @@ VF it_should_set_optional_arguments({ "verbose" => "-v" }) it "shows the ansible-playbook command and set verbosity to '-v' level" do - expect(machine.env.ui).to receive(:detail).with { |full_command| + expect(machine.env.ui).to receive(:detail).with(any_args) { |full_command| expect(full_command).to eq("PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --limit=\"machine1\" --inventory-file=#{generated_inventory_dir} -v playbook.yml") } end @@ -778,7 +784,7 @@ VF it_should_set_arguments_and_environment_variables it "doesn't show the ansible-playbook command" do - expect(machine.env.ui).not_to receive(:detail).with { |full_command| + expect(machine.env.ui).not_to receive(:detail).with(any_args) { |full_command| expect(full_command).to include("ansible-playbook") } end @@ -788,15 +794,15 @@ VF describe "without colorized output" do before do - machine.env.stub(ui: Vagrant::UI::Basic.new) + allow(machine.env).to receive(:ui).and_return(Vagrant::UI::Basic.new) end it "disables ansible-playbook colored output" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last expect(cmd_opts[:env]).to_not include("ANSIBLE_FORCE_COLOR") expect(cmd_opts[:env]['ANSIBLE_NOCOLOR']).to eql("true") - } + }.and_return(default_execute_result) end end @@ -809,8 +815,9 @@ VF it "raises an error when ansible-galaxy command fails", skip_before: true, skip_after: true do config.finalize! - subject.stub(:check_path) - Vagrant::Util::Subprocess.stub(execute: Vagrant::Util::Subprocess::Result.new(1, "", "")) + allow(subject).to receive(:check_path) + allow(Vagrant::Util::Subprocess).to receive(:execute) + .and_return(Vagrant::Util::Subprocess::Result.new(1, "", "")) expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleCommandFailed) end @@ -835,11 +842,11 @@ VF end it "sets ANSIBLE_ROLES_PATH with corresponding absolute path" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last expect(cmd_opts[:env]).to include("ANSIBLE_ROLES_PATH") expect(cmd_opts[:env]['ANSIBLE_ROLES_PATH']).to eql(File.join(machine.env.root_path, "my-roles")) - } + }.and_return(default_execute_result) end end @@ -906,17 +913,17 @@ VF }) it "also includes given raw arguments" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args).to include("--why-not") expect(args).to include("--su-user=foot") expect(args).to include("--ask-su-pass") expect(args).to include("--limit=all") expect(args).to include("--private-key=./myself.key") - } + }.and_return(default_execute_result) end it "shows the ansible-playbook command, with additional quotes when required" do - expect(machine.env.ui).to receive(:detail).with { |full_command| + expect(machine.env.ui).to receive(:detail).with(any_args) { |full_command| expect(full_command).to eq(%Q(PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_ROLES_PATH='/up/to the stars' ANSIBLE_CONFIG='#{existing_file}' ANSIBLE_HOST_KEY_CHECKING=true ANSIBLE_SSH_ARGS='-o IdentitiesOnly=yes -o IdentityFile=/my/key1 -o IdentityFile=/my/key2 -o ForwardAgent=yes -o ControlMaster=no -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --ask-sudo-pass --ask-vault-pass --limit="machine*:&vagrant:!that_one" --inventory-file=#{generated_inventory_dir} --extra-vars="{\\"var1\\":\\"string with 'apostrophes', \\\\\\\\, \\\\\\" and =\\",\\"var2\\":{\\"x\\":42}}" --sudo --sudo-user=deployer -vvv --vault-password-file=#{existing_file} --tags=db,www --skip-tags=foo,bar --start-at-task="joe's awesome task" --why-not --su-user=foot --ask-su-pass --limit=all --private-key=./myself.key --extra-vars='{\"var3\":\"foo\"}' playbook.yml)) } end @@ -936,21 +943,21 @@ VF }} let(:fake_host_vm) { double("host_vm").tap do |h| - h.stub(ssh_info: fake_host_ssh_info) + allow(h).to receive(:ssh_info).and_return(fake_host_ssh_info) end } before do - machine.stub(provider_name: :docker) - machine.provider.stub(host_vm?: true) - machine.provider.stub(host_vm: fake_host_vm) + allow(machine).to receive(:provider_name).and_return(:docker) + allow(machine.provider).to receive(:host_vm?).and_return(true) + allow(machine.provider).to receive(:host_vm).and_return(fake_host_vm) end it "uses an SSH ProxyCommand to reach the VM" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o ProxyCommand='ssh boot9docker@127.0.0.1 -p 2299 -i /path/to/docker/host/key -o Compression=yes -o ConnectTimeout=5 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no exec nc %h %p 2>/dev/null'") - } + }.and_return(default_execute_result) end end @@ -960,12 +967,12 @@ VF context "on a Windows host" do before do - Vagrant::Util::Platform.stub(windows?: true) - machine.ui.stub(:warn) + allow(Vagrant::Util::Platform).to receive(:windows?).and_return(true) + allow(machine.ui).to receive(:warn) end it "warns that Windows is not officially supported for the Ansible control machine" do - expect(machine.env.ui).to receive(:warn).with { |warning| + expect(machine.env.ui).to receive(:warn).with(any_args) { |warning| expect(warning).to eq(I18n.t("vagrant.provisioners.ansible.windows_not_supported_for_control_machine")) } end @@ -973,32 +980,32 @@ VF context "on a Solaris-like host" do before do - Vagrant::Util::Platform.stub(solaris?: true) + allow(Vagrant::Util::Platform).to receive(:solaris?).and_return(true) end it "does not set IdentitiesOnly=yes in ANSIBLE_SSH_ARGS" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to_not include("-o IdentitiesOnly=yes") # Ending this block with a negative expectation (to_not / not_to) # would lead to a failure of the above expectation. true - } + }.and_return(default_execute_result) end describe "and with host_key_checking option enabled" do it "does not set ANSIBLE_SSH_ARGS environment variable" do config.host_key_checking = true - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last expect(cmd_opts[:env]).to_not include('ANSIBLE_SSH_ARGS') # Ending this block with a negative expectation (to_not / not_to) # would lead to a failure of the above expectation. true - } + }.and_return(Vagrant::Util::Subprocess::Result.new(0, "", "")) end end @@ -1008,13 +1015,13 @@ VF it 'does not set IdentitiesOnly=yes in ANSIBLE_SSH_ARGS' do ssh_info[:keys_only] = false - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to_not include("-o IdentitiesOnly=yes") # Ending this block with a negative expectation (to_not / not_to) # would lead to a failure of the above expectation. - true + default_execute_result } end end diff --git a/test/unit/plugins/provisioners/chef/command_builder_test.rb b/test/unit/plugins/provisioners/chef/command_builder_test.rb index e2359d917..1eb7315c8 100644 --- a/test/unit/plugins/provisioners/chef/command_builder_test.rb +++ b/test/unit/plugins/provisioners/chef/command_builder_test.rb @@ -20,8 +20,8 @@ describe VagrantPlugins::Chef::CommandBuilder do describe ".initialize" do it "raises an error when chef type is not client or solo" do - expect { VagrantPlugins::Chef::CommandBuilder.new(chef_config, :client_bad) }. - to raise_error + expect { VagrantPlugins::Chef::CommandBuilder.new(:client_bad, chef_config) }. + to raise_error(RuntimeError) end it "does not raise an error for :client" do diff --git a/test/unit/plugins/provisioners/docker/config_test.rb b/test/unit/plugins/provisioners/docker/config_test.rb index a0952bb60..2145be87e 100644 --- a/test/unit/plugins/provisioners/docker/config_test.rb +++ b/test/unit/plugins/provisioners/docker/config_test.rb @@ -1,6 +1,7 @@ require File.expand_path("../../../../base", __FILE__) require Vagrant.source_root.join("plugins/provisioners/docker/config") +require Vagrant.source_root.join("plugins/provisioners/docker/provisioner") require Vagrant.source_root.join("plugins/kernel_v2/config/vm") describe VagrantPlugins::DockerProvisioner::Config do @@ -142,7 +143,7 @@ describe VagrantPlugins::DockerProvisioner::Config do describe "#post_install_provision" do it "raises an error if 'docker' provisioner was provided" do expect {subject.post_install_provision("myprov", :type=>"docker", :inline=>"echo 'hello'")} - .to raise_error() + .to raise_error(VagrantPlugins::DockerProvisioner::DockerError) end it "setups a basic provisioner" do diff --git a/test/unit/plugins/pushes/ftp/adapter_test.rb b/test/unit/plugins/pushes/ftp/adapter_test.rb index b577ee49d..93888f840 100644 --- a/test/unit/plugins/pushes/ftp/adapter_test.rb +++ b/test/unit/plugins/pushes/ftp/adapter_test.rb @@ -109,6 +109,7 @@ describe VagrantPlugins::FTPPush::SFTPAdapter do describe "#upload" do it "uploads the file" do pending "a way to mock an SFTP server" + test_with_mock_sftp_server end end end diff --git a/test/unit/plugins/synced_folders/nfs/config_test.rb b/test/unit/plugins/synced_folders/nfs/config_test.rb index c513e2889..670dfb394 100644 --- a/test/unit/plugins/synced_folders/nfs/config_test.rb +++ b/test/unit/plugins/synced_folders/nfs/config_test.rb @@ -10,7 +10,7 @@ describe VagrantPlugins::SyncedFolderNFS::Config do subject.finalize! end - its(:functional) { should be_true } + its(:functional) { should be(true) } its(:map_gid) { should eq(:auto) } its(:map_uid) { should eq(:auto) } end diff --git a/test/unit/plugins/synced_folders/rsync/helper_test.rb b/test/unit/plugins/synced_folders/rsync/helper_test.rb index 4640b5977..5e960d001 100644 --- a/test/unit/plugins/synced_folders/rsync/helper_test.rb +++ b/test/unit/plugins/synced_folders/rsync/helper_test.rb @@ -64,9 +64,9 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do let(:ui) { machine.ui } before do - Vagrant::Util::Subprocess.stub(execute: result) + Vagrant::Util::Subprocess.stub(:execute){ result } - guest.stub(capability?: false) + guest.stub(:capability?){ false } end it "doesn't raise an error if it succeeds" do @@ -83,9 +83,9 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do Vagrant::Util::Platform.stub(windows?: true) expect(Vagrant::Util::Platform).to receive(:cygwin_path).and_return("foo") - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args[args.length - 3]).to eql("foo/") - } + }.and_return(result) subject.rsync_single(machine, ssh_info, opts) end @@ -103,11 +103,11 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do opts[:hostpath] = "/foo" opts[:guestpath] = "/bar" - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*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") - } + }.and_return(result) subject.rsync_single(machine, ssh_info, opts) end @@ -118,22 +118,22 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do hostpath_expanded = File.expand_path(opts[:hostpath], machine.env.root_path) - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args[args.length - 3]).to eql("#{hostpath_expanded}/") expect(args[args.length - 2]).to include("/bar") - } + }.and_return(result) subject.rsync_single(machine, ssh_info, opts) end end it "executes within the root path" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args.last).to be_kind_of(Hash) opts = args.last expect(opts[:workdir]).to eql(machine.env.root_path.to_s) - } + }.and_return(result) 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" - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| index = args.find_index("foo") expect(index).to be > 0 expect(args[index-1]).to eql("--exclude") - } + }.and_return(result) 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"] - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*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") - } + }.and_return(result) 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 - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*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}/") - } + }.and_return(result) 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"] - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*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}/") - } + }.and_return(result) subject.rsync_single(machine, ssh_info, opts) end @@ -228,19 +228,19 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do let(:ui) { machine.ui } before do - Vagrant::Util::Subprocess.stub(execute: result) + Vagrant::Util::Subprocess.stub(:execute){ result } - guest.stub(capability?: false) + guest.stub(:capability?){ false } end it "includes IdentitiesOnly, StrictHostKeyChecking, and UserKnownHostsFile with defaults" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| expect(args[9]).to include('IdentitiesOnly') expect(args[9]).to include('StrictHostKeyChecking') expect(args[9]).to include('UserKnownHostsFile') expect(args[9]).to include("-i '/path/to/key'") - } + }.and_return(result) 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 07d2d4b53..39b654a06 100644 --- a/test/unit/plugins/synced_folders/rsync/synced_folder_test.rb +++ b/test/unit/plugins/synced_folders/rsync/synced_folder_test.rb @@ -26,12 +26,12 @@ describe VagrantPlugins::SyncedFolderRSync::SyncedFolder do describe "#usable?" do it "is usable if rsync can be found" do expect(Vagrant::Util::Which).to receive(:which).with("rsync").and_return(true) - expect(subject.usable?(machine)).to be_true + expect(subject.usable?(machine)).to be(true) end it "is not usable if rsync cant be found" do expect(Vagrant::Util::Which).to receive(:which).with("rsync").and_return(false) - expect(subject.usable?(machine)).to be_false + expect(subject.usable?(machine)).to be(false) end it "raises an exception if asked to" do diff --git a/test/unit/vagrant/action/builtin/box_add_test.rb b/test/unit/vagrant/action/builtin/box_add_test.rb index d3dd8ab33..5c2616b13 100644 --- a/test/unit/vagrant/action/builtin/box_add_test.rb +++ b/test/unit/vagrant/action/builtin/box_add_test.rb @@ -91,7 +91,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do env[:box_name] = "foo" env[:box_url] = box_path.to_s - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo") expect(version).to eq("0") @@ -113,7 +113,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do box_path.to_s, ] - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo") expect(version).to eq("0") @@ -132,7 +132,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do env[:box_name] = "foo" env[:box_url] = "http://127.0.0.1:#{port}/#{box_path.basename}" - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo") expect(version).to eq("0") @@ -152,7 +152,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do env[:box_name] = "foo" env[:box_url] = "ftp://127.0.0.1:#{port}/#{box_path.basename}" - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo") expect(version).to eq("0") @@ -268,7 +268,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do env[:box_provider] = "virtualbox" box_collection.stub(find: box) - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo") expect(version).to eq("0") @@ -288,7 +288,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do box_url_name = "http://127.0.0.1:#{port}/#{box_path.basename}" env[:box_name] = box_url_name - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(name).to eq(box_url_name) expect(version).to eq("0") expect(opts[:metadata_url]).to be_nil @@ -313,7 +313,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do box_url_name = "box name with spaces" env[:box_name] = box_url_name - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(name).to eq(box_url_name) expect(version).to eq("0") expect(opts[:metadata_url]).to be_nil @@ -337,7 +337,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do env[:box_name] = "foo" env[:box_url] = "http://#{username}:#{password}@127.0.0.1:#{port}/#{box_path.basename}" - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo") expect(version).to eq("0") @@ -385,7 +385,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do with_web_server(md_path) do |port| env[:box_url] = "http://127.0.0.1:#{port}/#{md_path.basename}" - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(name).to eq("foo/bar") expect(version).to eq("0.7") expect(checksum(path)).to eq(checksum(box_path)) @@ -430,7 +430,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do with_web_server(md_path, **opts) do |port| env[:box_url] = "http://127.0.0.1:#{port}/#{md_path.basename}" - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(name).to eq("foo/bar") expect(version).to eq("0.7") expect(checksum(path)).to eq(checksum(box_path)) @@ -475,7 +475,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do url = "http://127.0.0.1:#{port}" env[:box_url] = "mitchellh/precise64.json" - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(name).to eq("mitchellh/precise64") expect(version).to eq("0.7") expect(checksum(path)).to eq(checksum(box_path)) @@ -526,7 +526,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do env[:box_url] = "mitchellh/precise64.json" env[:box_server_url] = url - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(name).to eq("mitchellh/precise64") expect(version).to eq("0.7") expect(checksum(path)).to eq(checksum(box_path)) @@ -587,7 +587,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do end end - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(name).to eq("foo/bar") expect(version).to eq("0.7") expect(checksum(path)).to eq(checksum(box_path)) @@ -632,7 +632,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do with_web_server(md_path) do |port| env[:box_url] = "http://127.0.0.1:#{port}/#{md_path.basename}" - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(name).to eq("foo/bar") expect(version).to eq("0.7") expect(checksum(path)).to eq(checksum(box_path)) @@ -776,7 +776,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do end env[:box_url] = tf.path - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo/bar") expect(version).to eq("0.7") @@ -820,7 +820,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do env[:box_url] = tf.path env[:box_provider] = "vmware" - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo/bar") expect(version).to eq("0.7") @@ -869,7 +869,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do env[:box_url] = tf.path env[:box_provider] = "vmware" - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo/bar") expect(version).to eq("0.7") @@ -909,7 +909,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do env[:box_url] = tf.path env[:box_version] = "~> 0.1" - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo/bar") expect(version).to eq("0.5") @@ -954,7 +954,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do env[:box_url] = tf.path env[:box_provider] = "vmware" env[:box_version] = "~> 0.1" - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo/bar") expect(version).to eq("0.5") @@ -1002,7 +1002,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do env[:box_url] = tf.path env[:box_provider] = ["virtualbox", "vmware"] - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo/bar") expect(version).to eq("0.7") @@ -1050,7 +1050,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do expect(env[:ui]).to receive(:ask).and_return("1") - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts| expect(checksum(path)).to eq(checksum(box_path)) expect(name).to eq("foo/bar") expect(version).to eq("0.7") @@ -1226,11 +1226,11 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do env[:box_force] = true env[:box_url] = tf.path box_collection.stub(find: box) - expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(box_collection).to receive(:add).with(any_args) { |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[:force]).to be(true) expect(opts[:metadata_url]).to eq("file://#{tf.path}") true }.and_return(box) 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 0bb175c59..a17f29adb 100644 --- a/test/unit/vagrant/action/builtin/box_check_outdated_test.rb +++ b/test/unit/vagrant/action/builtin/box_check_outdated_test.rb @@ -93,7 +93,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do subject.call(env) - expect(env[:box_outdated]).to be_false + expect(env[:box_outdated]).to be(false) end it "sets env if there is an update" do @@ -126,7 +126,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do subject.call(env) - expect(env[:box_outdated]).to be_true + expect(env[:box_outdated]).to be(true) end it "has an update if it is local" do @@ -138,7 +138,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do subject.call(env) - expect(env[:box_outdated]).to be_true + expect(env[:box_outdated]).to be(true) end it "does not have a local update if not within constraints" do @@ -152,7 +152,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do subject.call(env) - expect(env[:box_outdated]).to be_false + expect(env[:box_outdated]).to be(false) end it "does nothing if metadata download fails" do @@ -163,7 +163,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do subject.call(env) - expect(env[:box_outdated]).to be_false + expect(env[:box_outdated]).to be(false) end it "raises error if has_update? errors" do diff --git a/test/unit/vagrant/action/builtin/confirm_test.rb b/test/unit/vagrant/action/builtin/confirm_test.rb index fb386eb1d..5ade5e247 100644 --- a/test/unit/vagrant/action/builtin/confirm_test.rb +++ b/test/unit/vagrant/action/builtin/confirm_test.rb @@ -47,7 +47,7 @@ describe Vagrant::Action::Builtin::Confirm do end end described_class.new(app, env, message, allowed: ["y", "N"]).call(env) - expect(env[:result]).to be_true + expect(env[:result]).to be(true) expect(times).to eq(4) 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 17f32563f..81f6151f3 100644 --- a/test/unit/vagrant/action/builtin/handle_box_test.rb +++ b/test/unit/vagrant/action/builtin/handle_box_test.rb @@ -54,7 +54,7 @@ describe Vagrant::Action::Builtin::HandleBox do end it "adds a box that doesn't exist" do - expect(action_runner).to receive(:run).with { |action, opts| + expect(action_runner).to receive(:run).with(any_args) { |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) @@ -70,7 +70,7 @@ describe Vagrant::Action::Builtin::HandleBox do it "adds a box using any format the provider allows" do machine.provider_options[:box_format] = [:foo, :bar] - expect(action_runner).to receive(:run).with { |action, opts| + expect(action_runner).to receive(:run).with(any_args) { |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]) @@ -93,7 +93,7 @@ describe Vagrant::Action::Builtin::HandleBox do end it "adds a box that doesn't exist" do - expect(action_runner).to receive(:run).with { |action, opts| + expect(action_runner).to receive(:run).with(any_args) { |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) @@ -118,7 +118,7 @@ describe Vagrant::Action::Builtin::HandleBox do end it "adds a box that doesn't exist and maps checksum options correctly" do - expect(action_runner).to receive(:run).with { |action, opts| + expect(action_runner).to receive(:run).with(any_args) { |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) diff --git a/test/unit/vagrant/action/builtin/is_env_set_test.rb b/test/unit/vagrant/action/builtin/is_env_set_test.rb index 56eafa956..de1bb9774 100644 --- a/test/unit/vagrant/action/builtin/is_env_set_test.rb +++ b/test/unit/vagrant/action/builtin/is_env_set_test.rb @@ -16,7 +16,7 @@ describe Vagrant::Action::Builtin::IsEnvSet do expect(app).to receive(:call).with(env) subject.call(env) - expect(env[:result]).to be_true + expect(env[:result]).to be(true) end it "sets result to false if it isn't set" do @@ -25,7 +25,7 @@ describe Vagrant::Action::Builtin::IsEnvSet do expect(app).to receive(:call).with(env) subject.call(env) - expect(env[:result]).to be_false + expect(env[:result]).to be(false) end end end diff --git a/test/unit/vagrant/action/builtin/is_state_test.rb b/test/unit/vagrant/action/builtin/is_state_test.rb index e060d7fb7..991c9d262 100644 --- a/test/unit/vagrant/action/builtin/is_state_test.rb +++ b/test/unit/vagrant/action/builtin/is_state_test.rb @@ -23,7 +23,7 @@ describe Vagrant::Action::Builtin::IsState do expect(app).to receive(:call).with(env) subject.call(env) - expect(env[:result]).to be_false + expect(env[:result]).to be(false) end it "sets result to true if is proper state" do @@ -34,7 +34,7 @@ describe Vagrant::Action::Builtin::IsState do expect(app).to receive(:call).with(env) subject.call(env) - expect(env[:result]).to be_true + expect(env[:result]).to be(true) end it "inverts the result if specified" do @@ -45,7 +45,7 @@ describe Vagrant::Action::Builtin::IsState do expect(app).to receive(:call).with(env) subject.call(env) - expect(env[:result]).to be_false + expect(env[:result]).to be(false) 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 ab4934dff..3ce90fc10 100644 --- a/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb +++ b/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb @@ -147,7 +147,7 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do folders["root"] = { type: "unusable" } expect { subject.synced_folders(machine) }. - to raise_error + to raise_error(RuntimeError) end it "should ignore disabled folders" do 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 c50d28628..6a9a94469 100644 --- a/test/unit/vagrant/action/builtin/synced_folder_cleanup_test.rb +++ b/test/unit/vagrant/action/builtin/synced_folder_cleanup_test.rb @@ -131,9 +131,9 @@ describe Vagrant::Action::Builtin::SyncedFolderCleanup do subject.call(env) - expect(trackers[0].clean).to be_true - expect(trackers[1].clean).to be_true - expect(trackers[2].clean).to 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/box_collection_test.rb b/test/unit/vagrant/box_collection_test.rb index f012be2ad..5f1467f6d 100644 --- a/test/unit/vagrant/box_collection_test.rb +++ b/test/unit/vagrant/box_collection_test.rb @@ -223,7 +223,7 @@ describe Vagrant::BoxCollection, :skip_windows do environment.box3("foo", "0", :virtualbox, metadata_url: "foourl") - expect(hook).to receive(:call).with { |name, env| + expect(hook).to receive(:call).with(any_args) { |name, env| expect(name).to eq(:authenticate_box_url) expect(env[:box_urls]).to eq(["foourl"]) true diff --git a/test/unit/vagrant/box_test.rb b/test/unit/vagrant/box_test.rb index dfba490aa..7be84d5e8 100644 --- a/test/unit/vagrant/box_test.rb +++ b/test/unit/vagrant/box_test.rb @@ -308,7 +308,7 @@ describe Vagrant::Box, :skip_windows do end # Repackage our box to some temporary directory - expect(subject.repackage(box_output_path)).to be_true + expect(subject.repackage(box_output_path)).to be(true) # Let's now add this box again under a different name, and then # verify that we get the proper result back. diff --git a/test/unit/vagrant/capability_host_test.rb b/test/unit/vagrant/capability_host_test.rb index d460a649b..5bdae28c3 100644 --- a/test/unit/vagrant/capability_host_test.rb +++ b/test/unit/vagrant/capability_host_test.rb @@ -104,15 +104,15 @@ describe Vagrant::CapabilityHost do end it "does not have a non-existent capability" do - expect(subject.capability?(:foo)).to be_false + expect(subject.capability?(:foo)).to be(false) end it "has capabilities of itself" do - expect(subject.capability?(:self)).to be_true + expect(subject.capability?(:self)).to be(true) end it "has capabilities of parent" do - expect(subject.capability?(:parent)).to be_true + expect(subject.capability?(:parent)).to be(true) end end diff --git a/test/unit/vagrant/cli_test.rb b/test/unit/vagrant/cli_test.rb index 4848f14c9..17212659b 100644 --- a/test/unit/vagrant/cli_test.rb +++ b/test/unit/vagrant/cli_test.rb @@ -45,10 +45,10 @@ describe Vagrant::CLI do commands[:bar] = [command_lambda("bar", 0), { primary: true }] commands[:baz] = [command_lambda("baz", 0), { primary: false }] - expect(env.ui).to receive(:info).with { |message, opts| + expect(env.ui).to receive(:info).with(any_args) { |message, opts| expect(message).to include("foo") expect(message).to include("bar") - expect(message.include?("baz")).to be_false + expect(message.include?("baz")).to be(false) } subject.help diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index b8c9b57a0..26bdd1c1d 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -48,8 +48,8 @@ describe Vagrant::Environment do it "should return whether it can install or not" do plugin_host_caps[:foo] = { provider_install_foo: Class } - expect(subject.can_install_provider?(:foo)).to be_true - expect(subject.can_install_provider?(:bar)).to be_false + expect(subject.can_install_provider?(:foo)).to be(true) + expect(subject.can_install_provider?(:bar)).to be(false) end end @@ -202,7 +202,7 @@ describe Vagrant::Environment do plugin_host_caps[:foo] = { bar: Class } result = subject.host - expect(result.capability?(:bar)).to be_true + expect(result.capability?(:bar)).to be(true) end it "should attempt to detect a host if host is :detect" do @@ -216,7 +216,7 @@ describe Vagrant::Environment do plugin_host_caps[:foo] = { bar: Class } result = subject.host - expect(result.capability?(:bar)).to be_true + expect(result.capability?(:bar)).to be(true) end it "should use an exact host if specified" do @@ -231,7 +231,7 @@ describe Vagrant::Environment do plugin_host_caps[:foo] = { bar: Class } result = subject.host - expect(result.capability?(:bar)).to be_true + expect(result.capability?(:bar)).to be(true) end it "should raise an error if an exact match was specified but not found" do @@ -270,7 +270,7 @@ describe Vagrant::Environment do end end - expect(raised).to be_true + expect(raised).to be(true) end it "allows nested locks on the same environment" do @@ -282,7 +282,7 @@ describe Vagrant::Environment do end end - expect(success).to be_true + expect(success).to be(true) end it "cleans up all lock files" do @@ -641,8 +641,8 @@ VF klass = double("machine_index") stub_const("Vagrant::MachineIndex", klass) - klass.should_receive(:new).with do |path| - expect(path.to_s.start_with?(subject.home_path.to_s)).to be_true + klass.should_receive(:new).with(any_args) do |path| + expect(path.to_s.start_with?(subject.home_path.to_s)).to be(true) true end @@ -985,7 +985,7 @@ VF Dir.chdir(temp_dir) do instance = described_class.new(local_data_path: "foo") expect(instance.local_data_path).to eq(instance.cwd.join("foo")) - expect(File.exist?(instance.local_data_path)).to be_false + expect(File.exist?(instance.local_data_path)).to be(false) end end end @@ -1249,7 +1249,7 @@ VF env = environment.create_vagrant_env env.push("foo") - expect(push_class.pushed?).to be_true + expect(push_class.pushed?).to be(true) end end @@ -1257,7 +1257,7 @@ VF it "should call the action runner with the proper hook" do hook_name = :foo - expect(instance.action_runner).to receive(:run).with { |callable, env| + expect(instance.action_runner).to receive(:run).with(any_args) { |callable, env| expect(env[:action_name]).to eq(hook_name) } @@ -1279,7 +1279,7 @@ VF end it "should allow passing in custom data" do - expect(instance.action_runner).to receive(:run).with { |callable, env| + expect(instance.action_runner).to receive(:run).with(any_args) { |callable, env| expect(env[:foo]).to eq(:bar) } @@ -1287,7 +1287,7 @@ VF end it "should allow passing a custom callable" do - expect(instance.action_runner).to receive(:run).with { |callable, env| + expect(instance.action_runner).to receive(:run).with(any_args) { |callable, env| expect(callable).to eq(:what) } diff --git a/test/unit/vagrant/machine_index_test.rb b/test/unit/vagrant/machine_index_test.rb index ed52e9eaa..e9aa20945 100644 --- a/test/unit/vagrant/machine_index_test.rb +++ b/test/unit/vagrant/machine_index_test.rb @@ -136,7 +136,7 @@ describe Vagrant::MachineIndex do end it "should include? by prefix" do - expect(subject.include?("b")).to be_true + expect(subject.include?("b")).to be(true) end it "locks the entry so subsequent gets fail" do @@ -159,7 +159,7 @@ describe Vagrant::MachineIndex do describe "#include" do it "should not include non-existent things" do - expect(subject.include?("foo")).to be_false + expect(subject.include?("foo")).to be(false) end it "should include created entries" do @@ -168,7 +168,7 @@ describe Vagrant::MachineIndex do subject.release(result) subject = described_class.new(data_dir) - expect(subject.include?(result.id)).to be_true + expect(subject.include?(result.id)).to be(true) end end @@ -204,7 +204,7 @@ describe Vagrant::MachineIndex do it "can delete an entry that doesn't exist" do e = entry_klass.new - expect(subject.delete(e)).to be_true + expect(subject.delete(e)).to be(true) end it "updates an existing entry" do diff --git a/test/unit/vagrant/machine_test.rb b/test/unit/vagrant/machine_test.rb index 8163b46c4..fdb9aa090 100644 --- a/test/unit/vagrant/machine_test.rb +++ b/test/unit/vagrant/machine_test.rb @@ -81,7 +81,7 @@ describe Vagrant::Machine do it "should not insert key" do subject = new_instance - expect(subject.config.ssh.insert_key).to be_false + expect(subject.config.ssh.insert_key).to be(false) end end @@ -197,7 +197,7 @@ describe Vagrant::Machine do it "should initialize the capabilities" do instance = new_provider_mock - expect(instance).to receive(:_initialize).with { |p, m| + expect(instance).to receive(:_initialize).with(any_args) { |p, m| expect(p).to eq(provider_name) expect(m.name).to eq(name) true @@ -383,7 +383,7 @@ describe Vagrant::Machine do it "should run the callable with the proper env" do subject.action_raw(:foo, callable) - expect(@env[:called]).to be_true + expect(@env[:called]).to be(true) expect(@env[:action_name]).to eq(:machine_action_foo) expect(@env[:machine]).to equal(subject) expect(@env[:machine_action]).to eq(:foo) @@ -398,7 +398,7 @@ describe Vagrant::Machine do it "should merge in any extra env" do subject.action_raw(:bar, callable, foo: :bar) - expect(@env[:called]).to be_true + expect(@env[:called]).to be(true) expect(@env[:foo]).to eq(:bar) end end @@ -788,18 +788,18 @@ describe Vagrant::Machine do context "with custom ssh_info" do it "keys_only should be default" do - expect(instance.ssh_info[:keys_only]).to be_true + expect(instance.ssh_info[:keys_only]).to be(true) end it "paranoid should be default" do - expect(instance.ssh_info[:paranoid]).to be_false + expect(instance.ssh_info[:paranoid]).to be(false) end it "keys_only should be overridden" do instance.config.ssh.keys_only = false - expect(instance.ssh_info[:keys_only]).to be_false + expect(instance.ssh_info[:keys_only]).to be(false) end it "paranoid should be overridden" do instance.config.ssh.paranoid = true - expect(instance.ssh_info[:paranoid]).to be_true + expect(instance.ssh_info[:paranoid]).to be(true) end end end diff --git a/test/unit/vagrant/plugin/manager_test.rb b/test/unit/vagrant/plugin/manager_test.rb index 8889c5ebd..f982ca119 100644 --- a/test/unit/vagrant/plugin/manager_test.rb +++ b/test/unit/vagrant/plugin/manager_test.rb @@ -30,9 +30,9 @@ 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" - expect(bundler).to receive(:install).once.with { |plugins, local| + expect(bundler).to receive(:install).once.with(any_args) { |plugins, local| expect(plugins).to have_key("foo") - expect(local).to be_false + expect(local).to be(false) }.and_return(specs) expect(bundler).to receive(:clean) @@ -92,10 +92,10 @@ describe Vagrant::Plugin::Manager do end it "installs a version with constraints" do - expect(bundler).to receive(:install).once.with { |plugins, local| + expect(bundler).to receive(:install).once.with(any_args) { |plugins, local| expect(plugins).to have_key("foo") expect(plugins["foo"]["gem_version"]).to eql(">= 0.1.0") - expect(local).to be_false + expect(local).to be(false) }.and_return(specs) expect(bundler).to receive(:clean) @@ -107,10 +107,10 @@ describe Vagrant::Plugin::Manager do end it "installs with an exact version but doesn't constrain" do - expect(bundler).to receive(:install).once.with { |plugins, local| + expect(bundler).to receive(:install).once.with(any_args) { |plugins, local| expect(plugins).to have_key("foo") expect(plugins["foo"]["gem_version"]).to eql("0.1.0") - expect(local).to be_false + expect(local).to be(false) }.and_return(specs) expect(bundler).to receive(:clean) @@ -170,7 +170,7 @@ describe Vagrant::Plugin::Manager do subject.uninstall_plugin("bar") plugins = subject.installed_plugins - expect(plugins["foo"]["system"]).to be_true + expect(plugins["foo"]["system"]).to be(true) end it "raises an error if uninstalling a system gem" do @@ -243,9 +243,9 @@ describe Vagrant::Plugin::Manager do expect(plugins.length).to eql(2) expect(plugins).to have_key("foo") expect(plugins["foo"]["gem_version"]).to eq("0.1.0") - expect(plugins["foo"]["system"]).to be_true + expect(plugins["foo"]["system"]).to be_truthy expect(plugins).to have_key("bar") - expect(plugins["bar"]["system"]).to be_true + expect(plugins["bar"]["system"]).to be(true) end end end diff --git a/test/unit/vagrant/plugin/state_file_test.rb b/test/unit/vagrant/plugin/state_file_test.rb index ec50f3cba..57818064d 100644 --- a/test/unit/vagrant/plugin/state_file_test.rb +++ b/test/unit/vagrant/plugin/state_file_test.rb @@ -36,9 +36,9 @@ describe Vagrant::Plugin::StateFile do end it "should check for plugins" do - expect(subject.has_plugin?("foo")).to be_false + expect(subject.has_plugin?("foo")).to be(false) subject.add_plugin("foo") - expect(subject.has_plugin?("foo")).to be_true + expect(subject.has_plugin?("foo")).to be(true) end it "should remove plugins" do diff --git a/test/unit/vagrant/plugin/v2/plugin_test.rb b/test/unit/vagrant/plugin/v2/plugin_test.rb index 76ad40993..85f472e0c 100644 --- a/test/unit/vagrant/plugin/v2/plugin_test.rb +++ b/test/unit/vagrant/plugin/v2/plugin_test.rb @@ -71,8 +71,8 @@ describe Vagrant::Plugin::V2::Plugin do command("bar", primary: false) { "bar" } end - expect(plugin.components.commands[:foo][1][:primary]).to be_true - expect(plugin.components.commands[:bar][1][:primary]).to be_false + expect(plugin.components.commands[:foo][1][:primary]).to be(true) + expect(plugin.components.commands[:bar][1][:primary]).to be(false) end ["spaces bad", "sym^bols"].each do |bad| diff --git a/test/unit/vagrant/plugin/v2/provider_test.rb b/test/unit/vagrant/plugin/v2/provider_test.rb index 634b311c6..3a3799de3 100644 --- a/test/unit/vagrant/plugin/v2/provider_test.rb +++ b/test/unit/vagrant/plugin/v2/provider_test.rb @@ -48,8 +48,8 @@ describe Vagrant::Plugin::V2::Provider do end it "can execute capabilities" do - expect(subject.capability?(:foo)).to be_false - expect(subject.capability?(:bar)).to be_true + expect(subject.capability?(:foo)).to be(false) + expect(subject.capability?(:bar)).to be(true) expect { subject.capability(:bar) }. to raise_error("bar YEAH") diff --git a/test/unit/vagrant/shared_helpers_test.rb b/test/unit/vagrant/shared_helpers_test.rb index 2ebfc76a5..908e552a8 100644 --- a/test/unit/vagrant/shared_helpers_test.rb +++ b/test/unit/vagrant/shared_helpers_test.rb @@ -18,13 +18,13 @@ describe Vagrant do describe "#in_installer?" do it "is not if env is not set" do with_temp_env("VAGRANT_INSTALLER_ENV" => nil) do - expect(subject.in_installer?).to be_false + expect(subject.in_installer?).to be(false) end end it "is if env is set" do with_temp_env("VAGRANT_INSTALLER_ENV" => "/foo") do - expect(subject.in_installer?).to be_true + expect(subject.in_installer?).to be(true) end end end @@ -47,13 +47,13 @@ describe Vagrant do describe "#plugins_enabled?" do it "returns true if the env is not set" do with_temp_env("VAGRANT_NO_PLUGINS" => nil) do - expect(subject.plugins_enabled?).to be_true + expect(subject.plugins_enabled?).to be(true) end end it "returns false if the env is set" do with_temp_env("VAGRANT_NO_PLUGINS" => "1") do - expect(subject.plugins_enabled?).to be_false + expect(subject.plugins_enabled?).to be(false) end end end diff --git a/test/unit/vagrant/ui_test.rb b/test/unit/vagrant/ui_test.rb index 8ac03437e..fdd75c5b5 100644 --- a/test/unit/vagrant/ui_test.rb +++ b/test/unit/vagrant/ui_test.rb @@ -5,7 +5,7 @@ describe Vagrant::UI::Basic do it "outputs within the a new thread" do current = Thread.current.object_id - expect(subject).to receive(:safe_puts).with { |*args| + expect(subject).to receive(:safe_puts).with(any_args) { |*args| expect(Thread.current.object_id).to_not eq(current) true } @@ -14,7 +14,7 @@ describe Vagrant::UI::Basic do end it "outputs using `puts` by default" do - expect(subject).to receive(:safe_puts).with { |message, **opts| + expect(subject).to receive(:safe_puts).with(any_args) { |message, **opts| expect(opts[:printer]).to eq(:puts) true } @@ -23,7 +23,7 @@ describe Vagrant::UI::Basic do end it "outputs using `print` if new_line is false" do - expect(subject).to receive(:safe_puts).with { |message, **opts| + expect(subject).to receive(:safe_puts).with(any_args) { |message, **opts| expect(opts[:printer]).to eq(:print) true } @@ -32,7 +32,7 @@ describe Vagrant::UI::Basic do end it "outputs using `print` if new_line is false" do - expect(subject).to receive(:safe_puts).with { |message, **opts| + expect(subject).to receive(:safe_puts).with(any_args) { |message, **opts| expect(opts[:printer]).to eq(:print) true } @@ -44,7 +44,7 @@ describe Vagrant::UI::Basic do stdout = StringIO.new subject.stdout = stdout - expect(subject).to receive(:safe_puts).with { |message, **opts| + expect(subject).to receive(:safe_puts).with(any_args) { |message, **opts| expect(opts[:io]).to be(stdout) true } @@ -60,7 +60,7 @@ describe Vagrant::UI::Basic do stderr = StringIO.new subject.stderr = stderr - expect(subject).to receive(:safe_puts).with { |message, **opts| + expect(subject).to receive(:safe_puts).with(any_args) { |message, **opts| expect(opts[:io]).to be(stderr) true } @@ -81,7 +81,7 @@ describe Vagrant::UI::Basic do context "#detail" do it "outputs details" do - expect(subject).to receive(:safe_puts).with { |message, **opts| + expect(subject).to receive(:safe_puts).with(any_args) { |message, **opts| expect(message).to eq("foo") true } @@ -114,7 +114,7 @@ describe Vagrant::UI::Colored do end it "does not bold by default with a color" do - expect(subject).to receive(:safe_puts).with { |message, *args| + expect(subject).to receive(:safe_puts).with(any_args) { |message, *args| expect(message).to start_with("\033[0;31m") expect(message).to end_with("\033[0m") } @@ -125,7 +125,7 @@ describe Vagrant::UI::Colored do describe "#error" do it "colors red" do - expect(subject).to receive(:safe_puts).with { |message, *args| + expect(subject).to receive(:safe_puts).with(any_args) { |message, *args| expect(message).to start_with("\033[0;31m") expect(message).to end_with("\033[0m") } @@ -153,7 +153,7 @@ describe Vagrant::UI::Colored do it "colors output to color specified in global opts" do subject.opts[:color] = :red - expect(subject).to receive(:safe_puts).with { |message, *args| + expect(subject).to receive(:safe_puts).with(any_args) { |message, *args| expect(message).to start_with("\033[0;31m") expect(message).to end_with("\033[0m") } @@ -164,7 +164,7 @@ describe Vagrant::UI::Colored do it "colors output to specified color over global opts" do subject.opts[:color] = :red - expect(subject).to receive(:safe_puts).with { |message, *args| + expect(subject).to receive(:safe_puts).with(any_args) { |message, *args| expect(message).to start_with("\033[0;32m") expect(message).to end_with("\033[0m") } @@ -175,7 +175,7 @@ describe Vagrant::UI::Colored do it "bolds the output if specified" do subject.opts[:color] = :red - expect(subject).to receive(:safe_puts).with { |message, *args| + expect(subject).to receive(:safe_puts).with(any_args) { |message, *args| expect(message).to start_with("\033[1;31m") expect(message).to end_with("\033[0m") } @@ -186,7 +186,7 @@ describe Vagrant::UI::Colored do describe "#success" do it "colors green" do - expect(subject).to receive(:safe_puts).with { |message, *args| + expect(subject).to receive(:safe_puts).with(any_args) { |message, *args| expect(message).to start_with("\033[0;32m") expect(message).to end_with("\033[0m") } @@ -197,7 +197,7 @@ describe Vagrant::UI::Colored do describe "#warn" do it "colors yellow" do - expect(subject).to receive(:safe_puts).with { |message, *args| + expect(subject).to receive(:safe_puts).with(any_args) { |message, *args| expect(message).to start_with("\033[0;33m") expect(message).to end_with("\033[0m") } @@ -218,7 +218,7 @@ describe Vagrant::UI::MachineReadable do [:detail, :warn, :error, :info, :output, :success].each do |method| describe "##{method}" do it "outputs UI type to the machine-readable output" do - expect(subject).to receive(:safe_puts).with { |message| + expect(subject).to receive(:safe_puts).with(any_args) { |message| parts = message.split(",") expect(parts.length).to eq(5) expect(parts[1]).to eq("") @@ -235,7 +235,7 @@ describe Vagrant::UI::MachineReadable do describe "#machine" do it "is formatted properly" do - expect(subject).to receive(:safe_puts).with { |message| + expect(subject).to receive(:safe_puts).with(any_args) { |message| parts = message.split(",") expect(parts.length).to eq(5) expect(parts[1]).to eq("") @@ -249,7 +249,7 @@ describe Vagrant::UI::MachineReadable do end it "includes a target if given" do - expect(subject).to receive(:safe_puts).with { |message| + expect(subject).to receive(:safe_puts).with(any_args) { |message| parts = message.split(",") expect(parts.length).to eq(4) expect(parts[1]).to eq("boom") @@ -262,7 +262,7 @@ describe Vagrant::UI::MachineReadable do end it "replaces commas" do - expect(subject).to receive(:safe_puts).with { |message| + expect(subject).to receive(:safe_puts).with(any_args) { |message| parts = message.split(",") expect(parts.length).to eq(4) expect(parts[3]).to eq("foo%!(VAGRANT_COMMA)bar") @@ -273,7 +273,7 @@ describe Vagrant::UI::MachineReadable do end it "replaces newlines" do - expect(subject).to receive(:safe_puts).with { |message| + expect(subject).to receive(:safe_puts).with(any_args) { |message| parts = message.split(",") expect(parts.length).to eq(4) expect(parts[3]).to eq("foo\\nbar\\r") @@ -286,7 +286,7 @@ 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 - expect(subject).to receive(:safe_puts).with { |message| + expect(subject).to receive(:safe_puts).with(any_args) { |message| parts = message.split(",") expect(parts.length).to eq(4) expect(parts[3]).to eq("foo\\nbar\\r") diff --git a/test/unit/vagrant/util/downloader_test.rb b/test/unit/vagrant/util/downloader_test.rb index 5a9bf2f2f..9f61399bd 100644 --- a/test/unit/vagrant/util/downloader_test.rb +++ b/test/unit/vagrant/util/downloader_test.rb @@ -69,7 +69,7 @@ describe Vagrant::Util::Downloader do with("curl", *curl_options). and_return(subprocess_result) - expect(subject.download!).to be_true + expect(subject.download!).to be(true) end end @@ -90,7 +90,7 @@ describe Vagrant::Util::Downloader do with("curl", *curl_options). and_return(subprocess_result) - expect(subject.download!).to be_true + expect(subject.download!).to be(true) end end @@ -116,7 +116,7 @@ describe Vagrant::Util::Downloader do end it "should not raise an exception" do - expect(subject.download!).to be_true + expect(subject.download!).to be(true) end end @@ -144,7 +144,7 @@ describe Vagrant::Util::Downloader do end it "should not raise an exception" do - expect(subject.download!).to be_true + expect(subject.download!).to be(true) end end diff --git a/test/unit/vagrant/util/subprocess_test.rb b/test/unit/vagrant/util/subprocess_test.rb index 94ba4225f..144635fde 100644 --- a/test/unit/vagrant/util/subprocess_test.rb +++ b/test/unit/vagrant/util/subprocess_test.rb @@ -52,14 +52,14 @@ describe Vagrant::Util::Subprocess do context "when subprocess has not been started" do it "should return false" do sp = described_class.new("ls") - expect(sp.running?).to be_false + expect(sp.running?).to be(false) end end context "when subprocess has completed" do it "should return false" do sp = described_class.new("ls") sp.execute - expect(sp.running?).to be_false + expect(sp.running?).to be(false) end end context "when subprocess is running" do @@ -67,7 +67,7 @@ describe Vagrant::Util::Subprocess do sp = described_class.new("sleep", "5") thread = Thread.new{ sp.execute } sleep(0.3) - expect(sp.running?).to be_true + expect(sp.running?).to be(true) sp.stop thread.join end @@ -78,7 +78,7 @@ describe Vagrant::Util::Subprocess do context "when subprocess has not been started" do it "should return false" do sp = described_class.new("ls") - expect(sp.stop).to be_false + expect(sp.stop).to be(false) end end @@ -86,7 +86,7 @@ describe Vagrant::Util::Subprocess do it "should return false" do sp = described_class.new("ls") sp.execute - expect(sp.stop).to be_false + expect(sp.stop).to be(false) end end @@ -95,7 +95,7 @@ describe Vagrant::Util::Subprocess do it "should return true" do thread = Thread.new{ sp.execute } sleep(0.1) - expect(sp.stop).to be_true + expect(sp.stop).to be(true) thread.join end @@ -103,7 +103,7 @@ describe Vagrant::Util::Subprocess do thread = Thread.new{ sp.execute } sleep(0.1) sp.stop - expect(sp.running?).to be_false + expect(sp.running?).to be(false) thread.join end end diff --git a/test/unit/vagrant_test.rb b/test/unit/vagrant_test.rb index 06f7489ca..0742526c4 100644 --- a/test/unit/vagrant_test.rb +++ b/test/unit/vagrant_test.rb @@ -59,11 +59,11 @@ describe Vagrant do name "i_am_installed" end - expect(described_class.has_plugin?("i_am_installed")).to be_true + expect(described_class.has_plugin?("i_am_installed")).to be(true) end it "should return false if the plugin is not installed" do - expect(described_class.has_plugin?("i_dont_exist")).to be_false + expect(described_class.has_plugin?("i_dont_exist")).to be(false) end it "finds plugins by gem name" do @@ -71,8 +71,8 @@ describe Vagrant do specs[0].name = "foo" Vagrant::Plugin::Manager.instance.stub(installed_specs: specs) - expect(described_class.has_plugin?("foo")).to be_true - expect(described_class.has_plugin?("bar")).to be_false + expect(described_class.has_plugin?("foo")).to be(true) + expect(described_class.has_plugin?("bar")).to be(false) end it "finds plugins by gem name and version" do @@ -81,9 +81,9 @@ describe Vagrant do specs[0].version = "1.2.3" Vagrant::Plugin::Manager.instance.stub(installed_specs: specs) - expect(described_class.has_plugin?("foo", "~> 1.2.0")).to be_true - expect(described_class.has_plugin?("foo", "~> 1.0.0")).to be_false - expect(described_class.has_plugin?("bar", "~> 1.2.0")).to be_false + expect(described_class.has_plugin?("foo", "~> 1.2.0")).to be(true) + expect(described_class.has_plugin?("foo", "~> 1.0.0")).to be(false) + expect(described_class.has_plugin?("bar", "~> 1.2.0")).to be(false) end end diff --git a/vagrant.gemspec b/vagrant.gemspec index d4f573605..3fc6c28a7 100644 --- a/vagrant.gemspec +++ b/vagrant.gemspec @@ -40,8 +40,9 @@ Gem::Specification.new do |s| # Constraint rake to properly handle deprecated method usage # from within rspec - s.add_development_dependency "rake", "~> 11.3.0" - s.add_development_dependency "rspec", "~> 2.14.0" + s.add_development_dependency "rake", "~> 12.0.0" + s.add_development_dependency "rspec", "~> 3.5.0" + s.add_development_dependency "rspec-its", "~> 1.2.0" s.add_development_dependency "webmock", "~> 1.20" s.add_development_dependency "fake_ftp", "~> 0.1.1"