Fix `use` with keyword arguments for Ruby 3.0 (#1701)

The added test case would, prior to the fix, fail, under Ruby 3.0, with the following error:

```
MiddlewareTest#test_handles_keyword_arguments_0:
ArgumentError: wrong number of arguments (given 2, expected 1)
```

The change itself was inspired by https://github.com/rack/rack/pull/1505
This commit is contained in:
Robin Wallin 2021-06-02 18:20:44 +02:00 committed by GitHub
parent c33c2b1a00
commit 0a50b5608d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -1471,6 +1471,7 @@ module Sinatra
@prototype = nil
@middleware << [middleware, args, block]
end
ruby2_keywords(:use) if respond_to?(:ruby2_keywords, true)
# Stop the self-hosted server if running.
def quit!

View File

@ -97,4 +97,14 @@ class MiddlewareTest < Minitest::Test
get '/'
end
class KeywordArgumentIntializationMiddleware < MockMiddleware
def initialize(app, **)
super app
end
end
it "handles keyword arguments" do
@app.use KeywordArgumentIntializationMiddleware, argument: "argument"
get '/'
end
end