vaguerent/test/acceptance/vagrant_test.rb
Mitchell Hashimoto 87bc6ec63f RSpec is coming in for acceptance tests. More details follow...
RSpec was chosen to be used for acceptance tests for many reasons:

* The tests are actually much cleaner now. It is clearer to see what
  is being tested, and what is being used for setup.
* Matcher transition will be coming soon. This will really clean up
  a lot of the "assert" boilerplate all over. There was a lot of repetition
  in this area.
* Shared examples will help greatly for testing common error cases
  for many commands.
* The test runner for RSpec is simply much better. Being able to specify
  the exact test to run by line, for example, is a great help.
2011-11-06 23:47:23 -08:00

54 lines
1.7 KiB
Ruby

require File.expand_path("../base", __FILE__)
describe "vagrant and color output" do
include_context "acceptance"
# This is a check to see if the `expect` program is installed on this
# computer. Some tests require this and if this doesn't exist then the
# test itself will be skipped.
def self.has_expect?
`which expect`
$?.success?
end
# This is a helper to check for a color in some text.
# This will return `nil` if no color is found, any other
# truthy value otherwise.
def has_color?(text)
text.index("\e[31m")
end
it "outputs color if there is a TTY", :if => has_expect? do
environment.workdir.join("color.exp").open("w+") do |f|
f.puts(<<-SCRIPT)
spawn #{environment.replace_command("vagrant")} status
expect default {}
SCRIPT
end
result = execute("expect", "color.exp")
assert(has_color?(result.stdout), "output should contain color")
end
it "doesn't output color if there is a TTY but --no-color is present", :if => has_expect? do
environment.workdir.join("color.exp").open("w+") do |f|
f.puts(<<-SCRIPT)
spawn #{environment.replace_command("vagrant")} status --no-color
expect default {}
SCRIPT
end
result = execute("expect", "color.exp")
assert(!has_color?(result.stdout), "output should not contain color")
end
it "doesn't output color in the absense of a TTY" do
# This should always output an error, which on a TTY would
# output color. We check that this doesn't output color.
# If `vagrant status` itself is broken, another acceptance test
# should catch that. We just assume it works here.
result = execute("vagrant", "status")
assert(!has_color?(result.stdout), "output should not contain color")
end
end