Use Dir.mktmpdir for tests more

This commit is contained in:
Mitchell Hashimoto 2013-02-26 11:32:44 -08:00
parent c9d9bf679b
commit 7c5d118e0d
1 changed files with 23 additions and 20 deletions

View File

@ -6,8 +6,6 @@ require "tmpdir"
require "vagrant/util/file_mode" require "vagrant/util/file_mode"
require "support/tempdir"
describe Vagrant::Environment do describe Vagrant::Environment do
include_context "unit" include_context "unit"
@ -50,27 +48,30 @@ describe Vagrant::Environment do
describe "current working directory" do describe "current working directory" do
it "is the cwd by default" do it "is the cwd by default" do
temp_dir = Tempdir.new.path Dir.mktmpdir do |temp_dir|
Dir.chdir(temp_dir) do Dir.chdir(temp_dir) do
with_temp_env("VAGRANT_CWD" => nil) do with_temp_env("VAGRANT_CWD" => nil) do
described_class.new.cwd.should == Pathname.new(Dir.pwd) described_class.new.cwd.should == Pathname.new(Dir.pwd)
end
end end
end end
end end
it "is set to the cwd given" do it "is set to the cwd given" do
directory = Tempdir.new.path Dir.mktmpdir do |directory|
instance = described_class.new(:cwd => directory) instance = described_class.new(:cwd => directory)
instance.cwd.should == Pathname.new(directory) instance.cwd.should == Pathname.new(directory)
end
end end
it "is set to the environmental variable VAGRANT_CWD" do it "is set to the environmental variable VAGRANT_CWD" do
directory = Tempdir.new.path Dir.mktmpdir do |directory|
instance = with_temp_env("VAGRANT_CWD" => directory) do instance = with_temp_env("VAGRANT_CWD" => directory) do
described_class.new described_class.new
end end
instance.cwd.should == Pathname.new(directory) instance.cwd.should == Pathname.new(directory)
end
end end
it "raises an exception if the CWD doesn't exist" do it "raises an exception if the CWD doesn't exist" do
@ -81,9 +82,10 @@ describe Vagrant::Environment do
describe "home path" do describe "home path" do
it "is set to the home path given" do it "is set to the home path given" do
dir = Tempdir.new.path Dir.mktmpdir do |dir|
instance = described_class.new(:home_path => dir) instance = described_class.new(:home_path => dir)
instance.home_path.should == Pathname.new(dir) instance.home_path.should == Pathname.new(dir)
end
end end
it "is set to the environmental variable VAGRANT_HOME" do it "is set to the environmental variable VAGRANT_HOME" do
@ -120,9 +122,10 @@ describe Vagrant::Environment do
end end
it "is set to the given value" do it "is set to the given value" do
dir = Tempdir.new.path Dir.mktmpdir do |dir|
instance = described_class.new(:local_data_path => dir) instance = described_class.new(:local_data_path => dir)
instance.local_data_path.to_s.should == dir instance.local_data_path.to_s.should == dir
end
end end
describe "upgrading V1 dotfiles" do describe "upgrading V1 dotfiles" do