vagrant 0.8.7 → 0.8.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. data/.gitignore +21 -0
  2. data/CHANGELOG.md +25 -0
  3. data/README.md +38 -8
  4. data/Rakefile +13 -6
  5. data/bin/vagrant +6 -1
  6. data/config/default.rb +2 -2
  7. data/lib/vagrant/action/box/download.rb +14 -2
  8. data/lib/vagrant/action/vm/check_box.rb +8 -1
  9. data/lib/vagrant/action/vm/check_guest_additions.rb +6 -3
  10. data/lib/vagrant/action/vm/share_folders.rb +12 -1
  11. data/lib/vagrant/command/init.rb +1 -1
  12. data/lib/vagrant/downloaders/http.rb +29 -2
  13. data/lib/vagrant/hosts.rb +1 -0
  14. data/lib/vagrant/hosts/bsd.rb +1 -0
  15. data/lib/vagrant/hosts/freebsd.rb +51 -0
  16. data/lib/vagrant/provisioners/chef.rb +6 -5
  17. data/lib/vagrant/provisioners/chef_client.rb +1 -1
  18. data/lib/vagrant/provisioners/chef_solo.rb +13 -4
  19. data/lib/vagrant/ssh.rb +24 -49
  20. data/lib/vagrant/ssh/session.rb +1 -1
  21. data/lib/vagrant/systems/solaris.rb +57 -11
  22. data/lib/vagrant/test_helpers.rb +23 -0
  23. data/lib/vagrant/ui.rb +1 -1
  24. data/lib/vagrant/util.rb +0 -1
  25. data/lib/vagrant/util/file_checksum.rb +38 -0
  26. data/lib/vagrant/util/platform.rb +1 -1
  27. data/lib/vagrant/util/safe_exec.rb +2 -1
  28. data/lib/vagrant/version.rb +1 -1
  29. data/tasks/acceptance.rake +113 -0
  30. data/tasks/bundler.rake +3 -0
  31. data/tasks/test.rake +15 -0
  32. data/templates/commands/init/Vagrantfile.erb +3 -0
  33. data/templates/locales/en.yml +1 -1
  34. data/test/acceptance/base.rb +48 -0
  35. data/test/acceptance/box_test.rb +77 -0
  36. data/test/acceptance/destroy_test.rb +37 -0
  37. data/test/acceptance/halt_test.rb +72 -0
  38. data/test/acceptance/init_test.rb +33 -0
  39. data/test/acceptance/resume_test.rb +17 -0
  40. data/test/acceptance/ssh_test.rb +41 -0
  41. data/test/acceptance/support/config.rb +42 -0
  42. data/test/acceptance/support/isolated_environment.rb +226 -0
  43. data/test/acceptance/support/matchers/have_color.rb +9 -0
  44. data/test/acceptance/support/matchers/match_output.rb +14 -0
  45. data/test/acceptance/support/output.rb +87 -0
  46. data/test/acceptance/support/shared/base_context.rb +65 -0
  47. data/test/acceptance/support/shared/command_examples.rb +33 -0
  48. data/test/acceptance/support/tempdir.rb +34 -0
  49. data/test/acceptance/support/virtualbox.rb +36 -0
  50. data/test/acceptance/suspend_test.rb +56 -0
  51. data/test/acceptance/up_basic_test.rb +58 -0
  52. data/test/acceptance/up_with_box_url.rb +40 -0
  53. data/test/acceptance/vagrant_test.rb +47 -0
  54. data/test/acceptance/version_test.rb +20 -0
  55. data/test/buildbot/README.md +72 -0
  56. data/test/buildbot/buildbot_config/__init__.py +0 -0
  57. data/test/buildbot/buildbot_config/config/__init__.py +0 -0
  58. data/test/buildbot/buildbot_config/config/loader.py +24 -0
  59. data/test/buildbot/buildbot_config/config/master.py +24 -0
  60. data/test/buildbot/buildbot_config/config/slave.py +22 -0
  61. data/test/buildbot/buildbot_config/master/__init__.py +6 -0
  62. data/test/buildbot/buildbot_config/master/builders.py +78 -0
  63. data/test/buildbot/buildbot_config/master/buildsteps.py +100 -0
  64. data/test/buildbot/buildbot_config/master/change_sources.py +8 -0
  65. data/test/buildbot/buildbot_config/master/schedulers.py +32 -0
  66. data/test/buildbot/buildbot_config/master/slaves.py +60 -0
  67. data/test/buildbot/buildbot_config/master/status.py +52 -0
  68. data/test/buildbot/master/Makefile.sample +28 -0
  69. data/test/buildbot/master/buildbot.tac +36 -0
  70. data/test/buildbot/master/master.cfg +67 -0
  71. data/test/buildbot/master/public_html/bg_gradient.jpg +0 -0
  72. data/test/buildbot/master/public_html/default.css +545 -0
  73. data/test/buildbot/master/public_html/favicon.ico +0 -0
  74. data/test/buildbot/master/public_html/robots.txt +10 -0
  75. data/test/buildbot/master/public_html/static/css/bootstrap-1.4.0.min.css +356 -0
  76. data/test/buildbot/master/public_html/static/css/prettify.css +97 -0
  77. data/test/buildbot/master/public_html/static/css/syntax.css +60 -0
  78. data/test/buildbot/master/public_html/static/css/vagrant.base.css +205 -0
  79. data/test/buildbot/master/public_html/static/images/base_box_mac.jpg +0 -0
  80. data/test/buildbot/master/public_html/static/images/getting-started/success.jpg +0 -0
  81. data/test/buildbot/master/public_html/static/images/icons/error.png +0 -0
  82. data/test/buildbot/master/public_html/static/images/vagrant_chilling.png +0 -0
  83. data/test/buildbot/master/public_html/static/images/vagrant_holding.png +0 -0
  84. data/test/buildbot/master/public_html/static/images/vagrant_looking.png +0 -0
  85. data/test/buildbot/master/public_html/static/images/windows/alter_path.jpg +0 -0
  86. data/test/buildbot/master/public_html/static/images/windows/edit_path.jpg +0 -0
  87. data/test/buildbot/master/public_html/static/images/windows/environment_variables_button.jpg +0 -0
  88. data/test/buildbot/master/public_html/static/images/windows/port_and_ppk_path.jpg +0 -0
  89. data/test/buildbot/master/public_html/static/images/windows/ppk_selection.jpg +0 -0
  90. data/test/buildbot/master/public_html/static/images/windows/putty_first_screen.jpg +0 -0
  91. data/test/buildbot/master/public_html/static/images/windows/save_result.jpg +0 -0
  92. data/test/buildbot/master/public_html/static/images/windows/vbox_manage_default_location.jpg +0 -0
  93. data/test/buildbot/master/public_html/static/js/bootstrap-tabs.js +80 -0
  94. data/test/buildbot/master/public_html/static/js/jquery-1.7.min.js +4 -0
  95. data/test/buildbot/master/templates/authfail.html +9 -0
  96. data/test/buildbot/master/templates/build.html +205 -0
  97. data/test/buildbot/master/templates/builder.html +118 -0
  98. data/test/buildbot/master/templates/builders.html +33 -0
  99. data/test/buildbot/master/templates/buildslave.html +72 -0
  100. data/test/buildbot/master/templates/buildslaves.html +70 -0
  101. data/test/buildbot/master/templates/change.html +15 -0
  102. data/test/buildbot/master/templates/layouts/base.html +58 -0
  103. data/test/buildbot/master/templates/macros/box.html +37 -0
  104. data/test/buildbot/master/templates/macros/build_line.html +50 -0
  105. data/test/buildbot/master/templates/macros/change.html +81 -0
  106. data/test/buildbot/master/templates/macros/forms.html +300 -0
  107. data/test/buildbot/master/templates/root.html +42 -0
  108. data/test/buildbot/master/templates/waterfall.html +53 -0
  109. data/test/buildbot/requirements.txt +4 -0
  110. data/test/buildbot/scripts/deploy.sh +38 -0
  111. data/test/buildbot/scripts/setup.sh +107 -0
  112. data/test/buildbot/slave/buildbot.tac +43 -0
  113. data/test/buildbot/slave/info/admin +1 -0
  114. data/test/buildbot/slave/info/host +1 -0
  115. data/test/buildbot/tests/__init__.py +0 -0
  116. data/test/buildbot/tests/master/__init__.py +0 -0
  117. data/test/buildbot/tests/master/test_slaves.py +41 -0
  118. data/test/buildbot/vendor/choices-0.4.0.tar.gz +0 -0
  119. data/test/config/acceptance_boxes.yml +7 -0
  120. data/test/unit/test_helper.rb +4 -0
  121. data/test/unit/vagrant/action/box/download_test.rb +2 -2
  122. data/test/unit/vagrant/action/vm/check_box_test.rb +6 -1
  123. data/test/unit/vagrant/action/vm/share_folders_test.rb +1 -1
  124. data/test/unit/vagrant/command/init_test.rb +10 -0
  125. data/test/unit/vagrant/downloaders/http_test.rb +12 -1
  126. data/test/unit/vagrant/provisioners/chef_test.rb +7 -0
  127. data/test/unit/vagrant/ssh/session_test.rb +2 -2
  128. data/test/unit/vagrant/ssh_test.rb +5 -8
  129. data/vagrant.gemspec +6 -0
  130. metadata +195 -7
