2011-12-04 01:12:48 +00:00
|
|
|
require "tempfile"
|
|
|
|
|
2011-12-11 23:53:11 +00:00
|
|
|
require "unit/support/isolated_environment"
|
2011-12-04 03:05:50 +00:00
|
|
|
|
2011-12-04 01:12:48 +00:00
|
|
|
shared_context "unit" do
|
2011-12-04 03:05:50 +00:00
|
|
|
# This creates an isolated environment so that Vagrant doesn't
|
|
|
|
# muck around with your real system during unit tests.
|
|
|
|
#
|
|
|
|
# The returned isolated environment has a variety of helper
|
|
|
|
# methods on it to easily create files, Vagrantfiles, boxes,
|
|
|
|
# etc.
|
|
|
|
def isolated_environment
|
|
|
|
env = Unit::IsolatedEnvironment.new
|
|
|
|
yield env if block_given?
|
|
|
|
env
|
|
|
|
end
|
|
|
|
|
2011-12-04 01:12:48 +00:00
|
|
|
# This helper creates a temporary file and returns a Pathname
|
|
|
|
# object pointed to it.
|
|
|
|
def temporary_file(contents=nil)
|
|
|
|
f = Tempfile.new("vagrant-unit")
|
|
|
|
|
|
|
|
if contents
|
|
|
|
f.write(contents)
|
|
|
|
f.flush
|
|
|
|
end
|
|
|
|
|
2011-12-18 04:22:46 +00:00
|
|
|
return Pathname.new(f.path)
|
2011-12-04 01:12:48 +00:00
|
|
|
end
|
|
|
|
end
|