summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-11-13 22:15:57 +1300
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-11-14 21:53:41 +1300
commit927ff4493f2969ac8aa5980fa9cdaa6450220a2b (patch)
treebb3b9c1e45008585be36d6b631dd1865259fdbad
parent2b763e0fae748bc942a625abf5a1a243237fa674 (diff)
downloadrack-remove-execution-variables.tar.gz
Add support for default app (404).remove-execution-variables
-rw-r--r--lib/rack/builder.rb6
-rw-r--r--test/spec_builder.rb7
2 files changed, 7 insertions, 6 deletions
diff --git a/lib/rack/builder.rb b/lib/rack/builder.rb
index 6f2ab0aa..fa64ae3e 100644
--- a/lib/rack/builder.rb
+++ b/lib/rack/builder.rb
@@ -109,10 +109,12 @@ module Rack
return builder.to_app
end
+ DEFAULT_APP = proc{|env| [404, [], []]}
+
# Initialize a new Rack::Builder instance. +default_app+ specifies the
# default application if +run+ is not called later. If a block
# is given, it is evaluted in the context of the instance.
- def initialize(default_app = nil, **options, &block)
+ def initialize(default_app = DEFAULT_APP, **options, &block)
@use = []
@map = nil
@run = default_app
@@ -247,8 +249,8 @@ module Rack
# Return the Rack application generated by this instance.
def to_app
app = @map ? generate_map(@run, @map) : @run
- fail "missing run or map statement" unless app
app.freeze if @freeze_app
+
app = @use.reverse.inject(app) { |a, e| e[a].tap { |x| x.freeze if @freeze_app } }
@warmup.call(app) if @warmup
app
diff --git a/test/spec_builder.rb b/test/spec_builder.rb
index eb13a976..3fcc9933 100644
--- a/test/spec_builder.rb
+++ b/test/spec_builder.rb
@@ -218,10 +218,9 @@ describe Rack::Builder do
Rack::MockRequest.new(app).get("/c").status.must_equal 200
end
- it 'complains about a missing run' do
- proc do
- Rack::Lint.new Rack::Builder.app { use Rack::ShowExceptions }
- end.must_raise(RuntimeError)
+ it 'should result in the default app' do
+ app = Rack::Builder.new.to_app
+ app.must_equal Rack::Builder::DEFAULT_APP
end
describe "parse_file" do