From b993699af6a028c170a5faf598da4eef28bcb03f Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sun, 29 May 2016 00:34:00 -0400 Subject: [PATCH] Cleanup more files in tests --- .../plugins/providers/docker/config_test.rb | 8 ++++++-- test/unit/plugins/pushes/atlas/push_test.rb | 18 +++++++++++------- test/unit/plugins/pushes/ftp/push_test.rb | 3 ++- test/unit/vagrant/box_test.rb | 9 ++++++++- test/unit/vagrant/environment_test.rb | 2 +- test/unit/vagrant/machine_index_test.rb | 2 +- 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/test/unit/plugins/providers/docker/config_test.rb b/test/unit/plugins/providers/docker/config_test.rb index a938fcf45..5dc59bcc4 100644 --- a/test/unit/plugins/providers/docker/config_test.rb +++ b/test/unit/plugins/providers/docker/config_test.rb @@ -10,13 +10,17 @@ describe VagrantPlugins::DockerProvider::Config do let(:machine) { double("machine") } let(:build_dir) do - temporary_dir.tap do |dir| - dir.join("Dockerfile").open("w") do |f| + Dir.mktmpdir("vagrant-test-docker-provider-build-dir").tap do |dir| + File.open(File.join(dir, "Dockerfile"), "wb+") do |f| f.write("Hello") end end end + after do + FileUtils.rm_rf(build_dir) + end + def assert_invalid errors = subject.validate(machine) if !errors.values.any? { |v| !v.empty? } diff --git a/test/unit/plugins/pushes/atlas/push_test.rb b/test/unit/plugins/pushes/atlas/push_test.rb index 974df36a8..9c2465177 100644 --- a/test/unit/plugins/pushes/atlas/push_test.rb +++ b/test/unit/plugins/pushes/atlas/push_test.rb @@ -125,6 +125,14 @@ describe VagrantPlugins::AtlasPush::Push do end describe "#uploader_path" do + let(:scratch) do + Pathname.new(Dir.mktmpdir("vagrant-test-atlas-push-upload-path")) + end + + after do + FileUtils.rm_rf(scratch) + end + it "should return the configured path if set" do config.uploader_path = "foo" expect(subject.uploader_path).to eq("foo") @@ -141,12 +149,10 @@ describe VagrantPlugins::AtlasPush::Push do end it "should look up the uploader in the embedded dir if installer" do - dir = temporary_dir - allow(Vagrant).to receive(:in_installer?).and_return(true) - allow(Vagrant).to receive(:installer_embedded_dir).and_return(dir.to_s) + allow(Vagrant).to receive(:installer_embedded_dir).and_return(scratch.to_s) - bin_path = dir.join("bin", bin) + bin_path = scratch.join("bin", bin) bin_path.dirname.mkpath bin_path.open("w+") { |f| f.write("hi") } @@ -154,10 +160,8 @@ describe VagrantPlugins::AtlasPush::Push do end it "should look up the uploader in the PATH if not in the installer" do - dir = temporary_dir - allow(Vagrant).to receive(:in_installer?).and_return(true) - allow(Vagrant).to receive(:installer_embedded_dir).and_return(dir.to_s) + allow(Vagrant).to receive(:installer_embedded_dir).and_return(scratch.to_s) expect(Vagrant::Util::Which).to receive(:which). with(described_class.const_get(:UPLOADER_BIN)). diff --git a/test/unit/plugins/pushes/ftp/push_test.rb b/test/unit/plugins/pushes/ftp/push_test.rb index 96537cd42..ba69e0078 100644 --- a/test/unit/plugins/pushes/ftp/push_test.rb +++ b/test/unit/plugins/pushes/ftp/push_test.rb @@ -41,7 +41,7 @@ describe VagrantPlugins::FTPPush::Push do end @server.start - @dir = temporary_dir + @dir = Dir.mktmpdir("vagrant-ftp-push") FileUtils.touch("#{@dir}/.hidden.rb") FileUtils.touch("#{@dir}/application.rb") FileUtils.touch("#{@dir}/config.rb") @@ -51,6 +51,7 @@ describe VagrantPlugins::FTPPush::Push do end after(:all) do + FileUtils.rm_rf(@dir) @server.stop end diff --git a/test/unit/vagrant/box_test.rb b/test/unit/vagrant/box_test.rb index ab6c6c548..dfba490aa 100644 --- a/test/unit/vagrant/box_test.rb +++ b/test/unit/vagrant/box_test.rb @@ -290,6 +290,14 @@ describe Vagrant::Box, :skip_windows do end describe "repackaging" do + let(:scratch) { Dir.mktmpdir("vagrant-test-box-repackaging") } + + let(:box_output_path) { File.join(scratch, "package.box") } + + after do + FileUtils.rm_rf(scratch) + end + it "should repackage the box" do test_file_contents = "hello, world!" @@ -300,7 +308,6 @@ describe Vagrant::Box, :skip_windows do end # Repackage our box to some temporary directory - box_output_path = temporary_dir.join("package.box") expect(subject.repackage(box_output_path)).to be_true # Let's now add this box again under a different name, and then diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index 8c1e3b06d..ba3466c9b 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -933,7 +933,7 @@ VF let(:instance) { described_class.new(local_data_path: local_data_path) } after do - File.unlink(v1_dotfile) if File.file?(v1_dotfile) + FileUtils.rm_rf(local_data_path) end it "should be fine if dotfile is empty" do diff --git a/test/unit/vagrant/machine_index_test.rb b/test/unit/vagrant/machine_index_test.rb index 1ea85110c..ed52e9eaa 100644 --- a/test/unit/vagrant/machine_index_test.rb +++ b/test/unit/vagrant/machine_index_test.rb @@ -9,7 +9,7 @@ require "vagrant/machine_index" describe Vagrant::MachineIndex do include_context "unit" - let(:data_dir) { temporary_dir } + let(:data_dir) { Pathname.new(Dir.mktmpdir("vagrant-test-machine-index-data-dir")) } let(:entry_klass) { Vagrant::MachineIndex::Entry } let(:new_entry) do