2011-11-04 05:12:51 +00:00
|
|
|
require "rubygems"
|
2011-11-03 04:09:38 +00:00
|
|
|
require "contest"
|
|
|
|
require "log4r"
|
|
|
|
|
2011-11-07 03:20:14 +00:00
|
|
|
require File.expand_path("../helpers/config", __FILE__)
|
2011-11-05 21:59:17 +00:00
|
|
|
require File.expand_path("../helpers/isolated_environment", __FILE__)
|
2011-11-07 03:20:14 +00:00
|
|
|
require File.expand_path("../helpers/output", __FILE__)
|
|
|
|
require File.expand_path("../helpers/virtualbox", __FILE__)
|
2011-11-03 04:09:38 +00:00
|
|
|
|
2011-11-07 03:21:29 +00:00
|
|
|
# If VirtualBox is currently running, fail.
|
|
|
|
if Acceptance::VirtualBox.find_vboxsvc
|
|
|
|
$stderr.puts "VirtualBox must be closed and remain closed for the duration of the tests."
|
|
|
|
abort
|
|
|
|
end
|
|
|
|
|
2011-11-03 04:09:38 +00:00
|
|
|
# Enable logging if requested
|
|
|
|
if ENV["ACCEPTANCE_LOGGING"]
|
|
|
|
logger = Log4r::Logger.new("acceptance")
|
|
|
|
logger.outputters = Log4r::Outputter.stdout
|
|
|
|
logger.level = Log4r.const_get(ENV["ACCEPTANCE_LOGGING"].upcase)
|
|
|
|
logger = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
# Parse the command line options and load the global configuration.
|
|
|
|
if !ENV.has_key?("ACCEPTANCE_CONFIG")
|
|
|
|
$stderr.puts "A configuration file must be passed into the acceptance test."
|
2011-11-07 03:21:29 +00:00
|
|
|
abort
|
2011-11-03 04:09:38 +00:00
|
|
|
elsif !File.file?(ENV["ACCEPTANCE_CONFIG"])
|
|
|
|
$stderr.puts "The configuration file must exist."
|
2011-11-07 03:21:29 +00:00
|
|
|
abort
|
2011-11-03 04:09:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
$acceptance_options = Acceptance::Config.new(ENV["ACCEPTANCE_CONFIG"])
|
|
|
|
|
|
|
|
class AcceptanceTest < Test::Unit::TestCase
|
|
|
|
# This method is a shortcut to give access to the global configuration
|
|
|
|
# setup by the acceptance tests.
|
|
|
|
def config
|
|
|
|
$acceptance_options
|
|
|
|
end
|
|
|
|
|
|
|
|
# Executes the given command in the isolated environment. This
|
|
|
|
# is just a shortcut to IsolatedEnvironment#execute.
|
|
|
|
#
|
|
|
|
# @return [Object]
|
2011-11-06 21:30:49 +00:00
|
|
|
def execute(*args, &block)
|
|
|
|
@environment.execute(*args, &block)
|
2011-11-03 04:09:38 +00:00
|
|
|
end
|
|
|
|
|
2011-11-05 21:59:17 +00:00
|
|
|
# This is a shortcut method to instantiate an Output matcher.
|
|
|
|
#
|
|
|
|
# @return [Acceptance::Output]
|
|
|
|
def output(text)
|
|
|
|
Acceptance::Output.new(text)
|
|
|
|
end
|
|
|
|
|
2011-11-06 21:30:49 +00:00
|
|
|
# This method is an assertion helper for asserting that a process
|
|
|
|
# succeeds. It is a wrapper around `execute` that asserts that the
|
|
|
|
# exit status was successful.
|
|
|
|
def assert_execute(*args, &block)
|
|
|
|
result = execute(*args, &block)
|
|
|
|
assert(result.success?, "expected '#{args.join(" ")}' to succeed")
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2011-11-03 04:09:38 +00:00
|
|
|
setup do
|
2011-11-07 03:20:14 +00:00
|
|
|
# Wait for VBoxSVC to disappear
|
|
|
|
Acceptance::VirtualBox.wait_for_vboxsvc
|
|
|
|
|
2011-11-03 04:09:38 +00:00
|
|
|
# Setup the environment so that we have an isolated area
|
|
|
|
# to run Vagrant. We do some configuration here as well in order
|
|
|
|
# to replace "vagrant" with the proper path to Vagrant as well
|
|
|
|
# as tell the isolated environment about custom environmental
|
|
|
|
# variables to pass in.
|
|
|
|
apps = { "vagrant" => config.vagrant_path }
|
|
|
|
@environment = Acceptance::IsolatedEnvironment.new(apps, config.env)
|
2011-11-04 06:07:51 +00:00
|
|
|
|
|
|
|
# Setup a logger for this test, since tests often log to assist
|
|
|
|
# with the debugging process in case of failure.
|
|
|
|
@logger = Log4r::Logger.new("acceptance::#{self.class.name.downcase.gsub("test", "")}")
|
2011-11-03 04:09:38 +00:00
|
|
|
end
|
2011-11-03 04:41:41 +00:00
|
|
|
|
|
|
|
teardown do
|
2011-11-07 03:20:14 +00:00
|
|
|
@environment.close if @environment
|
2011-11-03 04:41:41 +00:00
|
|
|
end
|
2011-11-03 04:09:38 +00:00
|
|
|
end
|