diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 55fe907b2..d950a315f 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -161,6 +161,7 @@ module Vagrant File.open(dotfile_path) do |f| @vm = Vagrant::VM.find(f.read) + @vm.env = self end rescue Errno::ENOENT @vm = nil @@ -170,10 +171,17 @@ module Vagrant # Methods to manage VM #--------------------------------------------------------------- + # Sets the VM to a new VM. This is not too useful but is used + # in {Command.up}. This will very likely be refactored at a later + # time. def create_vm @vm = VM.new + @vm.env = self + @vm end + # Persists this environment's VM to the dotfile so it can be + # re-loaded at a later time. def persist_vm # Save to the dotfile for this project File.open(dotfile_path, 'w+') do |f| @@ -184,6 +192,7 @@ module Vagrant ActiveList.add(vm) end + # Removes this environment's VM from the dotfile. def depersist_vm # Delete the dotfile if it exists File.delete(dotfile_path) if File.exist?(dotfile_path) diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index 5265353c2..000698ee3 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -2,6 +2,7 @@ module Vagrant class VM < Actions::Runner include Vagrant::Util + attr_accessor :env attr_accessor :vm attr_accessor :from diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index b7d9a9b1e..f946c975f 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -338,6 +338,7 @@ class EnvironmentTest < Test::Unit::TestCase should "loading of the uuid from the dotfile" do vm = mock("vm") + vm.expects(:env=).with(@env) filemock = mock("filemock") filemock.expects(:read).returns("foo") @@ -450,6 +451,16 @@ class EnvironmentTest < Test::Unit::TestCase assert !@env.vm.nil? assert @env.vm.is_a?(Vagrant::VM) end + + should "set the new VM's environment to the env" do + @env.create_vm + assert_equal @env, @env.vm.env + end + + should "return the new VM" do + result = @env.create_vm + assert result.is_a?(Vagrant::VM) + end end context "persisting the VM into a file" do