From 2661845b5d19101ae70c871328782e8b487d0e3d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 19 Mar 2010 01:27:40 -0700 Subject: [PATCH] Helper method to create a new VM on an environment. Interim method. --- lib/vagrant/environment.rb | 6 +++++- test/vagrant/environment_test.rb | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 424c19c28..55fe907b2 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -167,9 +167,13 @@ module Vagrant end #--------------------------------------------------------------- - # Methods to persist/unpersist VM + # Methods to manage VM #--------------------------------------------------------------- + def create_vm + @vm = VM.new + end + def persist_vm # Save to the dotfile for this project File.open(dotfile_path, 'w+') do |f| diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index 22cf662d6..b7d9a9b1e 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -429,20 +429,33 @@ class EnvironmentTest < Test::Unit::TestCase end end - context "persisting/depersisting VM" do + context "managing VM" do setup do @env = mock_environment @dotfile_path = "foo" @env.stubs(:dotfile_path).returns(@dotfile_path) + end + def mock_vm @vm = mock("vm") @vm.stubs(:uuid).returns("foo") @env.stubs(:vm).returns(@vm) end + context "creating a new VM" do + should "create a new VM" do + assert_nil @env.vm + @env.create_vm + assert !@env.vm.nil? + assert @env.vm.is_a?(Vagrant::VM) + end + end + context "persisting the VM into a file" do setup do + mock_vm + File.stubs(:open) Vagrant::ActiveList.stubs(:add) end @@ -462,6 +475,8 @@ class EnvironmentTest < Test::Unit::TestCase context "depersisting the VM" do setup do + mock_vm + File.stubs(:exist?).returns(false) File.stubs(:delete)