Tests for multivagrantfile being found

This commit is contained in:
Mitchell Hashimoto 2012-01-08 23:04:23 -08:00
parent 3fdc3bee4b
commit 4f30a834d0
3 changed files with 29 additions and 3 deletions

View File

@ -495,7 +495,7 @@ module Vagrant
if current_path.exist?
# We also test if current_path == path because on case insensitive
# file systems, it will look like multiple exist.
if path && current_path == path
if path && current_path != path
raise Errors::MultiVagrantfileFound, :directory => search_path.to_s
end

View File

@ -7,8 +7,13 @@ require "support/isolated_environment"
module Unit
class IsolatedEnvironment < ::IsolatedEnvironment
def create_vagrant_env
Vagrant::Environment.new(:cwd => @workdir, :home_path => @homedir)
def create_vagrant_env(options=nil)
options = {
:cwd => @workdir,
:home_path => @homedir
}.merge(options || {})
Vagrant::Environment.new(options)
end
def vagrantfile(contents, root=nil)
@ -22,6 +27,7 @@ module Unit
box_dir = boxes_dir.join(name)
box_dir.mkpath
vagrantfile(vagrantfile_contents, box_dir)
box_dir
end
def boxes_dir

View File

@ -151,6 +151,26 @@ VF
env = environment.create_vagrant_env
env.config.for_vm(:default).ssh.port.should == 100
end
it "should error if the box has an ambiguous Vagrantfile" do
environment = isolated_environment do |env|
env.vagrantfile(<<-VF)
Vagrant::Config.run do |config|
config.vm.box = "base"
end
VF
# Create two Vagrantfiles. The normal one and a Vagrantfile2
box_dir = env.box("base", "")
box_dir.join("Vagrantfile2").open("w") do |f|
f.write("")
end
end
env = environment.create_vagrant_env(:vagrantfile_name => ["Vagrantfile", "Vagrantfile2"])
expect { env.config }.
to raise_error(Vagrant::Errors::MultiVagrantfileFound)
end
end
describe "ui" do