@@ -0,0 +1,9 @@
1
+ RSpec::Matchers.define :have_color do
2
+ match do |actual|
3
+ actual.index("\e[31m")
4
+ end
5
+
6
+ failure_message_for_should do |actual|
7
+ "expected output to contain color, but didn't"
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require "support/output"
2
+
3
+ # This creates a matcher that is used to match against certain
4
+ # Vagrant output. Vagrant output is not what is being tested,
5
+ # so all that state is hidden away in Acceptance::Output.
6
+ RSpec::Matchers.define :match_output do |expected, *args|
7
+ match do |actual|
8
+ Acceptance::Output.new(actual).send(expected, *args)
9
+ end
10
+
11
+ failure_message_for_should do |actual|
12
+ "expected output to match: #{expected} #{args.inspect}"
13
+ end
14
+ end
@@ -0,0 +1,87 @@
1
+ module Acceptance
2
+ # This class helps with matching against output so that every
3
+ # test isn't inherently tied to the output format of Vagrant.
4
+ class Output
5
+ DEFAULT_VM = "default"
6
+
7
+ def initialize(text)
8
+ @text = text
9
+ end
10
+
11
+ # Checks that an error message was outputted about the box
12
+ # being added being invalid.
13
+ def box_invalid
14
+ @text =~ /^The box file you're attempting to add is invalid./
15
+ end
16
+
17
+ # Checks that an error message was outputted about the path
18
+ # not existing to the box.
19
+ def box_path_doesnt_exist
20
+ @text =~ /^The specified path to a file doesn't exist.$/
21
+ end
22
+
23
+ # Tests that the box with given name is installed.
24
+ def box_installed(name)
25
+ @text =~ /^#{name}$/
26
+ end
27
+
28
+ # Tests that the output says there are no installed boxes.
29
+ def no_boxes
30
+ @text =~ /There are no installed boxes!/
31
+ end
32
+
33
+ # Tests that the output says there is no Vagrantfile, and as such
34
+ # can't do whatever we requested Vagrant to do.
35
+ def no_vagrantfile
36
+ @text =~ /^No Vagrant environment detected/
37
+ end
38
+
39
+ # Tests that the output contains a specific Vagrant version.
40
+ def version(version)
41
+ @text =~ /^Vagrant version #{version}$/
42
+ end
43
+
44
+ # This checks that the VM with the given `vm_name` has the
45
+ # status of `status`.
46
+ def status(vm_name, status)
47
+ @text =~ /^#{vm_name}\s+#{status}$/
48
+ end
49
+
50
+ # This checks that an error message that the VM must be created
51
+ # is shown.
52
+ def error_vm_must_be_created
53
+ @text =~ /^VM must be created/
54
+ end
55
+
56
+ # This checks that the warning that the VM is not created is emitted.
57
+ def vm_not_created_warning
58
+ @text =~ /VM not created. Moving on...$/
59
+ end
60
+
61
+ # This checks that the VM is destroyed.
62
+ def vm_destroyed
63
+ @text =~ /Destroying VM and associated drives...$/
64
+ end
65
+
66
+ # This checks that the "up" output properly contains text showing that
67
+ # it is downloading the box during the up process.
68
+ def up_fetching_box(name, vm=DEFAULT_VM)
69
+ @text =~ /^\[#{vm}\] Box #{name} was not found. Fetching box from specified URL...$/
70
+ end
71
+
72
+ # Check that the output shows that the VM was shut down gracefully
73
+ def vm_halt_graceful
74
+ @text =~ /Attempting graceful shutdown of/
75
+ end
76
+
77
+ # Output shows a forceful VM shutdown.
78
+ def vm_halt_force
79
+ @text =~ /Forcing shutdown of VM...$/
80
+ end
81
+
82
+ # Output shows the VM is in the process of suspending
83
+ def vm_suspending
84
+ @text =~ /Saving VM state and suspending execution...$/
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,65 @@
1
+ require "support/isolated_environment"
2
+ require "support/output"
3
+ require "support/virtualbox"
4
+
5
+ shared_context "acceptance" do
6
+ # Setup variables for the loggers of this test. These can be used to
7
+ # create more verbose logs for tests which can be useful in the case
8
+ # that a test fails.
9
+ let(:logger_name) { "logger" }
10
+ let(:logger) { Log4r::Logger.new("acceptance::#{logger_name}") }
11
+
12
+ # This is the global configuration given by the acceptance test
13
+ # configurations.
14
+ let(:config) { $acceptance_options }
15
+
16
+ # Setup the environment so that we have an isolated area
17
+ # to run Vagrant. We do some configuration here as well in order
18
+ # to replace "vagrant" with the proper path to Vagrant as well
19
+ # as tell the isolated environment about custom environmental
20
+ # variables to pass in.
21
+ let!(:environment) do
22
+ apps = { "vagrant" => config.vagrant_path }
23
+ Acceptance::IsolatedEnvironment.new(apps, config.env)
24
+ end
25
+
26
+ before(:each) do
27
+ # Wait for VBoxSVC to disappear, since each test requires its
28
+ # own isolated VirtualBox process.
29
+ Acceptance::VirtualBox.wait_for_vboxsvc
30
+ end
31
+
32
+ after(:each) do
33
+ environment.close
34
+ end
35
+
36
+ # Executes the given command in the context of the isolated environment.
37
+ #
38
+ # @return [Object]
39
+ def execute(*args, &block)
40
+ environment.execute(*args, &block)
41
+ end
42
+
43
+ # This method is an assertion helper for asserting that a process
44
+ # succeeds. It is a wrapper around `execute` that asserts that the
45
+ # exit status was successful.
46
+ def assert_execute(*args, &block)
47
+ result = execute(*args, &block)
48
+ assert(result.success?, "expected '#{args.join(" ")}' to succeed")
49
+ result
50
+ end
51
+
52
+ # This can be added to the beginning of a test to verify that the
53
+ # box with the given name is available to a test. This will raise
54
+ # an exception if the box is not found.
55
+ def require_box(name)
56
+ if !File.exist?(box_path(name))
57
+ raise ArgumentError, "The tests should have a '#{name}' box."
58
+ end
59
+ end
60
+
61
+ # This is used to get the path to a box of a specific name.
62
+ def box_path(name)
63
+ File.join(config.box_directory, "#{name}.box")
64
+ end
65
+ end
@@ -0,0 +1,33 @@
1
+ # This is a shared example that tests that a command requires a
2
+ # Vagrant environment to run properly. The exact command to run
3
+ # should be given as a parameter to the shared examples.
4
+ shared_examples "a command that requires a Vagrantfile" do |*args|
5
+ let(:command) do
6
+ raise ArgumentError, "A command must be set for the shared example." if args.empty?
7
+ args[0]
8
+ end
9
+
10
+ it "fails if no Vagrantfile is found" do
11
+ result = execute(*command)
12
+ result.should_not be_success
13
+ result.stdout.should match_output(:no_vagrantfile)
14
+ end
15
+ end
16
+
17
+ # This is a shared example that tests that the command requires a
18
+ # virtual machine to be created, and additionally to be in one of
19
+ # many states.
20
+ shared_examples "a command that requires a virtual machine" do |*args|
21
+ let(:command) do
22
+ raise ArgumentError, "A command must be set for the shared example." if args.empty?
23
+ args[0]
24
+ end
25
+
26
+ it "fails if the virtual machine is not created" do
27
+ assert_execute("vagrant", "init")
28
+
29
+ result = execute(*command)
30
+ result.should_not be_success
31
+ result.stdout.should match_output(:error_vm_must_be_created)
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ require 'fileutils'
2
+ require 'tempfile'
3
+
4
+ # This class provides an easy way of creating a temporary
5
+ # directory and having it removed when the application exits.
6
+ #
7
+ # TODO: This class doesn't currently delete the temporary
8
+ # directory on exit.
9
+ class Tempdir
10
+ attr_reader :path
11
+
12
+ def initialize(basename="vagrant")
13
+ @path = nil
14
+
15
+ # Loop and attempt to create a temporary directory until
16
+ # it succeeds.
17
+ while @path.nil?
18
+ file = Tempfile.new(basename)
19
+ @path = file.path
20
+ file.unlink
21
+
22
+ begin
23
+ Dir.mkdir(@path)
24
+ rescue
25
+ @path = nil
26
+ end
27
+ end
28
+ end
29
+
30
+ # This deletes the temporary directory.
31
+ def unlink
32
+ FileUtils.rm_rf(@path)
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ require 'sys/proctable'
2
+
3
+ module Acceptance
4
+ module VirtualBox
5
+ extend self
6
+
7
+ # This method will wait for the "VBoxSVC" process to end. This will
8
+ # block during that time period. The reason for this is because only
9
+ # one "VBoxSVC" can run per user and manages all state within VirtualBox.
10
+ # Before you can run VirtualBox with a custom home directory, you must
11
+ # wait for this VBoxSVC process to die.
12
+ def wait_for_vboxsvc
13
+ time_passed = 0
14
+ while find_vboxsvc
15
+ if time_passed > 5
16
+ raise Exception, "VBoxSVC process is not going away."
17
+ end
18
+
19
+ sleep 1
20
+ time_passed += 1
21
+ end
22
+ end
23
+
24
+ # This method finds the VBoxSVC process and returns information about it.
25
+ # This will return "nil" if VBoxSVC is not found.
26
+ def find_vboxsvc
27
+ Sys::ProcTable.ps do |process|
28
+ if process.comm == "VBoxSVC"
29
+ return process
30
+ end
31
+ end
32
+
33
+ nil
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,56 @@
1
+ require File.expand_path("../base", __FILE__)
2
+ require "support/shared/command_examples"
3
+
4
+ describe "vagrant suspend" do
5
+ include_context "acceptance"
6
+ it_behaves_like "a command that requires a Vagrantfile", ["vagrant", "suspend"]
7
+
8
+ it "succeeds and ignores if the VM is not created" do
9
+ require_box("default")
10
+
11
+ assert_execute("vagrant", "box", "add", "base", box_path("default"))
12
+ assert_execute("vagrant", "init")
13
+
14
+ result = assert_execute("vagrant", "suspend")
15
+ result.stdout.should match_output(:vm_not_created_warning)
16
+ end
17
+
18
+ it "is able to suspend a running virtual machine" do
19
+ require_box("default")
20
+
21
+ assert_execute("vagrant", "box", "add", "base", box_path("default"))
22
+ assert_execute("vagrant", "init")
23
+ assert_execute("vagrant", "up")
24
+
25
+ # Suspend the VM and assert that it worked properly (seemingly)
26
+ result = assert_execute("vagrant", "suspend")
27
+ result.stdout.should match_output(:vm_suspending)
28
+
29
+ # Assert that the VM is no longer running
30
+ result = assert_execute("vagrant", "status")
31
+ result.stdout.should match_output(:status, "default", "saved")
32
+ end
33
+
34
+ # These tests are parameterized since both "vagrant resume" and
35
+ # "vagrant up" should achieve the same result.
36
+ ["resume", "up"].each do |command|
37
+ it "is able to resume after the machine has been suspended using #{command}" do
38
+ require_box("default")
39
+
40
+ assert_execute("vagrant", "box", "add", "base", box_path("default"))
41
+ assert_execute("vagrant", "init")
42
+ assert_execute("vagrant", "up")
43
+ assert_execute("vagrant", "suspend")
44
+
45
+ # Assert that the VM is no longer running
46
+ result = assert_execute("vagrant", "status")
47
+ result.stdout.should match_output(:status, "default", "saved")
48
+
49
+ assert_execute("vagrant", command)
50
+
51
+ # Assert that the VM is once again running
52
+ result = assert_execute("vagrant", "status")
53
+ result.stdout.should match_output(:status, "default", "running")
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,58 @@
1
+ require File.expand_path("../base", __FILE__)
2
+ require "support/shared/command_examples"
3
+
4
+ describe "vagrant up", "basics" do
5
+ include_context "acceptance"
6
+ it_behaves_like "a command that requires a Vagrantfile", ["vagrant", "up"]
7
+
8
+ # This creates an initial environment that is ready for a "vagrant up"
9
+ def initialize_valid_environment
10
+ require_box("default")
11
+
12
+ assert_execute("vagrant", "box", "add", "base", box_path("default"))
13
+ assert_execute("vagrant", "init")
14
+ end
15
+
16
+ it "brings up a running virtual machine" do
17
+ initialize_valid_environment
18
+
19
+ assert_execute("vagrant", "up")
20
+ result = assert_execute("vagrant", "status")
21
+ result.stdout.should match_output(:status, "default", "running")
22
+ end
23
+
24
+ it "is able to run if Vagrantfile is in a parent directory" do
25
+ initialize_valid_environment
26
+
27
+ # Create a subdirectory in the working directory and use
28
+ # that as the CWD for `vagrant up` and verify it still works
29
+ foodir = environment.workdir.join("foo")
30
+ foodir.mkdir
31
+ assert_execute("vagrant", "up", :chdir => foodir.to_s)
32
+ end
33
+
34
+ it "should have a '/vagrant' shared folder" do
35
+ initialize_valid_environment
36
+
37
+ # This is the file that will be created from the VM,
38
+ # but should then exist on the host machine
39
+ foofile = environment.workdir.join("foo")
40
+
41
+ assert_execute("vagrant", "up")
42
+ foofile.exist?.should_not be,
43
+ "'foo' should not exist yet."
44
+
45
+ assert_execute("vagrant", "ssh", "-c", "touch /vagrant/foo")
46
+ foofile.exist?.should be, "'foo' should exist since it was touched in the shared folder"
47
+ end
48
+
49
+ =begin
50
+
51
+ TODO:
52
+
53
+ should "destroy a running virtual machine"
54
+ should "save then restore a virtual machine using `vagrant up`"
55
+ should "halt then start a virtual machine using `vagrant up`"
56
+
57
+ =end
58
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path("../base", __FILE__)
2
+ require "support/shared/command_examples"
3
+
4
+ describe "vagrant up", "with a box URL set" do
5
+ include_context "acceptance"
6
+
7
+ it "downloads and brings up the VM if the box doesn't exist" do
8
+ require_box("default")
9
+
10
+ assert_execute("vagrant", "init", "base", box_path("default"))
11
+ result = assert_execute("vagrant", "up")
12
+ result.stdout.should match_output(:up_fetching_box, "base")
13
+ end
14
+
15
+ it "downloads the file only once and works if shared by multiple VMs", :issue => "GH-564" do
16
+ require_box("default")
17
+
18
+ environment.workdir.join("Vagrantfile").open("w+") do |f|
19
+ f.puts(<<-VFILE)
20
+ Vagrant::Config.run do |config|
21
+ config.vm.define :machine1 do |vm_config|
22
+ vm_config.vm.box = "base"
23
+ vm_config.vm.box_url = "#{box_path("default")}"
24
+ end
25
+
26
+ config.vm.define :machine2 do |vm_config|
27
+ vm_config.vm.box = "base"
28
+ vm_config.vm.box_url = "#{box_path("default")}"
29
+ end
30
+ end
31
+ VFILE
32
+ end
33
+
34
+ # Bring up the environment, which should work. `machine1` should download
35
+ # the box while `machine2` doesn't.
36
+ result = assert_execute("vagrant", "up")
37
+ result.stdout.should match_output(:up_fetching_box, "base", "machine1")
38
+ result.stdout.should_not match_output(:up_fetching_box, "base", "machine2")
39
+ end
40
+ end
@@ -0,0 +1,47 @@
1
+ require File.expand_path("../base", __FILE__)
2
+ require "support/matchers/have_color"
3
+
4
+ describe "vagrant and color output" do
5
+ include_context "acceptance"
6
+
7
+ # This is a check to see if the `expect` program is installed on this
8
+ # computer. Some tests require this and if this doesn't exist then the
9
+ # test itself will be skipped.
10
+ def self.has_expect?
11
+ `which expect`
12
+ $?.success?
13
+ end
14
+
15
+ it "outputs color if there is a TTY", :if => has_expect? do
16
+ environment.workdir.join("color.exp").open("w+") do |f|
17
+ f.puts(<<-SCRIPT)
18
+ spawn #{environment.replace_command("vagrant")} status
19
+ expect default {}
20
+ SCRIPT
21
+ end
22
+
23
+ result = execute("expect", "color.exp")
24
+ result.stdout.should have_color
25
+ end
26
+
27
+ it "doesn't output color if there is a TTY but --no-color is present", :if => has_expect? do
28
+ environment.workdir.join("color.exp").open("w+") do |f|
29
+ f.puts(<<-SCRIPT)
30
+ spawn #{environment.replace_command("vagrant")} status --no-color
31
+ expect default {}
32
+ SCRIPT
33
+ end
34
+
35
+ result = execute("expect", "color.exp")
36
+ result.stdout.should_not have_color
37
+ end
38
+
39
+ it "doesn't output color in the absense of a TTY" do
40
+ # This should always output an error, which on a TTY would
41
+ # output color. We check that this doesn't output color.
42
+ # If `vagrant status` itself is broken, another acceptance test
43
+ # should catch that. We just assume it works here.
44
+ result = execute("vagrant", "status")
45
+ result.stdout.should_not have_color
46
+ end
47
+ end