diff --git a/lib/vagrant/util/caps.rb b/lib/vagrant/util/caps.rb index 4a7337d86..310add326 100644 --- a/lib/vagrant/util/caps.rb +++ b/lib/vagrant/util/caps.rb @@ -30,7 +30,8 @@ module Vagrant if file_destination.nil? tmpfile = Tempfile.new(["vagrant", ".iso"]) file_destination = Pathname.new(tmpfile.path) - tmpfile.delete + tmpfile.close + tmpfile.unlink else file_destination = Pathname.new(file_destination.to_s) # If the file destination path is a folder, target the output to a randomly named diff --git a/test/unit/plugins/hosts/darwin/cap/fs_iso_test.rb b/test/unit/plugins/hosts/darwin/cap/fs_iso_test.rb index f16bc1758..460fd33f8 100644 --- a/test/unit/plugins/hosts/darwin/cap/fs_iso_test.rb +++ b/test/unit/plugins/hosts/darwin/cap/fs_iso_test.rb @@ -62,7 +62,8 @@ describe VagrantPlugins::HostDarwin::Cap::FsISO do ).and_return(double(exit_code: 0)) # Should create a directory wherever Tempfile creates files by default expect(FileUtils).to receive(:mkdir_p).with(Pathname.new(file_destination).dirname) - + allow(file_destination).to receive(:close) + allow(file_destination).to receive(:unlink) output = subject.create_iso(env, "/foo/src") expect(output.to_s).to eq(file_destination) end