From 06ff3a363cda12153fdc4b2d83750a79bfd87a69 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 5 Mar 2010 16:58:36 -0800 Subject: [PATCH] Env.load_box! gives a reasonable error if the box specified in the Vagrantfile doesn't exist now. --- lib/vagrant/env.rb | 13 +++++++++++-- test/vagrant/env_test.rb | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/env.rb b/lib/vagrant/env.rb index b666410b3..01b572255 100644 --- a/lib/vagrant/env.rb +++ b/lib/vagrant/env.rb @@ -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 diff --git a/test/vagrant/env_test.rb b/test/vagrant/env_test.rb index ce11be832..62f65720b 100644 --- a/test/vagrant/env_test.rb +++ b/test/vagrant/env_test.rb @@ -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