Skip to content

Commit f66a0d7

Browse files
authored
Fix test suite compatibility with Grape 4.0 (grape=HEAD CI) (#982)
The grape=HEAD canary CI job tracks Grape's development branch to catch breaking changes before they land in a release. It started failing because Grape 4.0 changed three internal constructor signatures that the test helpers rely on: - Grape::Router::Pattern.new dropped the format: keyword - Grape::Router::Route.new promoted forward_match from an options-hash entry to a required keyword argument - Grape::Endpoint.new replaced method:/for: with http_methods:/api: Add a GrapeVersion.satisfy?('>= 4.0.0') branch in spec/support/route_helper.rb and spec/lib/endpoint_spec.rb to use the new call shapes against Grape HEAD while leaving existing behavior untouched for the supported pinned range (2.1–3.x).
1 parent 76dd115 commit f66a0d7

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#### Fixes
99

1010
* [#978](https://github.com/ruby-grape/grape-swagger/pull/978): Fix Grape 3.2+ compatibility: desc kwargs, custom types, multi-type param recovery; bump Grape to `>= 2.1, < 5.0`. See [UPGRADING](UPGRADING.md) - [@numbata](https://github.com/numbata).
11+
* [#982](https://github.com/ruby-grape/grape-swagger/pull/982): Fix test suite compatibility with Grape 4.0 (grape=HEAD CI) - [@numbata](https://github.com/numbata).
1112
* Your contribution here.
1213

1314
### 2.1.4 (2026-02-02)

spec/lib/endpoint_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
describe Grape::Endpoint do
66
subject do
7-
# Grape >= HEAD requires :for (the owner API class) when constructing an Endpoint.
8-
described_class.new(Grape::Util::InheritableSetting.new, path: '/', method: :get, for: Class.new(Grape::API))
7+
if GrapeVersion.satisfy?('>= 4.0.0')
8+
# Grape >= 4.0 requires :http_methods and :api (the owner API class) when constructing an Endpoint.
9+
described_class.new(Grape::Util::InheritableSetting.new, path: '/', http_methods: :get, api: Class.new(Grape::API))
10+
else
11+
described_class.new(Grape::Util::InheritableSetting.new, path: '/', method: :get, for: Class.new(Grape::API))
12+
end
913
end
1014

1115
describe '.content_types_for' do

spec/support/route_helper.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22

33
module RouteHelper
44
def self.build(method:, pattern:, options:, origin: nil)
5-
if GrapeVersion.satisfy?('>= 3.1.0')
5+
if GrapeVersion.satisfy?('>= 4.0.0')
6+
pattern_obj = Grape::Router::Pattern.new(
7+
origin: origin || pattern,
8+
suffix: nil,
9+
anchor: options.fetch(:anchor, true),
10+
params: options.fetch(:params, {}),
11+
version: nil,
12+
requirements: options.fetch(:requirements, {})
13+
)
14+
Grape::Router::Route.new(nil, method, pattern_obj, options, forward_match: options.fetch(:forward_match, false))
15+
elsif GrapeVersion.satisfy?('>= 3.1.0')
616
pattern_obj = Grape::Router::Pattern.new(
717
origin: origin || pattern,
818
suffix: nil,

0 commit comments

Comments
 (0)