From 3d147f1d96ad1bf5561e07fe6db18194c3c3b6dc Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 5 May 2012 22:10:26 -0700 Subject: [PATCH] Raise exception if the insert_before middleware is not found --- lib/vagrant/action/builder.rb | 1 + test/unit/vagrant/action/builder_test.rb | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) 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