Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use with keyword arguments for Ruby 3.0 #1701

Merged
merged 1 commit into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix use with keyword arguments for Ruby 3.0
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 rack/rack#1505
  • Loading branch information
walro committed May 28, 2021
commit 71b91597b0e043e7d182e55c53e5e08b67413c66
1 change: 1 addition & 0 deletions lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,7 @@ def use(middleware, *args, &block)
@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!
Expand Down
10 changes: 10 additions & 0 deletions test/middleware_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,14 @@ def call(env)
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