diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index efd800546..d999245db 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -59,6 +59,7 @@ module Vagrant opts[:cwd] ||= ENV["VAGRANT_CWD"] if ENV.has_key?("VAGRANT_CWD") opts[:cwd] ||= Dir.pwd opts[:cwd] = Pathname.new(opts[:cwd]) + raise Errors::EnvironmentNonExistentCWD if !opts[:cwd].directory? # Set the Vagrantfile name up. We append "Vagrantfile" and "vagrantfile" so that # those continue to work as well, but anything custom will take precedence. diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index e3ad4c9ca..6523216df 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -173,6 +173,11 @@ module Vagrant error_key(:status_error, "vagrant.downloaders.http") end + class EnvironmentNonExistentCWD < VagrantError + status_code(75) + error_key(:environment_non_existent_cwd) + end + class EnvironmentLockedError < VagrantError status_code(52) error_key(:environment_locked) diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index 2df46366b..bae13da96 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -17,13 +17,19 @@ describe Vagrant::Environment do end it "is set to the cwd given" do - instance = described_class.new(:cwd => "foobarbaz") - instance.cwd.should == Pathname.new("foobarbaz") + directory = File.dirname(__FILE__) + instance = described_class.new(:cwd => directory) + instance.cwd.should == Pathname.new(directory) end it "is set to the environmental variable VAGRANT_CWD" do pending "A good temporary ENV thing" end + + it "raises an exception if the CWD doesn't exist" do + expect { described_class.new(:cwd => "doesntexist") }. + to raise_error(Vagrant::Errors::EnvironmentNonExistentCWD) + end end describe "home path" do