next_rails icon indicating copy to clipboard operation
next_rails copied to clipboard

[BUG] undefined method after_run when running Minitest version 4

Open JuanVqz opened this issue 1 year ago • 4 comments

Expected Behavior

Be able to use the Minitest deprecation tracker with Ruby 2.3.8 and Rails 3.2.22.5 using the Minitest gem at version 4.7.5

Actual Behavior

If I run the deprecation tracker it breaks with the following error:

vendor/bundle/ruby/2.3.0/gems/next_rails-1.3.0/lib/deprecation_tracker.rb:107:in `track_minitest': undefined method `after_run' for MiniTest:Module (NoMethodError)

Possible Fix

Add a check in the next_rails gem if the app is using Minitest v4, then instead of using after_run it should use the correct method (I think it was after_tests).

To Reproduce

  1. Have a Rails 3.2 with Ruby 2.3 and have Minitest v4.7.3 installed
  2. Configure the deprecation tracker for Minitest
  3. Run the test suite saving the deprecations
  4. see the error

Additional Information

I researched a little bit it seems like the Minitest gem at version 4.7.3 doesn't have the after_run method, it was initially introduced at version 5.0.0

If there are more questions feel free to ping me, :+1:

I will abide by the code of conduct

JuanVqz avatar Jan 24 '24 00:01 JuanVqz

Here is some more information that I found for Minitest version 4.7.3.

The below console results show how we can determine that the after_tests method exists.

irb(main):031:0> Minitest::Unit.respond_to?(:after_tests)
=> true
irb(main):032:0> defined?(Minitest::Unit)
=> "constant"

If after_run fails but the above results show that after_tests is available, then we can use after_tests to add the required hook.

fbuys avatar Jan 24 '24 13:01 fbuys

The workaround we used to solve this:

  # config/initializers/minitest.rb

  module Minitest
    def self.after_run(&block)
      Minitest::Unit.after_tests(&block)
    end
  end

JuanVqz avatar Jan 24 '24 14:01 JuanVqz

@JuanVqz @fbuys Thanks for sharing all this!

When you have a moment, could you please submit a PR that adds this monkeypatch for applications that are using Minitest < 5.0?

etagwerker avatar Jan 24 '24 15:01 etagwerker

After more investigation it turns out that a simple monkey patch is not enough to get next_rails to work with minitest 4.7

I believe we need to investigate how to hook into the test suites for minitest 4.7. The Minitest extension we currently use for the deprecation tracker is also not compatible with this version of minitest.

https://github.com/fastruby/next_rails/blob/4752fc9dd4d49d5ca35f779f66622604b208c6f2/lib/deprecation_tracker.rb#L36-L53

fbuys avatar Jan 24 '24 20:01 fbuys