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 stub implementation changes a method's lookup to be on metaclass always #947

Open
luke-gru opened this issue Mar 13, 2023 · 0 comments

Comments

@luke-gru
Copy link

luke-gru commented Mar 13, 2023

The problem:

I'm running a test suite, and after every test method I'm running a leakchecker in a hook. It checks for various leaks like threads not being joined, etc. I recently added a checker for checking that BasicObject, Kernel and Object don't have new methods added on to them (I eagerly require all libraries that alter these classes, like yaml libraries etc to not get false positives).

When using minitest stubs, there's the following problem:

require 'minitest'
require 'minitest/mock'

class MyTest < Minitest::Test
  def test_example
    puts Kernel.private_methods(false).grep(/gem/).inspect # []
    Kernel.stub(:gem, proc {}) do
    end
    puts Kernel.private_methods(false).grep(/gem/).inspect # [:gem]. I would expect this to be empty.
    # The method is now defined on Kernel's metaclass (a class method). Before it was only an instance method of Kernel.
  end
end

Minitest.autorun

So my leakchecker reports these as leaks. I would like it if the method lookup for the receiver was the same before and after the stub call.

Edit:
I just took a look at the PRs for this repo and saw #891 could be related to my issue. I have not checked to see if it is a good solution nor have I tried the solution.

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

1 participant