Skip to content

Troubles loading minitest-mock #9238

@voxik

Description

@voxik

Given this configuration:

$ ruby -v
ruby 3.4.8 (2025-12-17 revision 995b59f666) +PRISM [x86_64-linux]

$ gem list minitest

*** LOCAL GEMS ***

minitest (6.0.1, 5.26.2)
minitest-mock (5.27.0)

RubyGems can't properly load minitest-mock:

$ cat test.rb 
require 'minitest/autorun'
require 'minitest/mock'

$ ruby test.rb 
<internal:/usr/share/rubygems/rubygems/core_ext/kernel_require.rb>:141:in 'Kernel#require': cannot load such file -- minitest/mock (LoadError)
        from <internal:/usr/share/rubygems/rubygems/core_ext/kernel_require.rb>:141:in 'Kernel#require'
        from test.rb:2:in '<main>'
<internal:/usr/share/rubygems/rubygems/core_ext/kernel_require.rb>:136:in 'Kernel#require': cannot load such file -- minitest/mock (LoadError)
        from <internal:/usr/share/rubygems/rubygems/core_ext/kernel_require.rb>:136:in 'Kernel#require'
        from test.rb:2:in '<main>'

From this, it is not clear what is going on. Luckily the --debug option reports exceptions providing some hint what happens:

Exception 'Gem::LoadError' at /usr/share/rubygems/rubygems/specification.rb:2232 - can't activate minitest-5.26.2, already activated minitest-6.0.1

The first concerning issue is that while at some point, there is helpful message, it is lost and not reported to the user.

But the main concern here is why RubyGems don't try to load minitest/mock from minitest-mock gem? Why they prefer Minitest 5? Is it just e.g. the shorter name? But at this point, it is clear that Minitest 6 is loaded in memory, so why even bother with it?

IOW one possible solution could be to exclude libraries which are already loaded in some versions and try the rest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions