Skip to content
This repository was archived by the owner on Oct 31, 2023. It is now read-only.

Commit 0375fef

Browse files
committed
Merge pull request #5 from craiglittle/craig/raise-exception-before
Raise an exception when attempting to insert before an invalid middleware
2 parents f5a5ea8 + 5b7843d commit 0375fef

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/middleware/builder.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def use(middleware, *args, &block)
6767
# given middleware object.
6868
def insert(index, middleware, *args, &block)
6969
index = self.index(index) unless index.is_a?(Integer)
70+
raise "no such middleware to insert before: #{index.inspect}" unless index
7071
stack.insert(index, [middleware, args, block])
7172
end
7273

spec/middleware/builder_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ def appender_proc(data)
9090
data[:data].should == [2, 1]
9191
end
9292

93+
it "raises an exception if attempting to insert before an invalid object" do
94+
expect { instance.insert "object", appender_proc(1) }.
95+
to raise_error(RuntimeError)
96+
end
97+
9398
it "can insert after" do
9499
instance.use appender_proc(1)
95100
instance.use appender_proc(3)
@@ -99,7 +104,7 @@ def appender_proc(data)
99104
data[:data].should == [1, 2, 3]
100105
end
101106

102-
it "raises an exception if an invalid object given" do
107+
it "raises an exception if attempting to insert after an invalid object" do
103108
expect { instance.insert_after "object", appender_proc(1) }.
104109
to raise_error(RuntimeError)
105110
end

0 commit comments

Comments
 (0)