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 || {})
|
}.merge(opts || {})
|
||||||
|
|
||||||
opts[:cwd] ||= Dir.pwd
|
opts[:cwd] ||= Dir.pwd
|
||||||
|
opts[:cwd] = Pathname.new(opts[:cwd])
|
||||||
|
|
||||||
opts.each do |key, value|
|
opts.each do |key, value|
|
||||||
instance_variable_set("@#{key}".to_sym, opts[key])
|
instance_variable_set("@#{key}".to_sym, opts[key])
|
||||||
|
@ -172,12 +173,12 @@ module Vagrant
|
||||||
return @root_path if defined?(@root_path)
|
return @root_path if defined?(@root_path)
|
||||||
|
|
||||||
root_finder = lambda do |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?
|
return nil if path.root?
|
||||||
root_finder.call(path.parent)
|
root_finder.call(path.parent)
|
||||||
end
|
end
|
||||||
|
|
||||||
@root_path = root_finder.call(Pathname.new(cwd))
|
@root_path = root_finder.call(cwd)
|
||||||
end
|
end
|
||||||
|
|
||||||
#---------------------------------------------------------------
|
#---------------------------------------------------------------
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
require "test_helper"
|
require "test_helper"
|
||||||
|
require "pathname"
|
||||||
|
|
||||||
class EnvironmentTest < Test::Unit::TestCase
|
class EnvironmentTest < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
|
@ -37,12 +38,12 @@ class EnvironmentTest < Test::Unit::TestCase
|
||||||
should "set the cwd if given" do
|
should "set the cwd if given" do
|
||||||
cwd = "foobarbaz"
|
cwd = "foobarbaz"
|
||||||
env = @klass.new(:cwd => cwd)
|
env = @klass.new(:cwd => cwd)
|
||||||
assert_equal cwd, env.cwd
|
assert_equal Pathname.new(cwd), env.cwd
|
||||||
end
|
end
|
||||||
|
|
||||||
should "default to pwd if cwd is nil" do
|
should "default to pwd if cwd is nil" do
|
||||||
env = @klass.new
|
env = @klass.new
|
||||||
assert_equal Dir.pwd, env.cwd
|
assert_equal Pathname.new(Dir.pwd), env.cwd
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -252,7 +253,7 @@ class EnvironmentTest < Test::Unit::TestCase
|
||||||
path = File.expand_path("/foo")
|
path = File.expand_path("/foo")
|
||||||
File.expects(:exist?).with(File.join(path, @klass::ROOTFILE_NAME)).returns(true)
|
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
|
end
|
||||||
|
|
||||||
should "only load the root path once" do
|
should "only load the root path once" do
|
||||||
|
|
Loading…
Reference in New Issue