Utilize pathname when available instead of doing just a File.join

This commit is contained in:
Mitchell Hashimoto 2010-09-11 10:42:03 -07:00
parent 2026bb0b1c
commit 5ce43a8ae0
7 changed files with 14 additions and 17 deletions

View File

@ -60,7 +60,7 @@ module Vagrant
end
def box_temp_path
File.join(@env.env.tmp_path, BASENAME + Time.now.to_i.to_s)
@env.env.tmp_path.join(BASENAME + Time.now.to_i.to_s)
end
def download_to(f)

View File

@ -32,7 +32,7 @@ module Vagrant
def setup_temp_dir
@env.ui.info "vagrant.actions.vm.export.create_dir"
@temp_dir = @env["export.temp_dir"] = File.join(@env.env.tmp_path, Time.now.to_i.to_s)
@temp_dir = @env["export.temp_dir"] = @env.env.tmp_path.join(Time.now.to_i.to_s)
FileUtils.mkpath(@env["export.temp_dir"])
end

View File

@ -76,7 +76,7 @@ module Vagrant
#
# @return [String]
def full_template_path
File.join(Vagrant.source_root, 'templates', "#{template}.erb").squeeze("/")
Vagrant.source_root.join('templates', "#{template}.erb").to_s.squeeze("/")
end
end
end

View File

@ -75,7 +75,7 @@ class DownloadBoxActionTest < Test::Unit::TestCase
context "tempfile" do
should "create a tempfile in the vagrant tmp directory" do
File.expects(:open).with { |name, bitmask|
name =~ /#{Vagrant::Action::Box::Download::BASENAME}/ && name =~ /#{@env.env.tmp_path}/
name.to_s =~ /#{Vagrant::Action::Box::Download::BASENAME}/ && name.to_s =~ /#{@env.env.tmp_path}/
}.once
@instance.with_tempfile
end

View File

@ -66,10 +66,7 @@ class ExportVMActionTest < Test::Unit::TestCase
@time_now = Time.now.to_i.to_s
Time.stubs(:now).returns(@time_now)
@tmp_path = "foo"
@env.env.stubs(:tmp_path).returns(@tmp_path)
@temp_dir = File.join(@env.env.tmp_path, @time_now)
@temp_dir = @env.env.tmp_path.join(@time_now)
FileUtils.stubs(:mkpath)
end

View File

@ -239,22 +239,22 @@ class EnvironmentTest < Test::Unit::TestCase
search_seq = sequence("search_seq")
paths.each do |path|
File.expects(:exist?).with(File.join(path.to_s, @klass::ROOTFILE_NAME)).returns(false).in_sequence(search_seq)
File.expects(:exist?).with(path.join(@klass::ROOTFILE_NAME).to_s).returns(false).in_sequence(search_seq)
end
assert !@klass.new(:cwd => paths.first).root_path
end
should "should set the path for the rootfile" do
path = File.expand_path("/foo")
File.expects(:exist?).with(File.join(path, @klass::ROOTFILE_NAME)).returns(true)
path = Pathname.new(File.expand_path("/foo"))
File.expects(:exist?).with(path.join(@klass::ROOTFILE_NAME).to_s).returns(true)
assert_equal Pathname.new(path), @klass.new(:cwd => path).root_path
assert_equal path, @klass.new(:cwd => path).root_path
end
should "only load the root path once" do
env = @klass.new
File.expects(:exist?).with(File.join(env.cwd, @klass::ROOTFILE_NAME)).returns(true).once
File.expects(:exist?).with(env.cwd.join(@klass::ROOTFILE_NAME).to_s).returns(true).once
assert_equal env.cwd, env.root_path
assert_equal env.cwd, env.root_path

View File

@ -73,14 +73,14 @@ class TemplateRendererUtilTest < Test::Unit::TestCase
end
should "be the ERB file in the templates directory" do
result = File.join(Vagrant.source_root, "templates", "#{@template}.erb")
assert_equal result, @r.full_template_path
result = Vagrant.source_root.join("templates", "#{@template}.erb")
assert_equal result.to_s, @r.full_template_path
end
should "remove duplicate path separators" do
@r.template = "foo///bar"
result = File.join(Vagrant.source_root, "templates", "foo", "bar.erb")
assert_equal result, @r.full_template_path
result = Vagrant.source_root.join("templates", "foo", "bar.erb")
assert_equal result.to_s, @r.full_template_path
end
end