diff --git a/lib/vagrant/machine_index.rb b/lib/vagrant/machine_index.rb index 02fd13db9..29788ebaa 100644 --- a/lib/vagrant/machine_index.rb +++ b/lib/vagrant/machine_index.rb @@ -263,7 +263,7 @@ module Vagrant # # @return [Hash] def find_by_prefix(prefix) - return if !prefix + return if !prefix || prefix == "" @machines.each do |uuid, data| return data.merge("id" => uuid) if uuid.start_with?(prefix) end diff --git a/test/unit/plugins/commands/destroy/command_test.rb b/test/unit/plugins/commands/destroy/command_test.rb index 782455d17..73ea9b45d 100644 --- a/test/unit/plugins/commands/destroy/command_test.rb +++ b/test/unit/plugins/commands/destroy/command_test.rb @@ -164,11 +164,18 @@ describe VagrantPlugins::CommandDestroy::Command do subject.execute end - context "with an invalid argument" do + context "with machine that does not exist" do let(:argv){ ["notweb"] } it "raises an exception" do expect { subject.execute }.to raise_error(Vagrant::Errors::MachineNotFound) end end + + context "with an invalid argument" do + let(:argv){ [""] } + it "raises an exception" do + expect { subject.execute }.to raise_error(Vagrant::Errors::MachineNotFound) + end + end end end diff --git a/test/unit/vagrant/machine_index_test.rb b/test/unit/vagrant/machine_index_test.rb index 5556063af..09fa755a0 100644 --- a/test/unit/vagrant/machine_index_test.rb +++ b/test/unit/vagrant/machine_index_test.rb @@ -108,6 +108,11 @@ describe Vagrant::MachineIndex do expect(subject.get(nil)).to be_nil end + it "returns nil if the machine doesn't exist (is an empty string)" do + expect(subject.get("")).to be_nil + expect(subject.get(nil)).to be_nil + end + it "returns a valid entry if the machine exists" do result = subject.get("bar") @@ -144,7 +149,6 @@ describe Vagrant::MachineIndex do expect(subject.include?(nil)).to be(false) end - it "locks the entry so subsequent gets fail" do result = subject.get("bar") expect(result).to_not be_nil