From 5ce43a8ae06f0d46f140227d59bb0937604b171f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 11 Sep 2010 10:42:03 -0700 Subject: [PATCH] Utilize pathname when available instead of doing just a File.join --- lib/vagrant/action/box/download.rb | 2 +- lib/vagrant/action/vm/export.rb | 2 +- lib/vagrant/util/template_renderer.rb | 2 +- test/vagrant/action/box/download_test.rb | 2 +- test/vagrant/action/vm/export_test.rb | 5 +---- test/vagrant/environment_test.rb | 10 +++++----- test/vagrant/util/template_renderer_test.rb | 8 ++++---- 7 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/vagrant/action/box/download.rb b/lib/vagrant/action/box/download.rb index e9299e9d5..db50c9c00 100644 --- a/lib/vagrant/action/box/download.rb +++ b/lib/vagrant/action/box/download.rb @@ -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) diff --git a/lib/vagrant/action/vm/export.rb b/lib/vagrant/action/vm/export.rb index 6040a287e..258d2c4e7 100644 --- a/lib/vagrant/action/vm/export.rb +++ b/lib/vagrant/action/vm/export.rb @@ -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 diff --git a/lib/vagrant/util/template_renderer.rb b/lib/vagrant/util/template_renderer.rb index ce6c19811..414e26621 100644 --- a/lib/vagrant/util/template_renderer.rb +++ b/lib/vagrant/util/template_renderer.rb @@ -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 diff --git a/test/vagrant/action/box/download_test.rb b/test/vagrant/action/box/download_test.rb index 086b48630..ff385dda1 100644 --- a/test/vagrant/action/box/download_test.rb +++ b/test/vagrant/action/box/download_test.rb @@ -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 diff --git a/test/vagrant/action/vm/export_test.rb b/test/vagrant/action/vm/export_test.rb index ae3d2af3c..f95b1d7d5 100644 --- a/test/vagrant/action/vm/export_test.rb +++ b/test/vagrant/action/vm/export_test.rb @@ -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 diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index 4797a921f..cc8e26ddd 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -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 diff --git a/test/vagrant/util/template_renderer_test.rb b/test/vagrant/util/template_renderer_test.rb index 20922d5eb..41df5f723 100644 --- a/test/vagrant/util/template_renderer_test.rb +++ b/test/vagrant/util/template_renderer_test.rb @@ -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