Get rid of Environment#create_vm. VMs instances are now always available
This commit is contained in:
parent
14bb07e08f
commit
c8e36274d6
|
@ -243,13 +243,6 @@ 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(:env => self)
|
||||
end
|
||||
|
||||
# Persists this environment's VM to the dotfile so it can be
|
||||
# re-loaded at a later time.
|
||||
def persist_vm
|
||||
|
|
|
@ -11,7 +11,6 @@ module Vagrant
|
|||
# a Vagrant::VM object or returns nil.
|
||||
def find(uuid, env=nil, vm_name=nil)
|
||||
vm = VirtualBox::VM.find(uuid)
|
||||
return nil if vm.nil?
|
||||
new(:vm => vm, :env => env, :vm_name => vm_name)
|
||||
end
|
||||
end
|
||||
|
@ -71,6 +70,14 @@ module Vagrant
|
|||
@ssh ||= SSH.new(env)
|
||||
end
|
||||
|
||||
# Returns a boolean true if the VM has been created, otherwise
|
||||
# returns false.
|
||||
#
|
||||
# @return [Boolean]
|
||||
def created?
|
||||
!vm.nil?
|
||||
end
|
||||
|
||||
def uuid
|
||||
vm ? vm.uuid : nil
|
||||
end
|
||||
|
|
|
@ -552,27 +552,6 @@ class EnvironmentTest < Test::Unit::TestCase
|
|||
@env.stubs(:vm).returns(@vm)
|
||||
end
|
||||
|
||||
context "creating a new VM" do
|
||||
should "create a new VM with the given environment" do
|
||||
result = mock("result")
|
||||
Vagrant::VM.expects(:new).with(:env => @env).once.returns(result)
|
||||
@env.create_vm
|
||||
assert_equal result, @env.vm
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
setup do
|
||||
mock_vm
|
||||
|
|
|
@ -20,12 +20,14 @@ class VMTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
context "finding a VM" do
|
||||
should "return nil if the VM is not found" do
|
||||
should "return return an uncreated VM object if the VM is not found" do
|
||||
VirtualBox::VM.expects(:find).returns(nil)
|
||||
assert_nil Vagrant::VM.find("foo")
|
||||
result = Vagrant::VM.find("foo")
|
||||
assert result.is_a?(Vagrant::VM)
|
||||
assert !result.created?
|
||||
end
|
||||
|
||||
should "return a Vagrant::VM object for that VM otherwise" do
|
||||
should "return a Vagrant::VM object for that VM if found" do
|
||||
VirtualBox::VM.expects(:find).with("foo").returns("bar")
|
||||
result = Vagrant::VM.find("foo", mock_environment)
|
||||
assert result.is_a?(Vagrant::VM)
|
||||
|
@ -39,6 +41,18 @@ class VMTest < Test::Unit::TestCase
|
|||
@mock_vm.stubs(:uuid).returns("foo")
|
||||
end
|
||||
|
||||
context "checking if created" do
|
||||
should "return true if the VM object is not nil" do
|
||||
@vm.stubs(:vm).returns(:foo)
|
||||
assert @vm.created?
|
||||
end
|
||||
|
||||
should "return false if the VM object is nil" do
|
||||
@vm.stubs(:vm).returns(nil)
|
||||
assert !@vm.created?
|
||||
end
|
||||
end
|
||||
|
||||
context "accessing the SSH object" do
|
||||
setup do
|
||||
# Reset this to nil to force the reload
|
||||
|
|
Loading…
Reference in New Issue