diff --git a/lib/vagrant/commands/up.rb b/lib/vagrant/commands/up.rb new file mode 100644 index 000000000..137e04bc0 --- /dev/null +++ b/lib/vagrant/commands/up.rb @@ -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 \ No newline at end of file diff --git a/test/vagrant/commands/up_test.rb b/test/vagrant/commands/up_test.rb new file mode 100644 index 000000000..777df4cbf --- /dev/null +++ b/test/vagrant/commands/up_test.rb @@ -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