diff --git a/lib/vagrant/env.rb b/lib/vagrant/env.rb index 01b572255..bdae6d84f 100644 --- a/lib/vagrant/env.rb +++ b/lib/vagrant/env.rb @@ -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 diff --git a/test/vagrant/env_test.rb b/test/vagrant/env_test.rb index 62f65720b..ec192debe 100644 --- a/test/vagrant/env_test.rb +++ b/test/vagrant/env_test.rb @@ -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