Box existence error checking is now in proper 'require_box'

This commit is contained in:
Mitchell Hashimoto 2010-03-06 21:48:39 -08:00
parent 49c98ad8af
commit 6fd10504e0
2 changed files with 33 additions and 19 deletions

View File

@ -60,18 +60,9 @@ module Vagrant
end
def load_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
@@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
@ -114,11 +105,20 @@ msg
def require_box
if !box
error_and_exit(<<-msg)
if !Vagrant.config.vm.box
error_and_exit(<<-msg)
No base box was specified! A base box is required as a staring point
for every vagrant virtual machine. Please specify one in your Vagrantfile
using `config.vm.box`
msg
else
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
end
end

View File

@ -249,18 +249,32 @@ class EnvTest < Test::Unit::TestCase
Vagrant::Box.expects(:find).returns(@box)
Vagrant::Env.load_box!
end
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
context "requiring boxes" do
should "error and exit if no box is found" do
mock_config do |config|
config.vm.box = nil
end
Vagrant::Env.expects(:box).returns(nil)
Vagrant::Env.expects(:error_and_exit).once
Vagrant::Env.expects(:error_and_exit).once.with() do |msg|
assert msg =~ /no base box was specified/i
true
end
Vagrant::Env.require_box
end
should "error and exit if box is specified but doesn't exist" do
mock_config do |config|
config.vm.box = "foo"
end
Vagrant::Env.expects(:box).returns(nil)
Vagrant::Env.expects(:error_and_exit).once.with() do |msg|
assert msg =~ /does not exist/i
true
end
Vagrant::Env.require_box
end
end