From 16f3a3facea220c50e782b3573e4600d6b8c5acc Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 8 Sep 2010 23:51:09 -0700 Subject: [PATCH] Test helper `mock_environment` completely gone --- test/test_helper.rb | 67 -------------------- test/vagrant/action/vm/share_folders_test.rb | 43 ++++++------- 2 files changed, 20 insertions(+), 90 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 773b3b2bd..14622dd95 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -28,73 +28,6 @@ class Test::Unit::TestCase include VagrantTestHelpers::Environment include VagrantTestHelpers::Objects - # Mocks an environment, setting it up with the given config. - def mock_environment - environment = Vagrant::Environment.new - environment.instance_variable_set(:@loaded, true) - - Vagrant::Config.reset!(environment) - - Vagrant::Config.run do |config| - config.vagrant.home = '~/.home' - config.vagrant.dotfile_name = ".vagrant" - config.vagrant.log_output = nil - config.vagrant.host = :detect - - config.ssh.username = "foo" - config.ssh.host = "baz" - config.ssh.port = 22 - config.ssh.forwarded_port_key = "ssh" - config.ssh.max_tries = 10 - config.ssh.timeout = 10 - config.ssh.private_key_path = File.expand_path("keys/vagrant", Vagrant.source_root) - - config.vm.box = "foo" - config.vm.box_url = nil - config.vm.box_ovf = "box.ovf" - config.vm.base_mac = "42" - config.vm.disk_image_format = 'VMDK' - config.vm.forward_port("ssh", 22, 2222) - config.vm.shared_folder_uid = nil - config.vm.shared_folder_gid = nil - config.vm.system = :linux - config.vm.share_folder("v-root", "/vagrant", ".") - - config.package.name = 'package' - - # Chef - config.chef.chef_server_url = "http://localhost:4000" - config.chef.validation_key_path = "validation.pem" - config.chef.client_key_path = "/zoo/foo/bar.pem" - config.chef.node_name = "baz" - config.chef.recipe_url = nil - config.chef.cookbooks_path = "cookbooks" - config.chef.provisioning_path = "/tmp/vagrant-chef" - config.chef.log_level = :info - config.chef.json = { - :recipes => ["vagrant_main"] - } - end - - if block_given? - Vagrant::Config.run do |config| - yield config - end - end - - config = Vagrant::Config.execute! - - environment.instance_variable_set(:@config, config) - - # Setup the logger. We create it then reset it so that subsequent - # calls will recreate it for us. - environment.logger.class.reset_singleton_logger! - environment.logger.stubs(:flush_progress) - environment.logger.stubs(:cl_reset).returns("") - - environment - end - # Sets up the mocks for a VM def mock_vm(env=nil) env ||= vagrant_env diff --git a/test/vagrant/action/vm/share_folders_test.rb b/test/vagrant/action/vm/share_folders_test.rb index d5bc5e832..704747147 100644 --- a/test/vagrant/action/vm/share_folders_test.rb +++ b/test/vagrant/action/vm/share_folders_test.rb @@ -21,19 +21,11 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase @instance = @klass.new(@app, @env) end - def stub_shared_folders - env = mock_environment do |config| + def stub_shared_folders(contents) + env = vagrant_env(vagrantfile(<<-vf)) config.vm.shared_folders.clear - - if block_given? - yield config - else - folders = [%w{foo fooguest foohost}, %w{bar barguest barhost}] - folders.each do |data| - config.vm.share_folder(*data) - end - end - end + #{contents} + vf @env.stubs(:env).returns(env) env.config.vm.shared_folders @@ -57,11 +49,10 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase "bar" => %W[foo baz] } - stub_shared_folders do |config| - data.each do |name, value| - config.vm.share_folder(name, *value) - end - end + stub_shared_folders(<<-sf) + config.vm.share_folder("foo", "bar", "baz") + config.vm.share_folder("bar", "foo", "baz") + sf result = @instance.shared_folders assert_equal data.length, result.length @@ -73,20 +64,20 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase end should "ignore disabled shared folders" do - stub_shared_folders do |config| + stub_shared_folders(<<-sf) config.vm.share_folder("v-foo", "/foo", "/foo") config.vm.share_folder("v-root", "/vagrant", ".", :disabled => true) config.vm.share_folder("v-bar", "/bar", "/bar") - end + sf assert_equal 2, @instance.shared_folders.length assert_equal %W[v-bar v-foo], @instance.shared_folders.keys.sort end should "not destroy original hash" do - @folders = stub_shared_folders do |config| + @folders = stub_shared_folders(<<-sf) config.vm.share_folder("foo", "bar", "baz", :sync => true) - end + sf folder = @folders["foo"].dup @@ -97,7 +88,10 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase context "setting up shared folder metadata" do setup do - stub_shared_folders + stub_shared_folders(<<-sf) + config.vm.share_folder("foo", "fooguest", "foohost") + config.vm.share_folder("bar", "barguest", "barhost") + sf end should "add all shared folders to the VM" do @@ -119,7 +113,10 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase context "mounting the shared folders" do setup do - @folders = stub_shared_folders + @folders = stub_shared_folders(<<-sf) + config.vm.share_folder("foo", "fooguest", "foohost") + config.vm.share_folder("bar", "barguest", "barhost") + sf @ssh = mock("ssh") @vm.ssh.stubs(:execute).yields(@ssh) @vm.system.stubs(:mount_shared_folder)