Up command
This commit is contained in:
parent
e6006eacfa
commit
60c6ad480c
|
@ -0,0 +1,22 @@
|
|||
module Vagrant
|
||||
class Commands
|
||||
class Up < Base
|
||||
Base.subcommand "up", self
|
||||
description "Creates the vagrant environment"
|
||||
|
||||
def execute(args=[])
|
||||
if env.vm
|
||||
logger.info "VM already created. Starting VM if its not already running..."
|
||||
env.vm.start
|
||||
else
|
||||
env.require_box
|
||||
env.create_vm.execute!(Actions::VM::Up)
|
||||
end
|
||||
end
|
||||
|
||||
def options_spec(opts)
|
||||
opts.banner = "Usage: vagrant up"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,41 @@
|
|||
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
||||
|
||||
class CommandsUpTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@klass = Vagrant::Commands::Up
|
||||
|
||||
@env = mock_environment
|
||||
@instance = @klass.new(@env)
|
||||
|
||||
@persisted_vm = mock("persisted_vm")
|
||||
@persisted_vm.stubs(:execute!)
|
||||
end
|
||||
|
||||
context "executing" do
|
||||
setup do
|
||||
@new_vm = mock("vm")
|
||||
@new_vm.stubs(:execute!)
|
||||
|
||||
@env.stubs(:vm).returns(nil)
|
||||
@env.stubs(:require_box)
|
||||
@env.stubs(:create_vm).returns(@new_vm)
|
||||
end
|
||||
|
||||
should "require a box" do
|
||||
@env.expects(:require_box).once
|
||||
@instance.execute
|
||||
end
|
||||
|
||||
should "call the up action on VM if it doesn't exist" do
|
||||
@new_vm.expects(:execute!).with(Vagrant::Actions::VM::Up).once
|
||||
@instance.execute
|
||||
end
|
||||
|
||||
should "call start on the persisted vm if it exists" do
|
||||
@env.stubs(:vm).returns(@persisted_vm)
|
||||
@persisted_vm.expects(:start).once
|
||||
@env.expects(:create_vm).never
|
||||
@instance.execute
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue