Nicer error message when box is not found. [closes GH-195]

This commit is contained in:
Mitchell Hashimoto 2010-10-21 17:50:41 -07:00
parent af9fdef791
commit ef50361f95
4 changed files with 14 additions and 5 deletions

View File

@ -1,5 +1,6 @@
## 0.6.7 (unreleased) ## 0.6.7 (unreleased)
- Proper error message when box is not found for `config.vm.box`. [GH-195]
- Fix output of `vagrant status` with multi-vm to be correct. [GH-196] - Fix output of `vagrant status` with multi-vm to be correct. [GH-196]
## 0.6.6 (October 14, 2010) ## 0.6.6 (October 14, 2010)

View File

@ -121,7 +121,9 @@ module Vagrant
# #
# @return [Box] # @return [Box]
def box def box
boxes.find(config.vm.box) result = boxes.find(config.vm.box)
raise Errors::BoxNotFound, :name => config.vm.box if vm && !result
result
end end
# Returns the VMs associated with this environment. # Returns the VMs associated with this environment.

View File

@ -25,11 +25,16 @@ module Vagrant
def vagrantfile(*args) def vagrantfile(*args)
path = args.shift.join("Vagrantfile") if Pathname === args.first path = args.shift.join("Vagrantfile") if Pathname === args.first
path ||= vagrant_app("Vagrantfile") path ||= vagrant_app("Vagrantfile")
# Create this box so that it exists
vagrant_box("base")
str = args.shift || "" str = args.shift || ""
File.open(path.to_s, "w") do |f| File.open(path.to_s, "w") do |f|
f.puts "Vagrant::Config.run do |config|" f.puts "Vagrant::Config.run do |config|"
f.puts "config.vagrant.home = '#{home_path}'" f.puts "config.vagrant.home = '#{home_path}'"
f.puts "config.vm.base_mac = 'foo' if !config.vm.base_mac" f.puts "config.vm.base_mac = 'foo' if !config.vm.base_mac"
f.puts "config.vm.box = 'base'"
f.puts str f.puts str
f.puts "end" f.puts "end"
end end

View File

@ -13,18 +13,19 @@ class BoxCollectionTest < Test::Unit::TestCase
result = @klass.new(vagrant_env) result = @klass.new(vagrant_env)
names = result.collect { |b| b.name }.sort names = result.collect { |b| b.name }.sort
assert_equal 2, result.length assert result.length >= 2
assert_equal ["bar", "foo"], names assert names.include?("foo")
assert names.include?("bar")
end end
should "reload the box list" do should "reload the box list" do
instance = @klass.new(vagrant_env) instance = @klass.new(vagrant_env)
assert instance.empty? amount = instance.length
vagrant_box("foo") vagrant_box("foo")
instance.reload! instance.reload!
assert !instance.empty? assert_equal (amount + 1), instance.length
end end
should "find a specific box" do should "find a specific box" do