diff options
-rw-r--r-- | lib/rack/builder.rb | 6 | ||||
-rw-r--r-- | test/spec_builder.rb | 7 |
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 |