diff --git a/lib/vagrant/command/helpers.rb b/lib/vagrant/command/helpers.rb index 3405ca65c..7b074b85b 100644 --- a/lib/vagrant/command/helpers.rb +++ b/lib/vagrant/command/helpers.rb @@ -12,6 +12,8 @@ module Vagrant # This returns an array of {VM} objects depending on the arguments # given to the command. def target_vms(name=nil) + raise Errors::NoEnvironmentError.new if !env.root_path + name ||= self.name rescue nil @target_vms ||= begin diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 28f6b8d02..8ac506ef2 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -220,7 +220,6 @@ module Vagrant def load! if !loaded? @loaded = true - raise Errors::NoEnvironmentError.new if !root_path self.class.check_virtualbox! load_config! load_vm! @@ -242,7 +241,7 @@ module Vagrant loader.queue << File.expand_path("config/default.rb", Vagrant.source_root) loader.queue << File.join(box.directory, ROOTFILE_NAME) if !first_run && box loader.queue << File.join(home_path, ROOTFILE_NAME) if !first_run && home_path - loader.queue << File.join(root_path, ROOTFILE_NAME) + loader.queue << File.join(root_path, ROOTFILE_NAME) if root_path # If this environment is representing a sub-VM, then we push that # proc on as the last configuration. diff --git a/test/vagrant/command/helpers_test.rb b/test/vagrant/command/helpers_test.rb index 381f4e05a..c47548992 100644 --- a/test/vagrant/command/helpers_test.rb +++ b/test/vagrant/command/helpers_test.rb @@ -27,7 +27,14 @@ class CommandHelpersTest < Test::Unit::TestCase context "vms from args" do setup do @env = vagrant_env - @env.stubs(:root_path).returns(7) + end + + should "raise an exception if no root path" do + @env.stubs(:root_path).returns(nil) + + assert_raises(Vagrant::Errors::NoEnvironmentError) { + command([], @env).target_vms + } end should "only calculate the result once" do