Skip to content

Commit

Permalink
Add test to make sure Rack::Builder#call always create a new app
Browse files Browse the repository at this point in the history
This behavior is there for use cases like the Rack::Reloader. If you
need to cache the app it is better to call `to_app` when needed or use
`Rack::Builder.app`.

Closes #834
  • Loading branch information
rafaelfranca committed Nov 7, 2017
1 parent e6a1515 commit ab00830
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/spec_builder.rb
Expand Up @@ -55,6 +55,19 @@ def builder_to_app(&block)
NothingMiddleware.env['new_key'].must_equal 'new_value'
end

it "dupe #to_app when mapping so Rack::Reloader can reload the application on each request" do
app = builder do
map '/' do |outer_env|
run lambda { |env| [200, {"Content-Type" => "text/plain"}, [object_id.to_s]] }
end
end

builder_app1_id = Rack::MockRequest.new(app).get("/").body.to_s
builder_app2_id = Rack::MockRequest.new(app).get("/").body.to_s

builder_app2_id.wont_equal builder_app1_id
end

it "chains apps by default" do
app = builder_to_app do
use Rack::ShowExceptions
Expand Down

0 comments on commit ab00830

Please sign in to comment.