Sha256: 813979641e57dc23971fda47bd948cec1dadc5ecf2ae737642444a1bd4cada18

Contents?: true

Size: 1.44 KB

Versions: 62

Compression:

Stored size: 1.44 KB

Contents

require "fileutils"
require "pathname"

require "log4r"

require "support/tempdir"

# This class manages an isolated environment for Vagrant to
# run in. It creates a temporary directory to act as the
# working directory as well as sets a custom home directory.
#
# This class also provides various helpers to create Vagrantfiles,
# boxes, etc.
class IsolatedEnvironment
  attr_reader :homedir
  attr_reader :workdir

  # Initializes an isolated environment. You can pass in some
  # options here to configure runing custom applications in place
  # of others as well as specifying environmental variables.
  #
  # @param [Hash] apps A mapping of application name (such as "vagrant")
  #   to an alternate full path to the binary to run.
  # @param [Hash] env Additional environmental variables to inject
  #   into the execution environments.
  def initialize
    @logger = Log4r::Logger.new("test::isolated_environment")

    # Create a temporary directory for our work
    @tempdir = Tempdir.new("vagrant")
    @logger.info("Initialize isolated environment: #{@tempdir.path}")

    # Setup the home and working directories
    @homedir = Pathname.new(File.join(@tempdir.path, "home"))
    @workdir = Pathname.new(File.join(@tempdir.path, "work"))

    @homedir.mkdir
    @workdir.mkdir
  end

  # This closes the environment by cleaning it up.
  def close
    @logger.info("Removing isolated environment: #{@tempdir.path}")
    FileUtils.rm_rf(@tempdir.path)
  end
end

Version data entries

62 entries across 62 versions & 12 rubygems

Version Path
tamtam-vagrant-reload-1.1.3 vendor/cache/vagrant-0ac2a8738841/test/support/isolated_environment.rb
tamtam-vagrant-reload-1.1.2 vendor/cache/vagrant-0ac2a8738841/test/support/isolated_environment.rb
tamtam-vagrant-reload-1.1.1 vendor/cache/vagrant-0ac2a8738841/test/support/isolated_environment.rb
tamtam-vagrant-reload-1.1 vendor/cache/vagrant-0ac2a8738841/test/support/isolated_environment.rb
bmhatfield-vagrant-1.0.10 test/support/isolated_environment.rb
vagrant-parallels-0.2.1 test/support/isolated_environment.rb
vagrant-parallels-0.2.0 test/support/isolated_environment.rb
vagrant-parallels-0.1.3 test/support/isolated_environment.rb
bmhatfield-vagrant-1.0.9 test/support/isolated_environment.rb
tnargav-1.3.6 test/support/isolated_environment.rb
tnargav-1.3.3 test/support/isolated_environment.rb
bmhatfield-vagrant-1.0.8 test/support/isolated_environment.rb
vagrant-shell-0.2.9 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/test/support/isolated_environment.rb
tnargav-1.2.3 test/support/isolated_environment.rb
vagrant-shell-0.2.8 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/test/support/isolated_environment.rb
bmhatfield-vagrant-1.0.7 test/support/isolated_environment.rb
vagrant-shell-0.2.6 vendor/bundle/gems/tnargav-1.2.2/test/support/isolated_environment.rb
vagrant-shell-0.2.5 vendor/bundle/gems/tnargav-1.2.2/test/support/isolated_environment.rb
tnargav-1.2.2 test/support/isolated_environment.rb
vagrantup-1.1.3 test/support/isolated_environment.rb