diff --git a/lib/vagrant/box.rb b/lib/vagrant/box.rb index 67ed8923d..e4a265c20 100644 --- a/lib/vagrant/box.rb +++ b/lib/vagrant/box.rb @@ -81,7 +81,7 @@ module Vagrant # @return [Box] Instance of {Box} representing the box found def find(env, name) return nil unless File.directory?(directory(env, name)) - new(name) + new(env, name) end # Adds a new box with given name from the given URI. This method @@ -115,8 +115,9 @@ module Vagrant # # **Note:** This method does not actually _create_ the box, but merely # returns a new, abstract representation of it. To add a box, see {#add}. - def initialize(name=nil) + def initialize(env=nil, name=nil) @name = name + @env = env end # Returns path to the OVF file of the box. The OVF file is an open diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index ca1535408..7eebdc2b7 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -167,7 +167,6 @@ module Vagrant return unless root_path @box = Box.find(self, config.vm.box) if config.vm.box - @box.env = self if @box end # Loads the persisted VM (if it exists) for this environment. diff --git a/test/vagrant/box_test.rb b/test/vagrant/box_test.rb index 37a5f93fa..559e83f27 100644 --- a/test/vagrant/box_test.rb +++ b/test/vagrant/box_test.rb @@ -71,6 +71,13 @@ class BoxTest < Test::Unit::TestCase assert result assert_equal @name, result.name end + + should "return a box object with the proper env set" do + File.expects(:directory?).with(@dir).once.returns(true) + result = Vagrant::Box.find(@env, @name) + assert result + assert_equal @env, result.env + end end context "adding" do diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index 3738c2ffc..c0dbd5a12 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -345,12 +345,6 @@ class EnvironmentTest < Test::Unit::TestCase @env.load_box! assert @box.equal?(@env.box) end - - should "set the environment of the box" do - @box.expects(:env=).with(@env).once - Vagrant::Box.expects(:find).with(@env, @env.config.vm.box).once.returns(@box) - @env.load_box! - end end context "loading the UUID out from the persisted dotfile" do