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

minitest/mock emits "redefining object_id" warning on Ruby head #1019

Open
mattbrictson opened this issue Nov 2, 2024 · 1 comment
Open
Assignees

Comments

@mattbrictson
Copy link

mattbrictson commented Nov 2, 2024

When I use minitest/mock on the latest build of Ruby 3.4.0dev, I see this warning:

minitest/mock.rb:33: warning: redefining 'object_id' may cause serious problems

This warning can be demonstrated by running minitest's CI workflow on the master branch, specifically the test ubuntu-latest head job. Here is an example:

https://github.com/mattbrictson/minitest/actions/runs/11638307079/job/32412919800#step:5:5

Edit: here's a concise reproduction using just irb:

irb(main):001> RUBY_DESCRIPTION
=> "ruby 3.4.0dev (2024-11-01T14:49:50Z master c7708d22c3) +PRISM [arm64-darwin24]"
irb(main):002> require "minitest/mock"
/Users/mbrictson/.rbenv/versions/ruby-dev/lib/ruby/gems/3.4.0+0/gems/minitest-5.25.1/lib/minitest/mock.rb:33: warning: redefining 'object_id' may cause serious problems
=> true
@zenspider
Copy link
Collaborator

Sadly, the best I can come up with is to disable warnings during the offense:

--- //src/minitest/dev/lib/minitest/mock.rb	2024-07-30 23:54:25.000000000 -0700
+++ /Users/ryan/Work/p4/zss/src/minitest/dev/lib/minitest/mock.rb	2024-07-30 23:54:25.000000000 -0700
@@ -30,6 +30,7 @@
     end
 
     overridden_methods.map(&:to_sym).each do |method_id|
+      old_w, $-w = $-w, nil
       define_method method_id do |*args, **kwargs, &b|
         if @expected_calls.key? method_id then
           if kwargs.empty? then # FIX: drop this after 2.7 dead
@@ -45,6 +46,8 @@
           end
         end
       end
+    ensure
+      $-w = old_w
     end
 
     def initialize delegator = nil # :nodoc:

@zenspider zenspider self-assigned this Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants