From 816464461535fdff15733f977c682bffdf05e5ca Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 7 Sep 2010 11:41:52 -0700 Subject: [PATCH] Converted most "mock_environment" tests to "vagrant_env" which uses real filesystem --- test/test_helper.rb | 2 +- test/vagrant/action/box/destroy_test.rb | 10 ++-------- test/vagrant/action/box/download_test.rb | 10 ++-------- test/vagrant/action/box/package_test.rb | 4 ++-- test/vagrant/action/box/unpackage_test.rb | 10 ++-------- test/vagrant/action/box/verify_test.rb | 10 ++-------- test/vagrant/action/environment_test.rb | 2 +- test/vagrant/action_test.rb | 2 +- test/vagrant/box_test.rb | 4 ++-- test/vagrant/cli_test.rb | 2 +- test/vagrant/command/base_test.rb | 2 +- test/vagrant/command/group_base_test.rb | 2 +- test/vagrant/command/helpers_test.rb | 4 ++-- test/vagrant/config/ssh_test.rb | 3 +-- test/vagrant/config/vm_test.rb | 2 +- test/vagrant/config_test.rb | 2 +- test/vagrant/downloaders/base_test.rb | 2 +- test/vagrant/hosts/base_test.rb | 2 +- test/vagrant/provisioners/base_test.rb | 2 +- test/vagrant/provisioners/chef_server_test.rb | 2 +- test/vagrant/provisioners/chef_solo_test.rb | 2 +- test/vagrant/provisioners/chef_test.rb | 2 +- test/vagrant/systems/linux_test.rb | 2 +- test/vagrant/ui_test.rb | 2 +- test/vagrant/util/resource_logger_test.rb | 10 +++++----- 25 files changed, 36 insertions(+), 61 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index fe39779be..6b887e070 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -97,7 +97,7 @@ class Test::Unit::TestCase # Sets up the mocks for a VM def mock_vm(env=nil) - env ||= mock_environment + env ||= vagrant_env vm = Vagrant::VM.new vm.stubs(:env).returns(env) vm.stubs(:ssh).returns(Vagrant::SSH.new(vm.env)) diff --git a/test/vagrant/action/box/destroy_test.rb b/test/vagrant/action/box/destroy_test.rb index 86eecb006..0deb96597 100644 --- a/test/vagrant/action/box/destroy_test.rb +++ b/test/vagrant/action/box/destroy_test.rb @@ -3,14 +3,8 @@ require "test_helper" class DestroyBoxActionTest < Test::Unit::TestCase setup do @klass = Vagrant::Action::Box::Destroy - @app, @env = mock_action_data - - @vm = mock("vm") - @env["vm"] = @vm - @env["box"] = Vagrant::Box.new(mock_environment, "foo") - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) + @app, @env = action_env + @env["box"] = Vagrant::Box.new(vagrant_env, "foo") @instance = @klass.new(@app, @env) end diff --git a/test/vagrant/action/box/download_test.rb b/test/vagrant/action/box/download_test.rb index 404ce85c4..086b48630 100644 --- a/test/vagrant/action/box/download_test.rb +++ b/test/vagrant/action/box/download_test.rb @@ -3,15 +3,9 @@ require "test_helper" class DownloadBoxActionTest < Test::Unit::TestCase setup do @klass = Vagrant::Action::Box::Download - @app, @env = mock_action_data - - @vm = mock("vm") - @env["vm"] = @vm - @env["box"] = Vagrant::Box.new(mock_environment, "foo") + @app, @env = action_env + @env["box"] = Vagrant::Box.new(vagrant_env, "foo") @env["box"].uri = "http://google.com" - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) end context "initializing" do diff --git a/test/vagrant/action/box/package_test.rb b/test/vagrant/action/box/package_test.rb index d7d8c1e98..d2d51b129 100644 --- a/test/vagrant/action/box/package_test.rb +++ b/test/vagrant/action/box/package_test.rb @@ -3,8 +3,8 @@ require "test_helper" class PackageBoxActionTest < Test::Unit::TestCase setup do @klass = Vagrant::Action::Box::Package - @app, @env = mock_action_data - @env["box"] = Vagrant::Box.new(mock_environment, "foo") + @app, @env = action_env + @env["box"] = Vagrant::Box.new(vagrant_env, "foo") @instance = @klass.new(@app, @env) end diff --git a/test/vagrant/action/box/unpackage_test.rb b/test/vagrant/action/box/unpackage_test.rb index a5373eda9..7210e2653 100644 --- a/test/vagrant/action/box/unpackage_test.rb +++ b/test/vagrant/action/box/unpackage_test.rb @@ -3,14 +3,8 @@ require "test_helper" class UnpackageBoxActionTest < Test::Unit::TestCase setup do @klass = Vagrant::Action::Box::Unpackage - @app, @env = mock_action_data - - @vm = mock("vm") - @env["vm"] = @vm - @env["box"] = Vagrant::Box.new(mock_environment, "foo") - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) + @app, @env = action_env + @env["box"] = Vagrant::Box.new(vagrant_env, "foo") @instance = @klass.new(@app, @env) end diff --git a/test/vagrant/action/box/verify_test.rb b/test/vagrant/action/box/verify_test.rb index 6b7a4bd94..e478b3858 100644 --- a/test/vagrant/action/box/verify_test.rb +++ b/test/vagrant/action/box/verify_test.rb @@ -3,14 +3,8 @@ require "test_helper" class VerifyBoxActionTest < Test::Unit::TestCase setup do @klass = Vagrant::Action::Box::Verify - @app, @env = mock_action_data - - @vm = mock("vm") - @env["vm"] = @vm - @env["box"] = Vagrant::Box.new(mock_environment, "foo") - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) + @app, @env = action_env + @env["box"] = Vagrant::Box.new(vagrant_env, "foo") @instance = @klass.new(@app, @env) end diff --git a/test/vagrant/action/environment_test.rb b/test/vagrant/action/environment_test.rb index 59e5b3173..af12c8c6c 100644 --- a/test/vagrant/action/environment_test.rb +++ b/test/vagrant/action/environment_test.rb @@ -3,7 +3,7 @@ require "test_helper" class ActionEnvironmentTest < Test::Unit::TestCase setup do @klass = Vagrant::Action::Environment - @instance = @klass.new(mock_environment) + @instance = @klass.new(vagrant_env) end should "be a hash with indifferent access" do diff --git a/test/vagrant/action_test.rb b/test/vagrant/action_test.rb index cb3d9627a..a849ec6f8 100644 --- a/test/vagrant/action_test.rb +++ b/test/vagrant/action_test.rb @@ -24,7 +24,7 @@ class ActionTest < Test::Unit::TestCase context "with an instance" do setup do - @instance = @klass.new(mock_environment) + @instance = @klass.new(vagrant_env) end should "raise an exception if a nil action is given" do diff --git a/test/vagrant/box_test.rb b/test/vagrant/box_test.rb index a5b5ae376..4e457cf07 100644 --- a/test/vagrant/box_test.rb +++ b/test/vagrant/box_test.rb @@ -3,7 +3,7 @@ require "test_helper" class BoxTest < Test::Unit::TestCase context "class methods" do setup do - @env = mock_environment + @env = vagrant_env end context "listing all boxes" do @@ -112,7 +112,7 @@ class BoxTest < Test::Unit::TestCase context "instance methods" do setup do @box = Vagrant::Box.new - @box.env = mock_environment + @box.env = vagrant_env end should "execute the Add action when add is called" do diff --git a/test/vagrant/cli_test.rb b/test/vagrant/cli_test.rb index fc165258e..05f716b2e 100644 --- a/test/vagrant/cli_test.rb +++ b/test/vagrant/cli_test.rb @@ -29,7 +29,7 @@ class CLITest < Test::Unit::TestCase name = "__test_registering_with_alias" @klass.register(base, name, name, "A description", :alias => "--ALIAS") - assert_raises(RuntimeError) { @klass.start(["--ALIAS"], :env => mock_environment) } + assert_raises(RuntimeError) { @klass.start(["--ALIAS"], :env => vagrant_env) } end end end diff --git a/test/vagrant/command/base_test.rb b/test/vagrant/command/base_test.rb index 390c7f48a..0d09e5da9 100644 --- a/test/vagrant/command/base_test.rb +++ b/test/vagrant/command/base_test.rb @@ -3,7 +3,7 @@ require "test_helper" class CommandBaseTest < Test::Unit::TestCase setup do @klass = Vagrant::Command::Base - @env = mock_environment + @env = vagrant_env end context "initialization" do diff --git a/test/vagrant/command/group_base_test.rb b/test/vagrant/command/group_base_test.rb index b821edd31..0def8b817 100644 --- a/test/vagrant/command/group_base_test.rb +++ b/test/vagrant/command/group_base_test.rb @@ -3,7 +3,7 @@ require "test_helper" class CommandGroupBaseTest < Test::Unit::TestCase setup do @klass = Vagrant::Command::GroupBase - @env = mock_environment + @env = vagrant_env end context "initialization" do diff --git a/test/vagrant/command/helpers_test.rb b/test/vagrant/command/helpers_test.rb index d325eafdc..8651c6cbf 100644 --- a/test/vagrant/command/helpers_test.rb +++ b/test/vagrant/command/helpers_test.rb @@ -18,7 +18,7 @@ class CommandHelpersTest < Test::Unit::TestCase end should "not raise an exception if environment is given and setup UI" do - env = mock_environment + env = vagrant_env assert_nothing_raised { command([], env) } assert env.ui.is_a?(Vagrant::UI::Shell) end @@ -26,7 +26,7 @@ class CommandHelpersTest < Test::Unit::TestCase context "vms from args" do setup do - @env = mock_environment + @env = vagrant_env @env.stubs(:root_path).returns(7) end diff --git a/test/vagrant/config/ssh_test.rb b/test/vagrant/config/ssh_test.rb index fa55f1464..2fb90e333 100644 --- a/test/vagrant/config/ssh_test.rb +++ b/test/vagrant/config/ssh_test.rb @@ -2,8 +2,7 @@ require "test_helper" class ConfigSSHTest < Test::Unit::TestCase setup do - @env = mock_environment - @env.stubs(:root_path).returns("foo") + @env = vagrant_env end should "expand any path when requesting the value" do diff --git a/test/vagrant/config/vm_test.rb b/test/vagrant/config/vm_test.rb index f5a1478e1..26fecb5d4 100644 --- a/test/vagrant/config/vm_test.rb +++ b/test/vagrant/config/vm_test.rb @@ -4,7 +4,7 @@ class ConfigVMTest < Test::Unit::TestCase setup do @username = "mitchellh" - @env = mock_environment + @env = vagrant_env @config = @env.config.vm @env.config.ssh.username = @username end diff --git a/test/vagrant/config_test.rb b/test/vagrant/config_test.rb index 519a1eb0e..f04e223c7 100644 --- a/test/vagrant/config_test.rb +++ b/test/vagrant/config_test.rb @@ -7,7 +7,7 @@ class ConfigTest < Test::Unit::TestCase context "with an instance" do setup do - @env = mock_environment + @env = vagrant_env @instance = @klass.new(@env) # Don't want validation to occur for these tests diff --git a/test/vagrant/downloaders/base_test.rb b/test/vagrant/downloaders/base_test.rb index 7b7d679fe..4cb37c6e6 100644 --- a/test/vagrant/downloaders/base_test.rb +++ b/test/vagrant/downloaders/base_test.rb @@ -7,7 +7,7 @@ class BaseDownloaderTest < Test::Unit::TestCase context "base instance" do setup do - @env = mock_environment + @env = vagrant_env @base = Vagrant::Downloaders::Base.new(@env) end diff --git a/test/vagrant/hosts/base_test.rb b/test/vagrant/hosts/base_test.rb index 93ddd66c0..ad0dc837f 100644 --- a/test/vagrant/hosts/base_test.rb +++ b/test/vagrant/hosts/base_test.rb @@ -8,7 +8,7 @@ class BaseHostTest < Test::Unit::TestCase context "class methods" do context "loading" do setup do - @env = mock_environment + @env = vagrant_env end should "return detected class if klass is nil" do diff --git a/test/vagrant/provisioners/base_test.rb b/test/vagrant/provisioners/base_test.rb index 36ef54e6c..820cdd48b 100644 --- a/test/vagrant/provisioners/base_test.rb +++ b/test/vagrant/provisioners/base_test.rb @@ -7,7 +7,7 @@ class BaseProvisionerTest < Test::Unit::TestCase context "base instance" do setup do - @env = Vagrant::Action::Environment.new(mock_environment) + @env = Vagrant::Action::Environment.new(vagrant_env) @base = Vagrant::Provisioners::Base.new(@env) end diff --git a/test/vagrant/provisioners/chef_server_test.rb b/test/vagrant/provisioners/chef_server_test.rb index a60854c24..b31537207 100644 --- a/test/vagrant/provisioners/chef_server_test.rb +++ b/test/vagrant/provisioners/chef_server_test.rb @@ -2,7 +2,7 @@ require "test_helper" class ChefServerProvisionerTest < Test::Unit::TestCase setup do - @action_env = Vagrant::Action::Environment.new(mock_environment) + @action_env = Vagrant::Action::Environment.new(vagrant_env) @action_env.env.vm = mock_vm @action = Vagrant::Provisioners::ChefServer.new(@action_env) diff --git a/test/vagrant/provisioners/chef_solo_test.rb b/test/vagrant/provisioners/chef_solo_test.rb index dd7b37d8d..5271ab91d 100644 --- a/test/vagrant/provisioners/chef_solo_test.rb +++ b/test/vagrant/provisioners/chef_solo_test.rb @@ -2,7 +2,7 @@ require "test_helper" class ChefSoloProvisionerTest < Test::Unit::TestCase setup do - @action_env = Vagrant::Action::Environment.new(mock_environment) + @action_env = Vagrant::Action::Environment.new(vagrant_env) @action_env.env.vm = mock_vm @action = Vagrant::Provisioners::ChefSolo.new(@action_env) diff --git a/test/vagrant/provisioners/chef_test.rb b/test/vagrant/provisioners/chef_test.rb index 6f013d7a7..1a218a31a 100644 --- a/test/vagrant/provisioners/chef_test.rb +++ b/test/vagrant/provisioners/chef_test.rb @@ -2,7 +2,7 @@ require "test_helper" class ChefProvisionerTest < Test::Unit::TestCase setup do - @action_env = Vagrant::Action::Environment.new(mock_environment) + @action_env = Vagrant::Action::Environment.new(vagrant_env) @action_env.env.vm = mock_vm @action = Vagrant::Provisioners::Chef.new(@action_env) diff --git a/test/vagrant/systems/linux_test.rb b/test/vagrant/systems/linux_test.rb index 65b86c6b5..2e3000142 100644 --- a/test/vagrant/systems/linux_test.rb +++ b/test/vagrant/systems/linux_test.rb @@ -4,7 +4,7 @@ class LinuxSystemTest < Test::Unit::TestCase setup do @klass = Vagrant::Systems::Linux @ssh = mock("ssh") - @mock_env = mock_environment + @mock_env = vagrant_env @vm = mock("vm") @vm.stubs(:env).returns(@mock_env) @instance = @klass.new(@vm) diff --git a/test/vagrant/ui_test.rb b/test/vagrant/ui_test.rb index a2b3f404d..72802344f 100644 --- a/test/vagrant/ui_test.rb +++ b/test/vagrant/ui_test.rb @@ -4,7 +4,7 @@ class ShellUITest < Test::Unit::TestCase setup do @klass = Vagrant::UI::Shell @shell = mock("shell") - @instance = @klass.new(mock_environment, @shell) + @instance = @klass.new(vagrant_env, @shell) end context "prefixing with resource" do diff --git a/test/vagrant/util/resource_logger_test.rb b/test/vagrant/util/resource_logger_test.rb index a39900681..32a37a12e 100644 --- a/test/vagrant/util/resource_logger_test.rb +++ b/test/vagrant/util/resource_logger_test.rb @@ -13,7 +13,7 @@ class ResourceLoggerUtilTest < Test::Unit::TestCase end should "return a nil plain logger if the config is not loaded" do - env = mock_environment + env = vagrant_env env.config.stubs(:loaded?).returns(false) Vagrant::Util::PlainLogger.expects(:new).with(nil).returns(@result) @@ -22,7 +22,7 @@ class ResourceLoggerUtilTest < Test::Unit::TestCase should "return a logger with the specified output if environment is ready" do output = mock("output") - env = mock_environment + env = vagrant_env env.config.vagrant.log_output = output Vagrant::Util::PlainLogger.expects(:new).with(output).returns(@result) @@ -31,7 +31,7 @@ class ResourceLoggerUtilTest < Test::Unit::TestCase should "only load the logger once" do output = mock("output") - env = mock_environment + env = vagrant_env env.config.vagrant.log_output = output Vagrant::Util::PlainLogger.expects(:new).with(output).returns(@result) @@ -43,7 +43,7 @@ class ResourceLoggerUtilTest < Test::Unit::TestCase context "initialization" do should "setup the logger and attributes" do - env = mock_environment + env = vagrant_env resource = mock("resource") result = mock("result") @@ -58,7 +58,7 @@ class ResourceLoggerUtilTest < Test::Unit::TestCase context "with an instance" do setup do @resource = "foo" - @env = mock_environment + @env = vagrant_env @logger = mock("logger") @klass.stubs(:singleton_logger).returns(@logger)