Env.load_box! gives a reasonable error if the box specified in the Vagrantfile doesn't exist now.
This commit is contained in:
parent
0a54ea1464
commit
06ff3a363c
|
@ -60,9 +60,18 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_box!
|
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...")
|
logger.info("Reloading configuration to account for loaded box...")
|
||||||
load_config!
|
load_config!
|
||||||
end
|
end
|
||||||
|
|
|
@ -229,6 +229,15 @@ class EnvTest < Test::Unit::TestCase
|
||||||
Vagrant::Env.stubs(:load_config!)
|
Vagrant::Env.stubs(:load_config!)
|
||||||
end
|
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
|
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::Box.expects(:find).with(Vagrant.config.vm.box).once.returns(@box)
|
||||||
Vagrant::Env.load_box!
|
Vagrant::Env.load_box!
|
||||||
|
@ -241,9 +250,9 @@ class EnvTest < Test::Unit::TestCase
|
||||||
Vagrant::Env.load_box!
|
Vagrant::Env.load_box!
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not load the config if a box is not loaded" do
|
should "error and exit if a box is specified but doesn't exist" do
|
||||||
Vagrant::Env.expects(:load_config!).never
|
|
||||||
Vagrant::Box.expects(:find).returns(nil)
|
Vagrant::Box.expects(:find).returns(nil)
|
||||||
|
Vagrant::Env.expects(:error_and_exit).once
|
||||||
Vagrant::Env.load_box!
|
Vagrant::Env.load_box!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue