Env.load_box! gives a reasonable error if the box specified in the Vagrantfile doesn't exist now.

This commit is contained in:
Mitchell Hashimoto 2010-03-05 16:58:36 -08:00
parent 0a54ea1464
commit 06ff3a363c
2 changed files with 22 additions and 4 deletions

View File

@ -60,9 +60,18 @@ module Vagrant
end
def load_box!
@@box = Box.find(Vagrant.config.vm.box) if Vagrant.config.vm.box
if Vagrant.config.vm.box
@@box = Box.find(Vagrant.config.vm.box)
if !@@box
error_and_exit(<<-msg)
Specified box `#{Vagrant.config.vm.box}` does not exist!
The box must be added through the `vagrant box add` command. Please view
the documentation associated with the command for more information.
msg
end
if @@box
logger.info("Reloading configuration to account for loaded box...")
load_config!
end

View File

@ -229,6 +229,15 @@ class EnvTest < Test::Unit::TestCase
Vagrant::Env.stubs(:load_config!)
end
should "not load the box if its not set" do
mock_config do |config|
config.vm.box = nil
end
Vagrant::Box.expects(:find).never
Vagrant::Env.load_box!
end
should "set the box to what is found by the Box class" do
Vagrant::Box.expects(:find).with(Vagrant.config.vm.box).once.returns(@box)
Vagrant::Env.load_box!
@ -241,9 +250,9 @@ class EnvTest < Test::Unit::TestCase
Vagrant::Env.load_box!
end
should "not load the config if a box is not loaded" do
Vagrant::Env.expects(:load_config!).never
should "error and exit if a box is specified but doesn't exist" do
Vagrant::Box.expects(:find).returns(nil)
Vagrant::Env.expects(:error_and_exit).once
Vagrant::Env.load_box!
end
end