2011-12-04 03:05:50 +00:00
|
|
|
require "fileutils"
|
|
|
|
require "pathname"
|
|
|
|
|
|
|
|
require "log4r"
|
|
|
|
|
2011-12-11 23:53:11 +00:00
|
|
|
require "support/isolated_environment"
|
2011-12-04 03:05:50 +00:00
|
|
|
|
|
|
|
module Unit
|
2011-12-11 23:53:11 +00:00
|
|
|
class IsolatedEnvironment < ::IsolatedEnvironment
|
2012-01-09 07:04:23 +00:00
|
|
|
def create_vagrant_env(options=nil)
|
|
|
|
options = {
|
|
|
|
:cwd => @workdir,
|
|
|
|
:home_path => @homedir
|
|
|
|
}.merge(options || {})
|
|
|
|
|
|
|
|
Vagrant::Environment.new(options)
|
2011-12-04 03:05:50 +00:00
|
|
|
end
|
|
|
|
|
2011-12-04 03:15:53 +00:00
|
|
|
def vagrantfile(contents, root=nil)
|
|
|
|
root ||= @workdir
|
|
|
|
root.join("Vagrantfile").open("w+") do |f|
|
2011-12-04 03:05:50 +00:00
|
|
|
f.write(contents)
|
|
|
|
end
|
|
|
|
end
|
2011-12-04 03:15:53 +00:00
|
|
|
|
2011-12-04 19:39:44 +00:00
|
|
|
def box(name, vagrantfile_contents="")
|
2011-12-04 03:15:53 +00:00
|
|
|
box_dir = boxes_dir.join(name)
|
2011-12-04 19:39:44 +00:00
|
|
|
box_dir.mkpath
|
2011-12-04 03:15:53 +00:00
|
|
|
vagrantfile(vagrantfile_contents, box_dir)
|
2012-01-09 07:04:23 +00:00
|
|
|
box_dir
|
2011-12-04 03:15:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def boxes_dir
|
|
|
|
dir = @homedir.join("boxes")
|
2011-12-04 19:39:44 +00:00
|
|
|
dir.mkpath
|
2011-12-04 03:15:53 +00:00
|
|
|
dir
|
|
|
|
end
|
2011-12-04 03:05:50 +00:00
|
|
|
end
|
|
|
|
end
|