From ba9cb19808e4bbb2570c13640d5f21ab88e6ac2f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 8 Oct 2010 09:44:17 -0700 Subject: [PATCH] Configuration only validates on final Vagrantfile proc, allowing multi-VM to work correctly --- CHANGELOG.md | 2 ++ lib/vagrant/config.rb | 6 ++++-- test/vagrant/config_test.rb | 16 ++++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17498eb43..33d300cbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.6.5 (unreleased) + - Configuration now only validates on final Vagrantfile proc, so multi-VM + validates correctly. - A nice error message is given if ".vagrant" is a directory and therefore can't be accessed. [GH-172] - Fix plugin loading in a Rails 2.3.x project. [GH-176] diff --git a/lib/vagrant/config.rb b/lib/vagrant/config.rb index b9748748d..9e37bfbd2 100644 --- a/lib/vagrant/config.rb +++ b/lib/vagrant/config.rb @@ -70,9 +70,11 @@ module Vagrant # class. def execute!(config_object=nil) config_object ||= config - run_procs!(config_object) - config_object.validate! + + # Validate if we're looking at a config object which represents a + # real VM. + config_object.validate! if config_object.env.vm config_object end end diff --git a/test/vagrant/config_test.rb b/test/vagrant/config_test.rb index c57466fd8..4589c2081 100644 --- a/test/vagrant/config_test.rb +++ b/test/vagrant/config_test.rb @@ -74,6 +74,7 @@ class ConfigTest < Test::Unit::TestCase context "resetting" do setup do + @klass.reset!(vagrant_env) @klass::Top.any_instance.stubs(:validate!) @klass.run { |config| } @klass.execute! @@ -105,7 +106,7 @@ class ConfigTest < Test::Unit::TestCase context "initializing" do setup do - @klass.reset! + @klass.reset!(vagrant_env) @klass::Top.any_instance.stubs(:validate!) end @@ -115,13 +116,21 @@ class ConfigTest < Test::Unit::TestCase assert_equal [proc], @klass.proc_stack end - should "run the proc stack with the config when execute is called" do + should "run the validation on an environment which represents a VM" do + @klass.reset!(vagrant_env.vms[:default].env) seq = sequence('seq') @klass.expects(:run_procs!).with(@klass.config).once.in_sequence(seq) @klass.config.expects(:validate!).once.in_sequence(seq) @klass.execute! end + should "not run the validation on an environment that doesn't directly represent a VM" do + seq = sequence('seq') + @klass.expects(:run_procs!).with(@klass.config).once.in_sequence(seq) + @klass.expects(:validate!).never + @klass.execute! + end + should "return the configuration on execute!" do @klass.run {} result = @klass.execute! @@ -129,8 +138,7 @@ class ConfigTest < Test::Unit::TestCase end should "use given configuration object if given" do - fake_env = mock("env") - config = @klass::Top.new(fake_env) + config = @klass::Top.new(vagrant_env) result = @klass.execute!(config) assert_equal config.env, result.env end