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

Don't mess with Minitest unless RAILS_ENV is set #51718

Merged
merged 1 commit into from
May 3, 2024
Merged

Don't mess with Minitest unless RAILS_ENV is set #51718

merged 1 commit into from
May 3, 2024

Conversation

tenderlove
Copy link
Member

Minitest will automatically scan all installed gems and load plugins from those gems. We should detect whether or not we're being run within the context of a Rails app and only change MT behavior in that case.

To determine if we're being run via bin/rails we'll just check if RAILS_ENV is set.

Ref: minitest/minitest#996
Ref: minitest/minitest#725

Minitest will automatically scan all installed gems and load plugins
from those gems.  We should detect whether or not we're being run within
the context of a Rails app and only change MT behavior in that case.

To determine if we're being run via `bin/rails` we'll just check if
RAILS_ENV is set.

Ref: minitest/minitest#996
Ref: minitest/minitest#725
@rails-bot rails-bot bot added the railties label May 2, 2024
@@ -109,6 +109,9 @@ def self.plugin_rails_options(opts, options)
# Owes great inspiration to test runner trailblazers like RSpec,
# minitest-reporters, maxitest, and others.
def self.plugin_rails_init(options)
# Don't mess with Minitest unless RAILS_ENV is set
return unless ENV["RAILS_ENV"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excuse my ignorance but would defined?(::Rails) be more accurate?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind just read the linked issues 🙏

@tenderlove tenderlove merged commit e74dc16 into main May 3, 2024
6 checks passed
@tenderlove tenderlove deleted the mt-rails branch May 3, 2024 16:43
@justinko
Copy link
Contributor

@tenderlove I just noticed that running bundle exec rake test in this repo no longer has colorized output. It's because some of the projects test helpers don't set the RAILS_ENV.

I'm getting around it by just doing RAILS_ENV=test bundle exec rake test ... but do you think we should explicitly set RAILS_ENV in the test helpers that don't have it (and don't need it)?

Or shall we do nothing and just wait for Minitest to have "explicit plugin loading"?

@rafaelfranca
Copy link
Member

Does that happen on the application as well?

@justinko
Copy link
Contributor

@rafaelfranca no

@rafaelfranca
Copy link
Member

Great. I fixed on main already

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants