diff --git a/test/acceptance/base.rb b/test/acceptance/base.rb index 655fd6f09..01a5f329c 100644 --- a/test/acceptance/base.rb +++ b/test/acceptance/base.rb @@ -3,16 +3,14 @@ require "rspec/autorun" require "log4r" -# Add this directory to the load path, since it just makes -# everything else so much easier. -$:.unshift File.expand_path("../", __FILE__) +# Add the test directory to the load path $:.unshift File.expand_path("../../", __FILE__) # Load in the supporting files for our tests -require "support/shared/base_context" -require "support/config" -require "support/virtualbox" -require "support/matchers/match_output" +require "acceptance/support/shared/base_context" +require "acceptance/support/config" +require "acceptance/support/virtualbox" +require "acceptance/support/matchers/match_output" # Do not buffer output $stdout.sync = true diff --git a/test/acceptance/destroy_test.rb b/test/acceptance/destroy_test.rb index 7b8da2cb2..194f53f00 100644 --- a/test/acceptance/destroy_test.rb +++ b/test/acceptance/destroy_test.rb @@ -1,5 +1,5 @@ require File.expand_path("../base", __FILE__) -require "support/shared/command_examples" +require "acceptance/support/shared/command_examples" describe "vagrant destroy" do include_context "acceptance" diff --git a/test/acceptance/halt_test.rb b/test/acceptance/halt_test.rb index 0604767ea..6bae59304 100644 --- a/test/acceptance/halt_test.rb +++ b/test/acceptance/halt_test.rb @@ -1,5 +1,5 @@ require File.expand_path("../base", __FILE__) -require "support/shared/command_examples" +require "acceptance/support/shared/command_examples" describe "vagrant halt" do include_context "acceptance" diff --git a/test/acceptance/resume_test.rb b/test/acceptance/resume_test.rb index d1764dd06..6abe14808 100644 --- a/test/acceptance/resume_test.rb +++ b/test/acceptance/resume_test.rb @@ -1,5 +1,5 @@ require File.expand_path("../base", __FILE__) -require "support/shared/command_examples" +require "acceptance/support/shared/command_examples" describe "vagrant resume" do include_context "acceptance" diff --git a/test/acceptance/ssh_test.rb b/test/acceptance/ssh_test.rb index 8e9ae295f..5be5ba85f 100644 --- a/test/acceptance/ssh_test.rb +++ b/test/acceptance/ssh_test.rb @@ -1,5 +1,5 @@ require File.expand_path("../base", __FILE__) -require "support/shared/command_examples" +require "acceptance/support/shared/command_examples" describe "vagrant ssh" do include_context "acceptance" diff --git a/test/acceptance/support/isolated_environment.rb b/test/acceptance/support/isolated_environment.rb index 9540e6fba..c71623b44 100644 --- a/test/acceptance/support/isolated_environment.rb +++ b/test/acceptance/support/isolated_environment.rb @@ -1,45 +1,22 @@ -require "fileutils" -require "pathname" - require "log4r" require "childprocess" -require "support/tempdir" -require "support/virtualbox" +require "acceptance/support/virtualbox" +require "support/isolated_environment" module Acceptance # 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. - 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. + class IsolatedEnvironment < ::IsolatedEnvironment def initialize(apps=nil, env=nil) + super() + @logger = Log4r::Logger.new("acceptance::isolated_environment") @apps = apps || {} @env = env || {} - # 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 - # Set the home directory and virtualbox home directory environmental # variables so that Vagrant and VirtualBox see the proper paths here. @env["HOME"] = @homedir.to_s @@ -149,9 +126,8 @@ module Acceptance # environment. delete_virtual_machines if VirtualBox.find_vboxsvc - # Delete the temporary directory - @logger.info("Removing isolated environment: #{@tempdir.path}") - FileUtils.rm_rf(@tempdir.path) + # Let the parent handle cleaning up + super end def delete_virtual_machines diff --git a/test/acceptance/support/matchers/match_output.rb b/test/acceptance/support/matchers/match_output.rb index 5a64e93d8..c58c6f9d3 100644 --- a/test/acceptance/support/matchers/match_output.rb +++ b/test/acceptance/support/matchers/match_output.rb @@ -1,4 +1,4 @@ -require "support/output" +require "acceptance/support/output" # This creates a matcher that is used to match against certain # Vagrant output. Vagrant output is not what is being tested, diff --git a/test/acceptance/support/shared/base_context.rb b/test/acceptance/support/shared/base_context.rb index 905b0cd25..28753a8b7 100644 --- a/test/acceptance/support/shared/base_context.rb +++ b/test/acceptance/support/shared/base_context.rb @@ -1,6 +1,6 @@ -require "support/isolated_environment" -require "support/output" -require "support/virtualbox" +require "acceptance/support/isolated_environment" +require "acceptance/support/output" +require "acceptance/support/virtualbox" shared_context "acceptance" do # Setup variables for the loggers of this test. These can be used to diff --git a/test/acceptance/suspend_test.rb b/test/acceptance/suspend_test.rb index 84f645bc2..1f60ead40 100644 --- a/test/acceptance/suspend_test.rb +++ b/test/acceptance/suspend_test.rb @@ -1,5 +1,5 @@ require File.expand_path("../base", __FILE__) -require "support/shared/command_examples" +require "acceptance/support/shared/command_examples" describe "vagrant suspend" do include_context "acceptance" diff --git a/test/acceptance/up_basic_test.rb b/test/acceptance/up_basic_test.rb index 3f1d6524e..b06757a90 100644 --- a/test/acceptance/up_basic_test.rb +++ b/test/acceptance/up_basic_test.rb @@ -1,5 +1,5 @@ require File.expand_path("../base", __FILE__) -require "support/shared/command_examples" +require "acceptance/support/shared/command_examples" describe "vagrant up", "basics" do include_context "acceptance" diff --git a/test/acceptance/up_with_box_url.rb b/test/acceptance/up_with_box_url.rb index 493e8cf6f..5c77102b1 100644 --- a/test/acceptance/up_with_box_url.rb +++ b/test/acceptance/up_with_box_url.rb @@ -1,5 +1,5 @@ require File.expand_path("../base", __FILE__) -require "support/shared/command_examples" +require "acceptance/support/shared/command_examples" describe "vagrant up", "with a box URL set" do include_context "acceptance" diff --git a/test/acceptance/vagrant_test.rb b/test/acceptance/vagrant_test.rb index cc99e49da..399ef3765 100644 --- a/test/acceptance/vagrant_test.rb +++ b/test/acceptance/vagrant_test.rb @@ -1,5 +1,5 @@ require File.expand_path("../base", __FILE__) -require "support/matchers/have_color" +require "acceptance/support/matchers/have_color" describe "vagrant and color output" do include_context "acceptance" diff --git a/test/support/isolated_environment.rb b/test/support/isolated_environment.rb new file mode 100644 index 000000000..6e95c061f --- /dev/null +++ b/test/support/isolated_environment.rb @@ -0,0 +1,46 @@ +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("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 diff --git a/test/unit/base.rb b/test/unit/base.rb index bd0cff1c5..a6d85d310 100644 --- a/test/unit/base.rb +++ b/test/unit/base.rb @@ -5,13 +5,11 @@ require "rspec/autorun" # classes to test. require "vagrant" -# Add this directory to the load path, since it just makes -# everything else easier. -$:.unshift File.expand_path("../", __FILE__) +# Add the test directory to the load path $:.unshift File.expand_path("../../", __FILE__) # Load in helpers -require "support/shared/base_context" +require "unit/support/shared/base_context" # Do not buffer output $stdout.sync = true diff --git a/test/unit/support/isolated_environment.rb b/test/unit/support/isolated_environment.rb index 7b5d2366a..8320d60c5 100644 --- a/test/unit/support/isolated_environment.rb +++ b/test/unit/support/isolated_environment.rb @@ -3,42 +3,10 @@ require "pathname" require "log4r" -require "support/tempdir" +require "support/isolated_environment" module Unit - # 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(apps=nil, env=nil) - @logger = Log4r::Logger.new("unit::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 - + class IsolatedEnvironment < ::IsolatedEnvironment def create_vagrant_env Vagrant::Environment.new(:cwd => @workdir, :home_path => @homedir) end diff --git a/test/unit/support/shared/base_context.rb b/test/unit/support/shared/base_context.rb index 5b619848e..526cfaf73 100644 --- a/test/unit/support/shared/base_context.rb +++ b/test/unit/support/shared/base_context.rb @@ -1,6 +1,6 @@ require "tempfile" -require "support/isolated_environment" +require "unit/support/isolated_environment" shared_context "unit" do # This creates an isolated environment so that Vagrant doesn't