Skip to content

Commit 2be40a5

Browse files
authored
Add Ruby 3.4 support (#459)
* Add Ruby 3.4's Hash#inspect symbol change * Add Ruby 3.4 to CI matrix * Add empty line for consistency * Add Ruby 3.4's Hash#inspect symbol change for integration test * Remove duplicate lines
1 parent 7b82098 commit 2be40a5

File tree

4 files changed

+102
-16
lines changed

4 files changed

+102
-16
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
ruby:
17+
- "3.4"
1718
- "3.3"
1819
- "3.2"
1920
- "3.1"

spec/integration/hanami/controller/flash_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ def app
1313
get "/"
1414
follow_redirect!
1515

16-
expect(last_response.body).to match(/{:hello=>"world"}/)
16+
if RUBY_VERSION < "3.4"
17+
expect(last_response.body).to match(/{:hello=>"world"}/)
18+
else
19+
expect(last_response.body).to match(/{hello: "world"}/)
20+
end
21+
1722
expect(last_response.body).to match(/flash_empty: false/)
1823
end
1924

spec/unit/hanami/action/contract_spec.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
response = action.call("birth_date" => "2000-01-01")
1212

1313
expect(response.status).to eq 302
14-
expect(response.body).to eq ["{:errors=>{:book=>[\"is missing\"], :birth_date=>[\"you must be 18 years or older\"]}}"]
14+
15+
if RUBY_VERSION < "3.4"
16+
expect(response.body).to eq ["{:errors=>{:book=>[\"is missing\"], :birth_date=>[\"you must be 18 years or older\"]}}"]
17+
else
18+
expect(response.body).to eq ["{errors: {book: [\"is missing\"], birth_date: [\"you must be 18 years or older\"]}}"]
19+
end
1520
end
1621
end
1722

@@ -33,7 +38,12 @@
3338
response = action.call("birth_date" => "2000-01-01")
3439

3540
expect(response.status).to eq 302
36-
expect(response.body).to eq ["{:errors=>{:book=>[\"is missing\"], :birth_date=>[\"you must be 18 years or older\"]}}"]
41+
42+
if RUBY_VERSION < "3.4"
43+
expect(response.body).to eq ["{:errors=>{:book=>[\"is missing\"], :birth_date=>[\"you must be 18 years or older\"]}}"]
44+
else
45+
expect(response.body).to eq ["{errors: {book: [\"is missing\"], birth_date: [\"you must be 18 years or older\"]}}"]
46+
end
3747
end
3848
end
3949

@@ -55,7 +65,12 @@
5565
response = action.call("birth_date" => "2000-01-01")
5666

5767
expect(response.status).to eq 302
58-
expect(response.body).to eq ["{:errors=>{:book=>[\"is missing\"], :birth_date=>[\"you must be 18 years or older\"]}}"]
68+
69+
if RUBY_VERSION < "3.4"
70+
expect(response.body).to eq ["{:errors=>{:book=>[\"is missing\"], :birth_date=>[\"you must be 18 years or older\"]}}"]
71+
else
72+
expect(response.body).to eq ["{errors: {book: [\"is missing\"], birth_date: [\"you must be 18 years or older\"]}}"]
73+
end
5974
end
6075
end
6176

spec/unit/hanami/action/params_spec.rb

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,38 @@
6262
# For unit tests in Hanami projects, developers may want to define
6363
# params with symbolized keys.
6464
response = action.call(a: "1", b: "2", c: "3")
65-
expect(response.body).to eq([%({:a=>"1", :b=>"2", :c=>"3"})])
65+
66+
if RUBY_VERSION < "3.4"
67+
expect(response.body).to eq([%({:a=>"1", :b=>"2", :c=>"3"})])
68+
else
69+
expect(response.body).to eq([%({a: "1", b: "2", c: "3"})])
70+
end
6671
end
6772
end
6873

6974
context "in a Rack context" do
7075
it "returns all the params as they are" do
7176
# Rack params are always stringified
7277
response = Rack::MockRequest.new(action).request("PATCH", "?id=23", params: {"x" => {"foo" => "bar"}})
73-
expect(response.body).to match(%({:id=>"23", :x=>{:foo=>"bar"}}))
78+
79+
if RUBY_VERSION < "3.4"
80+
expect(response.body).to eq(%({:id=>"23", :x=>{:foo=>"bar"}}))
81+
else
82+
expect(response.body).to eq(%({id: "23", x: {foo: "bar"}}))
83+
end
7484
end
7585
end
7686

7787
context "with Hanami::Router" do
7888
it "returns all the params as they are" do
7989
# Hanami::Router params are always symbolized
8090
response = action.call("router.params" => {id: "23"})
81-
expect(response.body).to eq([%({:id=>"23"})])
91+
92+
if RUBY_VERSION < "3.4"
93+
expect(response.body).to eq([%({:id=>"23"})])
94+
else
95+
expect(response.body).to eq([%({id: "23"})])
96+
end
8297
end
8398
end
8499
end
@@ -92,7 +107,12 @@
92107
context "in testing mode" do
93108
it "returns only the listed params" do
94109
response = action.call(id: 23, unknown: 4, article: {foo: "bar", tags: [:cool]})
95-
expect(response.body).to eq([%({:id=>23, :article=>{:tags=>[:cool]}})])
110+
111+
if RUBY_VERSION < "3.4"
112+
expect(response.body).to eq([%({:id=>23, :article=>{:tags=>[:cool]}})])
113+
else
114+
expect(response.body).to eq([%({id: 23, article: {tags: [:cool]}})])
115+
end
96116
end
97117

98118
it "removes _csrf_token" do
@@ -104,20 +124,35 @@
104124
context "in a Rack context" do
105125
it "returns only the listed params" do
106126
response = Rack::MockRequest.new(action).request("PATCH", "?id=23", params: {x: {foo: "bar"}})
107-
expect(response.body).to match(%({:id=>23}))
127+
128+
if RUBY_VERSION < "3.4"
129+
expect(response.body).to match(%({:id=>23}))
130+
else
131+
expect(response.body).to match(%({id: 23}))
132+
end
108133
end
109134

110135
it "removes _csrf_token" do
111136
response = Rack::MockRequest.new(action).request("PATCH", "?id=1", params: {_csrf_token: "def", x: {foo: "bar"}})
112137
expect(response.body).not_to match("_csrf_token")
113-
expect(response.body).to match(%(:id=>1))
138+
139+
if RUBY_VERSION < "3.4"
140+
expect(response.body).to match(%({:id=>1}))
141+
else
142+
expect(response.body).to match(%({id: 1}))
143+
end
114144
end
115145
end
116146

117147
context "with Hanami::Router" do
118148
it "returns only the listed params" do
119149
response = action.call("router.params" => {id: 23, another: "x"})
120-
expect(response.body).to eq([%({:id=>23})])
150+
151+
if RUBY_VERSION < "3.4"
152+
expect(response.body).to eq([%({:id=>23})])
153+
else
154+
expect(response.body).to eq([%({id: 23})])
155+
end
121156
end
122157
end
123158
end
@@ -133,21 +168,36 @@
133168
context "in testing mode" do
134169
it "returns only the listed params" do
135170
response = action.call(username: "jodosha", unknown: "field")
136-
expect(response.body).to eq([%({:username=>"jodosha"})])
171+
172+
if RUBY_VERSION < "3.4"
173+
expect(response.body).to eq([%({:username=>"jodosha"})])
174+
else
175+
expect(response.body).to eq([%({username: "jodosha"})])
176+
end
137177
end
138178
end
139179

140180
context "in a Rack context" do
141181
it "returns only the listed params" do
142182
response = Rack::MockRequest.new(action).request("PATCH", "?username=jodosha", params: {x: {foo: "bar"}})
143-
expect(response.body).to match(%({:username=>"jodosha"}))
183+
184+
if RUBY_VERSION < "3.4"
185+
expect(response.body).to match(%({:username=>"jodosha"}))
186+
else
187+
expect(response.body).to match(%({username: "jodosha"}))
188+
end
144189
end
145190
end
146191

147192
context "with Hanami::Router" do
148193
it "returns only the listed params" do
149194
response = action.call("router.params" => {username: "jodosha", y: "x"})
150-
expect(response.body).to eq([%({:username=>"jodosha"})])
195+
196+
if RUBY_VERSION < "3.4"
197+
expect(response.body).to eq([%({:username=>"jodosha"})])
198+
else
199+
expect(response.body).to eq([%({username: "jodosha"})])
200+
end
151201
end
152202
end
153203
end
@@ -507,7 +557,17 @@
507557
it "raises error when try to add an error " do
508558
params = klass.new(env: {})
509559

510-
expect { params.errors.add(:book, :code, "is invalid") }.to raise_error(ArgumentError, %(Can't add :book, :code, "is invalid" to {:book=>["is missing"]}))
560+
if RUBY_VERSION < "3.4"
561+
expect { params.errors.add(:book, :code, "is invalid") }.to raise_error(
562+
ArgumentError,
563+
%(Can't add :book, :code, "is invalid" to {:book=>["is missing"]})
564+
)
565+
else
566+
expect { params.errors.add(:book, :code, "is invalid") }.to raise_error(
567+
ArgumentError,
568+
%(Can't add :book, :code, "is invalid" to {book: ["is missing"]})
569+
)
570+
end
511571
end
512572
end
513573

@@ -516,7 +576,12 @@
516576

517577
it "uses the params defined in the parent class" do
518578
response = action.call(id: 23, unknown: 4, article: {foo: "bar", tags: [:cool]})
519-
expect(response.body).to eq([%({:id=>23, :article=>{:tags=>[:cool]}})])
579+
580+
if RUBY_VERSION < "3.4"
581+
expect(response.body).to eq([%({:id=>23, :article=>{:tags=>[:cool]}})])
582+
else
583+
expect(response.body).to eq([%({id: 23, article: {tags: [:cool]}})])
584+
end
520585
end
521586
end
522587
end

0 commit comments

Comments
 (0)