diff --git a/lib/vagrant/action.rb b/lib/vagrant/action.rb index 4966dff5d..1917d9489 100644 --- a/lib/vagrant/action.rb +++ b/lib/vagrant/action.rb @@ -45,6 +45,7 @@ module Vagrant def run(callable, options=nil) callable = Builder.new.use(callable) if callable.kind_of?(Class) callable = self.class.actions[callable] if callable.kind_of?(Symbol) + raise Exceptions::UncallableAction.new(callable) if !callable action_environment = Action::Environment.new(env) action_environment.merge!(options || {}) diff --git a/lib/vagrant/exceptions/uncallable_action.rb b/lib/vagrant/exceptions/uncallable_action.rb new file mode 100644 index 000000000..0a0c254b6 --- /dev/null +++ b/lib/vagrant/exceptions/uncallable_action.rb @@ -0,0 +1,17 @@ +module Vagrant + module Exceptions + # Raised when an action sequence is trying to be run for an uncallable + # action (not a lambda, middleware, or registered sequence). + class UncallableAction < Exception + def initialize(callable) + super() + + @callable = callable + end + + def to_s + @callable.inspect + end + end + end +end diff --git a/test/vagrant/action_test.rb b/test/vagrant/action_test.rb index 5e8b839bf..3c184d0cb 100644 --- a/test/vagrant/action_test.rb +++ b/test/vagrant/action_test.rb @@ -31,6 +31,11 @@ class ActionTest < Test::Unit::TestCase @klass.actions.clear end + should "raise an exception if a nil action is given" do + assert_raises(Vagrant::Exceptions::UncallableAction) { @instance.run(nil) } + assert_raises(Vagrant::Exceptions::UncallableAction) { @instance.run(:dontexist) } + end + should "run the callable item with the proper context" do callable = mock("callable") callable.expects(:call).with() do |env|