Skip to content

Commit

Permalink
! Fix cucumber for ruby 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
PikachuEXE committed Dec 26, 2024
1 parent 233b08f commit e242853
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Test
run: "bundle exec rspec && bundle exec cucumber || $ALLOW_FAILURES"
run: "bundle exec rspec && bundle exec rake cucumber || $ALLOW_FAILURES"
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ group :test do
if RUBY_VERSION >= "3.4"
# Cucumber is broken on Ruby 3.4, requires the fix in
# https://github.com/cucumber/cucumber-ruby/pull/1757
gem "cucumber", ">= 9.2", git: "https://github.com/cucumber/cucumber-ruby"
gem "cucumber", ">= 9.2", git: "https://github.com/cucumber/cucumber-ruby", ref: "a468bc682eec68ef5b5660a17c4c0e7e52cfc67b"
else
gem "cucumber", "~> 9.2"
end
Expand Down
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

task :default => [:spec]

task :cucumber do
if RUBY_VERSION >= "3.4"
sh "cucumber --tags 'not @before_ruby_3_3'"
else
sh "cucumber --tags 'not @after_ruby_3_4'"
end
end

task :add_tag do
`git tag -a v#{Contracts::VERSION} -m 'v#{Contracts::VERSION}'`
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Feature: Pretty printing Contract violations
@before_ruby_3_3
Feature: Pretty printing Contract violations (Ruby 3.3-)

Scenario: Big array argument being passed to big array method parameter
Given a file named "example.rb" with:
Expand Down
242 changes: 242 additions & 0 deletions features/basics/pretty-print_after_ruby_3_4.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
@after_ruby_3_4
Feature: Pretty printing Contract violations (Ruby 3.4+)

Scenario: Big array argument being passed to big array method parameter
Given a file named "example.rb" with:
"""ruby
require "contracts"
C = Contracts
class Example
include Contracts::Core
class << self
Contract [
C::Or[String, Symbol],
C::Or[String, Symbol],
C::Or[String, Symbol],
C::Or[String, Symbol],
C::Or[String, Symbol],
C::Or[String, Symbol],
C::Or[String, Symbol]
] => nil
def run(data)
nil
end
end
end
puts Example.run([
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"]
])
"""
When I run `ruby example.rb`
Then the output should contain:
"""
: Contract violation for argument 1 of 1: (ParamContractError)
Expected: [(String or Symbol),
(String or Symbol),
(String or Symbol),
(String or Symbol),
(String or Symbol),
(String or Symbol),
(String or Symbol)],
Actual: [["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"]]
Value guarded in: Example::run
With Contract: Array => NilClass
At: example.rb:17
"""

Scenario: Big array value being returned from method expecting different big array type
Given a file named "example.rb" with:
"""ruby
require "contracts"
C = Contracts
class Example
include Contracts::Core
class << self
Contract C::None => [
C::Or[String, Symbol],
C::Or[String, Symbol],
C::Or[String, Symbol],
C::Or[String, Symbol],
C::Or[String, Symbol],
C::Or[String, Symbol],
C::Or[String, Symbol]
]
def run
[
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"]
]
end
end
end
puts Example.run
"""
When I run `ruby example.rb`
Then the output should contain:
"""
: Contract violation for return value: (ReturnContractError)
Expected: [(String or Symbol),
(String or Symbol),
(String or Symbol),
(String or Symbol),
(String or Symbol),
(String or Symbol),
(String or Symbol)],
Actual: [["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"],
["foo", "foo"]]
Value guarded in: Example::run
With Contract: None => Array
At: example.rb:17
"""

Scenario: Big hash argument being passed to big hash method parameter
Given a file named "example.rb" with:
"""ruby
require "contracts"
C = Contracts
class Example
include Contracts::Core
class << self
Contract ({
a: C::Or[String, Symbol],
b: C::Or[String, Symbol],
c: C::Or[String, Symbol],
d: C::Or[String, Symbol],
e: C::Or[String, Symbol],
f: C::Or[String, Symbol],
g: C::Or[String, Symbol]
}) => nil
def run(data)
nil
end
end
end
puts Example.run({
a: ["foo", "foo"],
b: ["foo", "foo"],
c: ["foo", "foo"],
d: ["foo", "foo"],
e: ["foo", "foo"],
f: ["foo", "foo"],
g: ["foo", "foo"]
})
"""
When I run `ruby example.rb`
Then the output should contain:
"""
: Contract violation for argument 1 of 1: (ParamContractError)
Expected: {a: (String or Symbol),
b: (String or Symbol),
c: (String or Symbol),
d: (String or Symbol),
e: (String or Symbol),
f: (String or Symbol),
g: (String or Symbol)},
Actual: {a: ["foo", "foo"],
b: ["foo", "foo"],
c: ["foo", "foo"],
d: ["foo", "foo"],
e: ["foo", "foo"],
f: ["foo", "foo"],
g: ["foo", "foo"]}
Value guarded in: Example::run
With Contract: Hash => NilClass
At: example.rb:17
"""

Scenario: Big hash value being returned from method expecting different big hash type
Given a file named "example.rb" with:
"""ruby
require "contracts"
C = Contracts
class Example
include Contracts::Core
class << self
Contract C::None => ({
a: C::Or[String, Symbol],
b: C::Or[String, Symbol],
c: C::Or[String, Symbol],
d: C::Or[String, Symbol],
e: C::Or[String, Symbol],
f: C::Or[String, Symbol],
g: C::Or[String, Symbol]
})
def run
{
a: ["foo", "foo"],
b: ["foo", "foo"],
c: ["foo", "foo"],
d: ["foo", "foo"],
e: ["foo", "foo"],
f: ["foo", "foo"],
g: ["foo", "foo"]
}
end
end
end
puts Example.run
"""
When I run `ruby example.rb`
Then the output should contain:
"""
: Contract violation for return value: (ReturnContractError)
Expected: {a: (String or Symbol),
b: (String or Symbol),
c: (String or Symbol),
d: (String or Symbol),
e: (String or Symbol),
f: (String or Symbol),
g: (String or Symbol)},
Actual: {a: ["foo", "foo"],
b: ["foo", "foo"],
c: ["foo", "foo"],
d: ["foo", "foo"],
e: ["foo", "foo"],
f: ["foo", "foo"],
g: ["foo", "foo"]}
Value guarded in: Example::run
With Contract: None => Hash
At: example.rb:17
"""

0 comments on commit e242853

Please sign in to comment.