Sha256: c2ca3d8ad67b5ea116844ba8761f84197c3ca0a4c1af66ac34534901007376a2

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')

class CommandsProvisionTest < Test::Unit::TestCase
  setup do
    @klass = Vagrant::Commands::Provision
    @env = mock_environment
    @instance = @klass.new(@env)
  end

  context "executing" do
    should "provision all if no name is given" do
      @instance.expects(:all_or_single).with([], :provision).once
      @instance.execute
    end
  end

  context "provisioning a single VM" do
    setup do
      @foo_vm = mock("vm")
      @foo_vm.stubs(:env).returns(@env)

      @vm_for_real = mock("vm for real")
      @foo_vm.stubs(:vm).returns(@vm_for_real)
      vms = { :foo => @foo_vm }
      @env.stubs(:vms).returns(vms)
    end

    should "error and exit if the VM doesn't exist" do
      @env.stubs(:vms).returns({})
      @instance.expects(:error_and_exit).with(:unknown_vm, :vm => 'foo').once
      @instance.execute(["foo"])
    end

    should "reload if it's running" do
      @vm_for_real.stubs(:running?).returns(true)
      @foo_vm.expects(:provision).once
      @instance.execute(["foo"])
    end

    should "do log to info if it's not running" do
      logger = mock("logger")
      logger.expects(:info)
      @env.stubs(:logger).returns(logger)
      @vm_for_real.stubs(:running?).returns(false)
      @foo_vm.expects(:provision).never
      @instance.execute(["foo"])
    end
  end

end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
vagrantup-0.4.0 test/vagrant/commands/provision_test.rb
vagrant-0.4.0 test/vagrant/commands/provision_test.rb