Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rake test fails with ruby 3.2.0preview3 #590

Closed
mtasaka opened this issue Nov 23, 2022 · 5 comments
Closed

rake test fails with ruby 3.2.0preview3 #590

mtasaka opened this issue Nov 23, 2022 · 5 comments
Assignees

Comments

@mtasaka
Copy link

mtasaka commented Nov 23, 2022

With latest git mocha ( f4a858d ) rake test fails with ruby3.2preview3 like:

  1) Error:
RegexpMatchesTest#test_should_not_match_on_argument_that_does_not_respond_to_equals_tilde:
NameError: undefined method `=~' for class `#<Class:0x00007fbe4cb46b00>'
    /builddir/build/GIT/mocha/test/unit/parameter_matchers/regexp_matches_test.rb:41:in `block in test_should_not_match_on_argument_that_does_not_respond_to_equals_tilde'
    /builddir/build/GIT/mocha/test/unit/parameter_matchers/regexp_matches_test.rb:41:in `initialize'
    /builddir/build/GIT/mocha/test/unit/parameter_matchers/regexp_matches_test.rb:41:in `new'
    /builddir/build/GIT/mocha/test/unit/parameter_matchers/regexp_matches_test.rb:41:in `test_should_not_match_on_argument_that_does_not_respond_to_equals_tilde'

  2) Error:
RegexpMatchesTest#test_should_not_raise_error_on_argument_that_does_not_respond_to_equals_tilde:
NameError: undefined method `=~' for class `#<Class:0x00007fbe4cb45200>'
    /builddir/build/GIT/mocha/test/unit/parameter_matchers/regexp_matches_test.rb:35:in `block in test_should_not_raise_error_on_argument_that_does_not_respond_to_equals_tilde'
    /builddir/build/GIT/mocha/test/unit/parameter_matchers/regexp_matches_test.rb:35:in `initialize'
    /builddir/build/GIT/mocha/test/unit/parameter_matchers/regexp_matches_test.rb:35:in `new'
    /builddir/build/GIT/mocha/test/unit/parameter_matchers/regexp_matches_test.rb:35:in `test_should_not_raise_error_on_argument_that_does_not_respond_to_equals_tilde'

425 runs, 814 assertions, 0 failures, 2 errors, 0 skips

So test_should_not_raise_error_on_argument_that_does_not_respond_to_equals_tilde seems to test for object not responding to =~ , so it tries to create Class object then trying to undefine =~ method explicitly, however with ruby3.2 this makes error by:

https://github.com/ruby/ruby/blob/eaf2b6c4396ff19921cbc75a394d7a752aaab4ef/NEWS.md?plain=1#L306

@mtasaka
Copy link
Author

mtasaka commented Nov 23, 2022

Quick fix is:

diff --git a/test/unit/parameter_matchers/regexp_matches_test.rb b/test/unit/parameter_matchers/regexp_matches_test.rb
index e0282c8..9251054 100644
--- a/test/unit/parameter_matchers/regexp_matches_test.rb
+++ b/test/unit/parameter_matchers/regexp_matches_test.rb
@@ -32,13 +32,13 @@ class RegexpMatchesTest < Mocha::TestCase
   end
 
   def test_should_not_raise_error_on_argument_that_does_not_respond_to_equals_tilde
-    object_not_responding_to_equals_tilde = Class.new { undef =~ }.new
+    object_not_responding_to_equals_tilde = Class.new { undef =~ if respond_to?(:=~) }.new
     matcher = regexp_matches(/oo/)
     assert_nothing_raised { matcher.matches?([object_not_responding_to_equals_tilde]) }
   end
 
   def test_should_not_match_on_argument_that_does_not_respond_to_equals_tilde
-    object_not_responding_to_equals_tilde = Class.new { undef =~ }.new
+    object_not_responding_to_equals_tilde = Class.new { undef =~ if respond_to?(:=~) }.new
     matcher = regexp_matches(/oo/)
     assert !matcher.matches?([object_not_responding_to_equals_tilde])
   end

@floehopper
Copy link
Member

@mtasaka Thanks for reporting this. I will apply the patch you have suggested as soon as I have time.

@floehopper
Copy link
Member

Note to self: the change is explained in more detail here.

@floehopper
Copy link
Member

@mtasaka Sorry this took a while - I was unable to install Ruby v3.2.0-preview3 locally due to this issue. However, fortunately that version is available in CircleCI builds.

@floehopper
Copy link
Member

The fix for this was released in v2.0.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants