vaguerent/test/unit/vagrant/util/safe_chdir_test.rb
Seth Vargo fb60d34236
Add unique names to all tmpdir and tempfile calls in tests + cleanup
This commit attempts to uniquely identify the temporary files and
directories that are created during test runs. Where it was a quick
fix, this commit also removes the temporary files and directories.

There are still a ton of temporary files due to calls to
.isolated_environment in the tests without an easy API an easy way
to provide a closer to that function.
2016-05-28 23:22:34 -04:00

50 lines
984 B
Ruby

require 'tmpdir'
require File.expand_path("../../../base", __FILE__)
require 'vagrant/util/safe_chdir'
describe Vagrant::Util::SafeChdir do
let(:temp_dir) { Dir.mktmpdir("vagrant-test-util-safe-chdir") }
let(:temp_dir2) { Dir.mktmpdir("vagrant-test-util-safe-chdir-2") }
after do
FileUtils.rm_rf(temp_dir)
FileUtils.rm_rf(temp_dir2)
end
it "should change directories" do
expected = nil
result = nil
Dir.chdir(temp_dir) do
expected = Dir.pwd
end
described_class.safe_chdir(temp_dir) do
result = Dir.pwd
end
expect(result).to eq(expected)
end
it "should allow recursive chdir" do
expected = nil
result = nil
Dir.chdir(temp_dir) do
expected = Dir.pwd
end
expect do
described_class.safe_chdir(temp_dir2) do
described_class.safe_chdir(temp_dir) do
result = Dir.pwd
end
end
end.to_not raise_error
expect(result).to eq(expected)
end
end