Skip to content

Commit e242853

Browse files
committed
! Fix cucumber for ruby 3.4
1 parent 233b08f commit e242853

File tree

5 files changed

+254
-3
lines changed

5 files changed

+254
-3
lines changed

.github/workflows/tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ jobs:
4747
ruby-version: ${{ matrix.ruby }}
4848
bundler-cache: true
4949
- name: Test
50-
run: "bundle exec rspec && bundle exec cucumber || $ALLOW_FAILURES"
50+
run: "bundle exec rspec && bundle exec rake cucumber || $ALLOW_FAILURES"

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ group :test do
99
if RUBY_VERSION >= "3.4"
1010
# Cucumber is broken on Ruby 3.4, requires the fix in
1111
# https://github.com/cucumber/cucumber-ruby/pull/1757
12-
gem "cucumber", ">= 9.2", git: "https://github.com/cucumber/cucumber-ruby"
12+
gem "cucumber", ">= 9.2", git: "https://github.com/cucumber/cucumber-ruby", ref: "a468bc682eec68ef5b5660a17c4c0e7e52cfc67b"
1313
else
1414
gem "cucumber", "~> 9.2"
1515
end

Rakefile

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
task :default => [:spec]
44

5+
task :cucumber do
6+
if RUBY_VERSION >= "3.4"
7+
sh "cucumber --tags 'not @before_ruby_3_3'"
8+
else
9+
sh "cucumber --tags 'not @after_ruby_3_4'"
10+
end
11+
end
12+
513
task :add_tag do
614
`git tag -a v#{Contracts::VERSION} -m 'v#{Contracts::VERSION}'`
715
end

features/basics/pretty-print.feature features/basics/pretty-print_@before_ruby_3_3.feature

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Feature: Pretty printing Contract violations
1+
@before_ruby_3_3
2+
Feature: Pretty printing Contract violations (Ruby 3.3-)
23

