If a box contains a Vagrantfile, that is now loaded in the configuration chain between the gem config and the project config.

This commit is contained in:
Mitchell Hashimoto 2010-02-23 21:50:44 -08:00
parent 3b198e208d
commit 71abd76fae
2 changed files with 38 additions and 4 deletions

View File

@ -28,10 +28,9 @@ module Vagrant
end
def load_config!
load_paths = [
File.join(PROJECT_ROOT, "config", "default.rb"),
File.join(root_path, ROOTFILE_NAME)
]
load_paths = [File.join(PROJECT_ROOT, "config", "default.rb")]
load_paths << File.join(box.directory, ROOTFILE_NAME) if box
load_paths << File.join(root_path, ROOTFILE_NAME)
load_paths.each do |path|
logger.info "Loading config from #{path}..."
@ -59,6 +58,11 @@ module Vagrant
def load_box!
@@box = Box.find(Vagrant.config.vm.box) if Vagrant.config.vm.box
if @@box
logger.info("Reloading configuration to account for loaded box...")
load_config!
end
end
def load_vm!

View File

@ -57,6 +57,7 @@ class EnvTest < Test::Unit::TestCase
setup do
@root_path = "/foo"
Vagrant::Env.stubs(:root_path).returns(@root_path)
Vagrant::Env.stubs(:box).returns(nil)
File.stubs(:exist?).returns(false)
Vagrant::Config.stubs(:execute!)
Vagrant::Config.stubs(:reset!)
@ -77,6 +78,20 @@ class EnvTest < Test::Unit::TestCase
Vagrant::Env.load_config!
end
should "not load from the box directory if it is nil" do
Vagrant::Env.expects(:box).once.returns(nil)
Vagrant::Env.load_config!
end
should "load from the box directory if it is not nil" do
dir = "foo"
box = mock("box")
box.stubs(:directory).returns(dir)
Vagrant::Env.expects(:box).twice.returns(box)
File.expects(:exist?).with(File.join(dir, Vagrant::Env::ROOTFILE_NAME)).once
Vagrant::Env.load_config!
end
should "load the files only if exist? returns true" do
File.expects(:exist?).once.returns(true)
Vagrant::Env.expects(:load).once
@ -102,6 +117,7 @@ class EnvTest < Test::Unit::TestCase
Vagrant::Env.expects(:load_vm!).once
Vagrant::Env.expects(:load_root_path!).once
Vagrant::Env.expects(:load_home_directory!).once
Vagrant::Env.expects(:load_box!).once
Vagrant::Env.load!
end
end
@ -209,6 +225,8 @@ class EnvTest < Test::Unit::TestCase
context "loading box" do
setup do
@box = mock("box")
Vagrant::Env.stubs(:load_config!)
end
should "set the box to what is found by the Box class" do
@ -216,6 +234,18 @@ class EnvTest < Test::Unit::TestCase
Vagrant::Env.load_box!
assert @box.equal?(Vagrant::Env.box)
end
should "load the config if a box is loaded" do
Vagrant::Env.expects(:load_config!).once
Vagrant::Box.expects(:find).returns(@box)
Vagrant::Env.load_box!
end
should "not load the config if a box is not loaded" do
Vagrant::Env.expects(:load_config!).never
Vagrant::Box.expects(:find).returns(nil)
Vagrant::Env.load_box!
end
end
context "requiring boxes" do