diff --git a/lib/vagrant/env.rb b/lib/vagrant/env.rb index 19a917f4d..70e851572 100644 --- a/lib/vagrant/env.rb +++ b/lib/vagrant/env.rb @@ -48,8 +48,9 @@ module Vagrant 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 == '/' + return false if opts[:suppress_errors] error_and_exit(<<-msg) A `#{ROOTFILE_NAME}` was not found! This file is required for vagrant to run since it describes the expected environment that vagrant is supposed @@ -62,10 +63,10 @@ msg file = "#{path}/#{ROOTFILE_NAME}" if File.exist?(file) @@root_path = path.to_s - return + return true end - load_root_path!(path.parent) + load_root_path!(path.parent, opts) end def require_persisted_vm diff --git a/test/vagrant/env_test.rb b/test/vagrant/env_test.rb index d8cba02ca..dc0474eb9 100644 --- a/test/vagrant/env_test.rb +++ b/test/vagrant/env_test.rb @@ -1,11 +1,6 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper') 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") filemock = mock("filemock") filemock.expects(:read).returns("foo") @@ -15,7 +10,6 @@ class EnvTest < Test::Unit::TestCase end setup do - Vagrant::Env.stubs(:error_and_exit) mock_config end @@ -114,6 +108,8 @@ class EnvTest < Test::Unit::TestCase context "loading the root path" do test "should walk the parent directories looking for rootfile" do + Vagrant::Env.expects(:error_and_exit).once + paths = [ Pathname.new("/foo/bar/baz"), Pathname.new("/foo/bar"), @@ -135,11 +131,26 @@ class EnvTest < Test::Unit::TestCase Vagrant::Env.load_root_path!(path) 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 path = "/foo" 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 end end