From ba8307712d695d9a07f61f9d2cc61a37de206a84 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 16 Sep 2010 18:14:41 -0600 Subject: [PATCH] Don't require root path to load an environment. (Makes `vagrant box` commands work again without a Vagrantfile) --- lib/vagrant/command/helpers.rb | 2 ++ lib/vagrant/environment.rb | 3 +-- test/vagrant/command/helpers_test.rb | 9 ++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) 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