From fe593c88b814509b258243185e2fb673dc7d3a2a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 7 Sep 2010 00:25:52 -0700 Subject: [PATCH] Environment#cwd and Environment#root_path are now pathname objects for more robust usage --- lib/vagrant/environment.rb | 5 +++-- test/vagrant/environment_test.rb | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 91f28830e..63a7eb4a3 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -39,6 +39,7 @@ module Vagrant }.merge(opts || {}) opts[:cwd] ||= Dir.pwd + opts[:cwd] = Pathname.new(opts[:cwd]) opts.each do |key, value| instance_variable_set("@#{key}".to_sym, opts[key]) @@ -172,12 +173,12 @@ module Vagrant return @root_path if defined?(@root_path) root_finder = lambda do |path| - return path.to_s if File.exist?(File.join(path.to_s, ROOTFILE_NAME)) + return path if File.exist?(File.join(path.to_s, ROOTFILE_NAME)) return nil if path.root? root_finder.call(path.parent) end - @root_path = root_finder.call(Pathname.new(cwd)) + @root_path = root_finder.call(cwd) end #--------------------------------------------------------------- diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index 14c251cf0..a413c055d 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -1,4 +1,5 @@ require "test_helper" +require "pathname" class EnvironmentTest < Test::Unit::TestCase setup do @@ -37,12 +38,12 @@ class EnvironmentTest < Test::Unit::TestCase should "set the cwd if given" do cwd = "foobarbaz" env = @klass.new(:cwd => cwd) - assert_equal cwd, env.cwd + assert_equal Pathname.new(cwd), env.cwd end should "default to pwd if cwd is nil" do env = @klass.new - assert_equal Dir.pwd, env.cwd + assert_equal Pathname.new(Dir.pwd), env.cwd end end @@ -252,7 +253,7 @@ class EnvironmentTest < Test::Unit::TestCase path = File.expand_path("/foo") File.expects(:exist?).with(File.join(path, @klass::ROOTFILE_NAME)).returns(true) - assert_equal path, @klass.new(:cwd => path).root_path + assert_equal Pathname.new(path), @klass.new(:cwd => path).root_path end should "only load the root path once" do