load_root_path! can now suppress errors if option is set
This commit is contained in:
parent
09bd40c207
commit
fef985009f
|
@ -48,8 +48,9 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_root_path!(path=Pathname.new(Dir.pwd))
|
def load_root_path!(path=Pathname.new(Dir.pwd), opts={})
|
||||||
if path.to_s == '/'
|
if path.to_s == '/'
|
||||||
|
return false if opts[:suppress_errors]
|
||||||
error_and_exit(<<-msg)
|
error_and_exit(<<-msg)
|
||||||
A `#{ROOTFILE_NAME}` was not found! This file is required for vagrant to run
|
A `#{ROOTFILE_NAME}` was not found! This file is required for vagrant to run
|
||||||
since it describes the expected environment that vagrant is supposed
|
since it describes the expected environment that vagrant is supposed
|
||||||
|
@ -62,10 +63,10 @@ msg
|
||||||
file = "#{path}/#{ROOTFILE_NAME}"
|
file = "#{path}/#{ROOTFILE_NAME}"
|
||||||
if File.exist?(file)
|
if File.exist?(file)
|
||||||
@@root_path = path.to_s
|
@@root_path = path.to_s
|
||||||
return
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
load_root_path!(path.parent)
|
load_root_path!(path.parent, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_persisted_vm
|
def require_persisted_vm
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
||||||
|
|
||||||
class EnvTest < Test::Unit::TestCase
|
class EnvTest < Test::Unit::TestCase
|
||||||
def dot_file_expectation
|
|
||||||
File.expects(:exists?).at_least_once.returns(true)
|
|
||||||
File.expects(:open).with(dotfile, 'r').returns(['foo'])
|
|
||||||
end
|
|
||||||
|
|
||||||
def mock_persisted_vm(returnvalue="foovm")
|
def mock_persisted_vm(returnvalue="foovm")
|
||||||
filemock = mock("filemock")
|
filemock = mock("filemock")
|
||||||
filemock.expects(:read).returns("foo")
|
filemock.expects(:read).returns("foo")
|
||||||
|
@ -15,7 +10,6 @@ class EnvTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
Vagrant::Env.stubs(:error_and_exit)
|
|
||||||
mock_config
|
mock_config
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -114,6 +108,8 @@ class EnvTest < Test::Unit::TestCase
|
||||||
|
|
||||||
context "loading the root path" do
|
context "loading the root path" do
|
||||||
test "should walk the parent directories looking for rootfile" do
|
test "should walk the parent directories looking for rootfile" do
|
||||||
|
Vagrant::Env.expects(:error_and_exit).once
|
||||||
|
|
||||||
paths = [
|
paths = [
|
||||||
Pathname.new("/foo/bar/baz"),
|
Pathname.new("/foo/bar/baz"),
|
||||||
Pathname.new("/foo/bar"),
|
Pathname.new("/foo/bar"),
|
||||||
|
@ -135,11 +131,26 @@ class EnvTest < Test::Unit::TestCase
|
||||||
Vagrant::Env.load_root_path!(path)
|
Vagrant::Env.load_root_path!(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "return false if suppress errors is set and no root path is found" do
|
||||||
|
path = Pathname.new("/")
|
||||||
|
|
||||||
|
Vagrant::Env.expects(:error_and_exit).never
|
||||||
|
assert !Vagrant::Env.load_root_path!(path, :suppress_errors => true)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "pipe suppress errors flag through recursion" do
|
||||||
|
path = Pathname.new("/foo/bar/baz")
|
||||||
|
File.expects(:exist?).times(3).returns(false)
|
||||||
|
|
||||||
|
Vagrant::Env.expects(:error_and_exit).never
|
||||||
|
assert !Vagrant::Env.load_root_path!(path, :suppress_errors => true)
|
||||||
|
end
|
||||||
|
|
||||||
test "should set the path for the rootfile" do
|
test "should set the path for the rootfile" do
|
||||||
path = "/foo"
|
path = "/foo"
|
||||||
File.expects(:exist?).with("#{path}/#{Vagrant::Env::ROOTFILE_NAME}").returns(true)
|
File.expects(:exist?).with("#{path}/#{Vagrant::Env::ROOTFILE_NAME}").returns(true)
|
||||||
Vagrant::Env.load_root_path!(Pathname.new(path))
|
|
||||||
|
|
||||||
|
assert Vagrant::Env.load_root_path!(Pathname.new(path))
|
||||||
assert_equal path, Vagrant::Env.root_path
|
assert_equal path, Vagrant::Env.root_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue