Skip to content

Fix minitest plugin leaking into rails/rails tests - #29818

Closed
kirs wants to merge 1 commit into
rails:masterfrom
kirs:fix-minitest-plugin
Closed

kirs wants to merge 1 commit into
rails:masterfrom
kirs:fix-minitest-plugin

Conversation

@kirs

@kirs kirs commented Jul 16, 2017

Copy link
Copy Markdown
Member

Bug

After #29572 has been merged, any failing test in ActiveRecord/ActiveJob/ActiveSupport suite would fail in Minitest reporter.

Reproduction steps

  1. Add a failing test
diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb
index 4ef9a12..a353503 100644
--- a/activerecord/test/cases/enum_test.rb
+++ b/activerecord/test/cases/enum_test.rb
@@ -9,6 +9,10 @@ class EnumTest < ActiveRecord::TestCase
     @book = books(:awdr)
   end

+  test "omg im failing!" do
+    assert false
+  end
+
  1. Run the test suite
$ bundle exec ruby -Itest test/cases/enum_test.rb
Using sqlite3
Run options: --seed 49833

# Running:

..........................F

Failure:
EnumTest#test_omg [test/cases/enum_test.rb:13]:
Failed assertion, no message given.


/Users/kir/Projects/opensource/rails/railties/lib/rails/test_unit/reporter.rb:74:in `app_root': undefined method `root' for Rails:Module (NoMethodError)
        from /Users/kir/Projects/opensource/rails/railties/lib/rails/test_unit/reporter.rb:52:in `relative_path_for'
        from /Users/kir/Projects/opensource/rails/railties/lib/rails/test_unit/reporter.rb:70:in `format_rerun_snippet'
        from /Users/kir/Projects/opensource/rails/railties/lib/rails/test_unit/reporter.rb:22:in `record'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/minitest-5.3.3/lib/minitest.rb:613:in `block in record'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/minitest-5.3.3/lib/minitest.rb:612:in `each'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/minitest-5.3.3/lib/minitest.rb:612:in `record'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/minitest-5.3.3/lib/minitest.rb:293:in `run_one_method'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/minitest-5.3.3/lib/minitest.rb:287:in `block (2 levels) in run'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/minitest-5.3.3/lib/minitest.rb:286:in `each'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/minitest-5.3.3/lib/minitest.rb:286:in `block in run'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/minitest-5.3.3/lib/minitest.rb:317:in `on_signal'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/minitest-5.3.3/lib/minitest.rb:306:in `with_info_handler'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/minitest-5.3.3/lib/minitest.rb:285:in `run'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/minitest-5.3.3/lib/minitest.rb:149:in `block in __run'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/minitest-5.3.3/lib/minitest.rb:149:in `map'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/minitest-5.3.3/lib/minitest.rb:149:in `__run'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/minitest-5.3.3/lib/minitest.rb:126:in `run'
        from /Users/kir/Projects/opensource/rails/vendor/bundle/gems/minitest-5.3.3/lib/minitest.rb:55:in `block in autorun'

Fix

With #29572 Minitest always loads loads the plugins, including Rails test reporter plugin. This works fine if you're running a Rails application test suite, but when you're running rails/rails test suite you don't want to load custom test reporter.

In ActiveRecord tests, there's no Rails.application or Rails.root available, which makes the custom test reporter 💥

The solution is to disable custom reporter when it's not running in the context of Rails app.

@kirs

kirs commented Jul 16, 2017

Copy link
Copy Markdown
Member Author

@kaspth

@kirs

kirs commented Jul 16, 2017

Copy link
Copy Markdown
Member Author

@kaspth

kaspth commented Jul 16, 2017

Copy link
Copy Markdown
Contributor

I'd rather we dog food our test reporter like we do on 5-1-stable. So I've forward ported 519467b to master. Thanks for the reminder, Kir!

@kaspth kaspth closed this Jul 16, 2017
@kirs

kirs commented Jul 16, 2017

Copy link
Copy Markdown
Member Author

I thought about dog fooding and it would be great, but what about test reporter being specific to Rails apps? For instance Rerun: bin/rails test/cases/activerecord_test_case.rb doesn't make any sense for rails/rails. Even worse that it's misleading.

@kaspth

kaspth commented Jul 17, 2017

Copy link
Copy Markdown
Contributor

It doesn't make sense, yeah. The rails_app? early return bothers me more than seeing those snippets though ¯_(ツ)_/¯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants