diff --git a/BRANCH_TODO b/BRANCH_TODO index 62631e6a5..cdf50d48a 100644 --- a/BRANCH_TODO +++ b/BRANCH_TODO @@ -1,8 +1,9 @@ This is a TODO file for only this branch (config-overhaul) * Config validation +* What happens if a configured box doesn't exist? * Separation of global vs VM configuration. # Put VM-specific config directly into Vagrant::VM objects * Only allow one kind of vagrantfile to be loaded (i.e. if both Vagrantfile and vagrantfile exist, throw an error) -* Nicer error if can't setup home directory \ No newline at end of file +* Nicer error if can't setup home directory diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 4c94fadf3..b003a717e 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -162,13 +162,6 @@ module Vagrant @_boxes ||= BoxCollection.new(self) end - # Returns the box that this environment represents. - # - # @return [Box] - def box - boxes.find(config.vm.box) - end - # Returns the VMs associated with this environment. # # @return [Hash] @@ -458,7 +451,7 @@ module Vagrant config = inner_load[subvm] # Second pass, with the box - config = inner_load[subvm, config.vm.box] + config = inner_load[subvm, boxes.find(config.vm.box)] config.vm.name = vm_name.to_s # Return the final configuration for this VM diff --git a/test/unit/support/isolated_environment.rb b/test/unit/support/isolated_environment.rb index c3a302561..61e85e102 100644 --- a/test/unit/support/isolated_environment.rb +++ b/test/unit/support/isolated_environment.rb @@ -43,10 +43,23 @@ module Unit Vagrant::Environment.new(:cwd => @workdir, :home_path => @homedir) end - def vagrantfile(contents) - @workdir.join("Vagrantfile").open("w+") do |f| + def vagrantfile(contents, root=nil) + root ||= @workdir + root.join("Vagrantfile").open("w+") do |f| f.write(contents) end end + + def box(name, vagrantfile_contents) + box_dir = boxes_dir.join(name) + box_dir.mkdir + vagrantfile(vagrantfile_contents, box_dir) + end + + def boxes_dir + dir = @homedir.join("boxes") + dir.mkdir + dir + end end end diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index 7b0f0b7a1..8a4049232 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -84,6 +84,25 @@ VF env.config.for_vm("foo").ssh.port.should == 100 env.config.for_vm("bar").ssh.port.should == 200 end + + it "should load box configuration" do + environment = isolated_environment do |env| + env.vagrantfile(<<-VF) +Vagrant::Config.run do |config| + config.vm.box = "base" +end +VF + + env.box("base", <<-VF) +Vagrant::Config.run do |config| + config.ssh.port = 100 +end +VF + end + + env = environment.create_vagrant_env + env.config.for_vm("default").ssh.port.should == 100 + end end describe "ui" do diff --git a/test/unit_legacy/vagrant/environment_test.rb b/test/unit_legacy/vagrant/environment_test.rb index 6e944839e..189972597 100644 --- a/test/unit_legacy/vagrant/environment_test.rb +++ b/test/unit_legacy/vagrant/environment_test.rb @@ -372,18 +372,6 @@ class EnvironmentTest < Test::Unit::TestCase end end - context "accessing the current box" do - should "return the box that is specified in the config" do - vagrant_box("foo") - env = vagrant_env(vagrantfile(<<-vf)) - config.vm.box = "foo" - vf - - assert env.box - assert_equal "foo", env.box.name - end - end - context "accessing the VMs hash" do should "load the environment if its not already loaded" do env = @klass.new(:cwd => vagrantfile)