34
Scenario: Big array argument being passed to big array method parameter
45
Given a file named "example.rb" with:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
@after_ruby_3_4
2+
Feature: Pretty printing Contract violations (Ruby 3.4+)
3+
4+
Scenario: Big array argument being passed to big array method parameter
5+
Given a file named "example.rb" with:
6+
"""ruby
7+
require "contracts"
8+
C = Contracts
9+
10+
class Example
11+
include Contracts::Core
12+
13+
class << self
14+
Contract [
15+
C::Or[String, Symbol],
16+
C::Or[String, Symbol],
17+
C::Or[String, Symbol],
18+
C::Or[String, Symbol],
19+
C::Or[String, Symbol],
20+
C::Or[String, Symbol],
21+
C::Or[String, Symbol]
22+
] => nil
23+
def run(data)
24+
nil
25+
end
26+
end
27+
end
28+
29+
puts Example.run([
30+
["foo", "foo"],
31+
["foo", "foo"],
32+
["foo", "foo"],
33+
["foo", "foo"],
34+
["foo", "foo"],
35+
["foo", "foo"],
36+
["foo", "foo"],
37+
["foo", "foo"],
38+
["foo", "foo"]
39+
])
40+
"""
41+
When I run `ruby example.rb`
42+
Then the output should contain:
43+
"""
44+
: Contract violation for argument 1 of 1: (ParamContractError)
45+
Expected: [(String or Symbol),
46+
(String or Symbol),
47+
(String or Symbol),
48+
(String or Symbol),
49+
(String or Symbol),
50+
(String or Symbol),
51+
(String or Symbol)],
52+
Actual: [["foo", "foo"],
53+
["foo", "foo"],
54+
["foo", "foo"],
55+
["foo", "foo"],
56+
["foo", "foo"],
57+
["foo", "foo"],
58+
["foo", "foo"],
59+
["foo", "foo"],
60+
["foo", "foo"]]
61+
Value guarded in: Example::run
62+
With Contract: Array => NilClass
63+
At: example.rb:17
64+
"""
65+
66+
Scenario: Big array value being returned from method expecting different big array type
67+
Given a file named "example.rb" with:
68+
"""ruby
69+
require "contracts"
70+
C = Contracts
71+
72+
class Example
73+
include Contracts::Core
74+
75+
class << self
76+
Contract C::None => [
77+
C::Or[String, Symbol],
78+
C::Or[String, Symbol],
79+
C::Or[String, Symbol],
80+
C::Or[String, Symbol],
81+
C::Or[String, Symbol],
82+
C::Or[String, Symbol],
83+
C::Or[String, Symbol]
84+
]
85+
def run
86+
[
87+
["foo", "foo"],
88+
["foo", "foo"],
89+
["foo", "foo"],
90+
["foo", "foo"],
91+
["foo", "foo"],
92+
["foo", "foo"],
93+
["foo", "foo"],
94+
["foo", "foo"],
95+
["foo", "foo"]
96+
]
97+
end
98+
end
99+
end
100+
101+
puts Example.run
102+
"""
103+
When I run `ruby example.rb`
104+
Then the output should contain:
105+
"""
106+
: Contract violation for return value: (ReturnContractError)
107+
Expected: [(String or Symbol),
108+
(String or Symbol),
109+
(String or Symbol),
110+
(String or Symbol),
111+
(String or Symbol),
112+
(String or Symbol),
113+
(String or Symbol)],
114+
Actual: [["foo", "foo"],
115+
["foo", "foo"],
116+
["foo", "foo"],
117+
["foo", "foo"],
118+
["foo", "foo"],
119+
["foo", "foo"],
120+
["foo", "foo"],
121+
["foo", "foo"],
122+
["foo", "foo"]]
123+
Value guarded in: Example::run
124+
With Contract: None => Array
125+
At: example.rb:17
126+
"""
127+
128+
Scenario: Big hash argument being passed to big hash method parameter
129+
Given a file named "example.rb" with:
130+
"""ruby
131+
require "contracts"
132+
C = Contracts
133+
134+
class Example
135+
include Contracts::Core
136+
137+
class << self
138+
Contract ({
139+
a: C::Or[String, Symbol],
140+
b: C::Or[String, Symbol],
141+
c: C::Or[String, Symbol],
142+
d: C::Or[String, Symbol],
143+
e: C::Or[String, Symbol],
144+
f: C::Or[String, Symbol],
145+
g: C::Or[String, Symbol]
146+
}) => nil
147+
def run(data)
148+
nil
149+
end
150+
end
151+
end
152+
153+
puts Example.run({
154+
a: ["foo", "foo"],
155+
b: ["foo", "foo"],
156+
c: ["foo", "foo"],
157+
d: ["foo", "foo"],
158+
e: ["foo", "foo"],
159+
f: ["foo", "foo"],
160+
g: ["foo", "foo"]
161+
})
162+
"""
163+
When I run `ruby example.rb`
164+
Then the output should contain:
165+
"""
166+
: Contract violation for argument 1 of 1: (ParamContractError)
167+
Expected: {a: (String or Symbol),
168+
b: (String or Symbol),
169+
c: (String or Symbol),
170+
d: (String or Symbol),
171+
e: (String or Symbol),
172+
f: (String or Symbol),
173+
g: (String or Symbol)},
174+
Actual: {a: ["foo", "foo"],
175+
b: ["foo", "foo"],
176+
c: ["foo", "foo"],
177+
d: ["foo", "foo"],
178+
e: ["foo", "foo"],
179+
f: ["foo", "foo"],
180+
g: ["foo", "foo"]}
181+
Value guarded in: Example::run
182+
With Contract: Hash => NilClass
183+
At: example.rb:17
184+
"""
185+
186+
Scenario: Big hash value being returned from method expecting different big hash type
187+
Given a file named "example.rb" with:
188+
"""ruby
189+
require "contracts"
190+
C = Contracts
191+
192+
class Example
193+
include Contracts::Core
194+
195+
class << self
196+
Contract C::None => ({
197+
a: C::Or[String, Symbol],
198+
b: C::Or[String, Symbol],
199+
c: C::Or[String, Symbol],
200+
d: C::Or[String, Symbol],
201+
e: C::Or[String, Symbol],
202+
f: C::Or[String, Symbol],
203+
g: C::Or[String, Symbol]
204+
})
205+
def run
206+
{
207+
a: ["foo", "foo"],
208+
b: ["foo", "foo"],
209+
c: ["foo", "foo"],
210+
d: ["foo", "foo"],
211+
e: ["foo", "foo"],
212+
f: ["foo", "foo"],
213+
g: ["foo", "foo"]
214+
}
215+
end
216+
end
217+
end
218+
219+
puts Example.run
220+
"""
221+
When I run `ruby example.rb`
222+
Then the output should contain:
223+
"""
224+
: Contract violation for return value: (ReturnContractError)
225+
Expected: {a: (String or Symbol),
226+
b: (String or Symbol),
227+
c: (String or Symbol),
228+
d: (String or Symbol),
229+
e: (String or Symbol),
230+
f: (String or Symbol),
231+
g: (String or Symbol)},
232+
Actual: {a: ["foo", "foo"],
233+
b: ["foo", "foo"],
234+
c: ["foo", "foo"],
235+
d: ["foo", "foo"],
236+
e: ["foo", "foo"],
237+
f: ["foo", "foo"],
238+
g: ["foo", "foo"]}
239+
Value guarded in: Example::run
240+
With Contract: None => Hash
241+
At: example.rb:17
242+
"""

0 commit comments

Comments
 (0)