diff --git a/lib/vagrant/action/builder.rb b/lib/vagrant/action/builder.rb index 2b54115ff..5276ec3ab 100644 --- a/lib/vagrant/action/builder.rb +++ b/lib/vagrant/action/builder.rb @@ -57,6 +57,7 @@ module Vagrant # given middleware object. def insert(index, middleware, *args, &block) index = self.index(index) unless index.is_a?(Integer) + raise "no such middleware to insert before: #{index.inspect}" unless index stack.insert(index, [middleware, args, block]) end diff --git a/test/unit/vagrant/action/builder_test.rb b/test/unit/vagrant/action/builder_test.rb index 66bcd9897..046166cfa 100644 --- a/test/unit/vagrant/action/builder_test.rb +++ b/test/unit/vagrant/action/builder_test.rb @@ -113,7 +113,12 @@ describe Vagrant::Action::Builder do data[:data].should == [1, 2, 3] end - it "raises an exception if an invalid object given" do + it "raises an exception if an invalid object given for insert" do + expect { instance.insert "object", appender_proc(1) }. + to raise_error(RuntimeError) + end + + it "raises an exception if an invalid object given for insert_after" do expect { instance.insert_after "object", appender_proc(1) }. to raise_error(RuntimeError) end