Environment#cwd and Environment#root_path are now pathname objects for more robust usage
This commit is contained in:
parent
84389580d6
commit
fe593c88b8
|
@ -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
|
||||
|
||||
#---------------------------------------------------------------
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue