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

[BUG] undefined method after_run when running Minitest version 4 #114

Open
JuanVqz opened this issue Jan 24, 2024 · 4 comments
Open

[BUG] undefined method after_run when running Minitest version 4 #114

JuanVqz opened this issue Jan 24, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@JuanVqz
Copy link
Member

JuanVqz commented Jan 24, 2024

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, 👍

I will abide by the code of conduct

@JuanVqz JuanVqz added the bug Something isn't working label Jan 24, 2024
@JuanVqz JuanVqz changed the title [BUG] [BUG] undefined method after_run when running Minitest version 4 Jan 24, 2024
@fbuys
Copy link

fbuys commented Jan 24, 2024

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.

@JuanVqz
Copy link
Member Author

JuanVqz commented Jan 24, 2024

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

@etagwerker
Copy link
Member

@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?

@fbuys
Copy link

fbuys commented Jan 24, 2024

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.

module MinitestExtension
def self.new(deprecation_tracker)
@@deprecation_tracker = deprecation_tracker
Module.new do
def before_setup
test_file_name = method(name).source_location.first.to_s
@@deprecation_tracker.bucket = test_file_name.gsub(Rails.root.to_s, ".")
super
end
def after_teardown
super
@@deprecation_tracker.bucket = nil
end
end
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants