Declare `required_ruby_version` to be Ruby 3.1
This is only documented in the Readme.
3.0.0 now depends on pattern matching, which is (partially) invalid syntax on 2.7. The test-unit gem depends on power_assert and tries to handle that by catching SyntaxError: https://github.com/test-unit/test-unit/blob/edfa50cf4fef5521f34dca1995c1c8f3efe77d7b/lib/test/unit/assertions.rb#L12-L18 That seems to have worked ok previously but now it leaves the PowerAssert module behind, among other things. test-unit cleans that up via https://github.com/test-unit/test-unit/pull/329 but there are other side-effects it can do nothing about.
For example, an undefined new method:
/Users/runner/hostedtoolcache/Ruby/2.7.8/arm64/lib/ruby/gems/2.7.0/gems/onigmo-0.1.0/lib/onigmo/node.rb:27:in
private_class_method': undefined methodnew' for class `#Class:Onigmo::Node' (NameError) Did you mean? next
Now, bundler will always fall back to 3.0.0 even if this gets released as 3.0.0. But eventually it will help for future version bumps.
Thanks for reporting!
For now, I'd prefer not to define required_ruby_version. I think power_assert should remain optional in something like test-unit, and I don't want to impose dependency requirements on users just for that. I'd like to find a smarter way to handle this. (Of course, the easiest fix would be to just remove power_assert from test-unit's dependencies and make it truly optional, but that would only make things less convenient for most users.)
I guess the following patch resolves the issue. I'll check it later.
diff --git i/lib/power_assert.rb w/lib/power_assert.rb
index 8de209e..0be9b5d 100644
--- i/lib/power_assert.rb
+++ w/lib/power_assert.rb
@@ -17,6 +17,7 @@
raise LoadError, 'Fully compatible TracePoint API required'
end
+require 'power_assert/parser'
require 'power_assert/context'
require 'power_assert/configuration'
require 'power_assert/version'
I don't entirely understand your reasoning. This gem does not work on older rubies, why allow installating it on them?
By specifying it, older versions will be resolved that actually work on the ruby version that the user is running. It's true that practically power_assert is "optional" for test-unit insofar that it tries to do nothing when it fails to load because of syntax errors. But that should not be the workflow. SyntaxErrors are easy to catch, what if something goes wrong at runtime? Your proposed patch moves the syntax error earlier but it seemingly still works on ruby 3.0, which you claim no support for
Of course, the easiest fix would be to just remove power_assert from test-unit's dependencies and make it truly optional
I'd still have to apply workarounds like @byroot did with https://github.com/ruby/json/commit/2b8f853589a5898bbfddb5286d59f191ddd66ef9 or simply skip the gem entirely.
If you are dead-set on not specifying it, an early return in the entrypoint like return if RUBY_VERSION < '3.1.0' should give you the least trouble. Then you don't have to bother with any side-effects
The lack of required_ruby_version for power_assert is also causing failures in Psych's CI on Ruby 2.5 and 2.7:
https://github.com/ruby/psych/actions/runs/19099038401/job/54566189010?pr=749
On 2.5:
| /opt/hostedtoolcache/Ruby/2.5.9/x64/lib/ruby/gems/2.5.0/gems/power_assert-3.0.0/lib/power_assert/parser.rb:146: warning: else without rescue is useless
| /opt/hostedtoolcache/Ruby/2.5.9/x64/lib/ruby/gems/2.5.0/gems/power_assert-3.0.0/lib/power_assert/parser.rb:146: warning: else without rescue is useless
On 2.7:
| /opt/hostedtoolcache/Ruby/2.7.8/x64/lib/ruby/gems/2.7.0/gems/power_assert-3.0.0/lib/power_assert/parser.rb:106: warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!
| /opt/hostedtoolcache/Ruby/2.7.8/x64/lib/ruby/gems/2.7.0/gems/power_assert-3.0.0/lib/power_assert/parser.rb:106: warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!
(Of course, the easiest fix would be to just remove power_assert from test-unit's dependencies and make it truly optional, but that would only make things less convenient for most users.)
I think most users of test-unit do not use power_assert, so I think this would be a good fix.
https://github.com/ruby/power_assert/releases/tag/v3.0.1
FYI: https://github.com/ruby/test-unit-ruby-core/pull/21
adding
required_ruby_versionto power_assert causes to fail the installation with old rubygems