diff --git a/lib/vagrant/action/general/validate.rb b/lib/vagrant/action/general/validate.rb new file mode 100644 index 000000000..78a5d5e20 --- /dev/null +++ b/lib/vagrant/action/general/validate.rb @@ -0,0 +1,19 @@ +module Vagrant + class Action + module General + # Simply validates the configuration of the current Vagrant + # environment. + class Validate + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + @env["config"].validate! if !@env.has_key?("validate") || @env["validate"] + @app.call(@env) + end + end + end + end +end diff --git a/test/vagrant/action/general/validate_test.rb b/test/vagrant/action/general/validate_test.rb new file mode 100644 index 000000000..00814bb77 --- /dev/null +++ b/test/vagrant/action/general/validate_test.rb @@ -0,0 +1,31 @@ +require "test_helper" + +class ValidateGeneralActionTest < Test::Unit::TestCase + setup do + @klass = Vagrant::Action::General::Validate + @app, @env = action_env + end + + should "initialize fine" do + @klass.new(@app, @env) + end + + should "validate and call up" do + @instance = @klass.new(@app, @env) + + seq = sequence("seq") + @env["config"].expects(:validate!).once.in_sequence(seq) + @app.expects(:call).with(@env).once.in_sequence(seq) + @instance.call(@env) + end + + should "not validate if env says not to" do + @env["validate"] = false + @instance = @klass.new(@app, @env) + + seq = sequence("seq") + @env["config"].expects(:validate!).never + @app.expects(:call).with(@env).once.in_sequence(seq) + @instance.call(@env) + end +end