Skip to content

Commit

Permalink
Fix use with keyword arguments for Ruby 3.0 (#1701)
Browse files Browse the repository at this point in the history
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 Jun 2, 2021
1 parent c33c2b1 commit 0a50b56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/sinatra/base.rb
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
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

0 comments on commit 0a50b56

Please sign in to comment.