@ledsun blog

無味の味は佳境に入らざればすなわち知れず

Rails 5.0.7.2とMinitest 5.14.4で --verbose オプションをつけるとエラーがおきる

minitestをつかったRailsアプリケーションを5.0にアップデートするときに不思議な現象に出会いました。

bin/rails test は通るのに bin/rails test —verbose でエラーになる 不思議・・・です。

~ bin/rails test
Run options: --seed 4913

# Running:

.....SSSSSSS.....SS..........................................SSSS......SSSSSS...............

Finished in 1.496610s, 61.4723 runs/s, 76.1721 assertions/s.
92 runs, 114 assertions, 0 failures, 0 errors, 19 skips

You have skipped tests. Run with --verbose for details.
~ bin/rails test --verbose
Run options: --verbose --seed 56328

# Running:

Minitest::Result#test_a_request_is_finished_after_finish = 0.05 s = .
Minitest::Result#test_raise_RequestInvalidStateError_if_a_request_with_other_than_runnnig_state_finish = 0.00 s = .
Minitest::Result#test_that_it_counts_predicates_with_optional_ignore_predicates = 0.02 s = S


Skipped:
PredicateCollectorTest#test_that_it_counts_predicates_with_optional_ignore_predicates [/Users/shigerunakajima/lodqa-db/test/lib/predicate_collector_test.rb:22]:
The endpoint is unable.


Traceback (most recent call last):
    18: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/minitest-5.14.4/lib/minitest.rb:68:in `block in autorun'
  17: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/minitest-5.14.4/lib/minitest.rb:141:in `run'
   16: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/minitest-5.14.4/lib/minitest.rb:164:in `__run'
  15: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/minitest-5.14.4/lib/minitest.rb:164:in `map'
    14: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/minitest-5.14.4/lib/minitest.rb:164:in `block in __run'
  13: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.0.7.2/lib/rails/test_unit/line_filtering.rb:9:in `run'
   12: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/minitest-5.14.4/lib/minitest.rb:326:in `run'
  11: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/minitest-5.14.4/lib/minitest.rb:354:in `with_info_handler'
    10: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/minitest-5.14.4/lib/minitest.rb:367:in `on_signal'
   9: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/minitest-5.14.4/lib/minitest.rb:327:in `block in run'
    8: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/minitest-5.14.4/lib/minitest.rb:327:in `each'
   7: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/minitest-5.14.4/lib/minitest.rb:328:in `block (2 levels) in run'
     6: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/minitest-5.14.4/lib/minitest.rb:341:in `run_one_method'
   5: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/minitest-5.14.4/lib/minitest.rb:860:in `record'
    4: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/minitest-5.14.4/lib/minitest.rb:860:in `each'
   3: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/minitest-5.14.4/lib/minitest.rb:861:in `block in record'
     2: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.0.7.2/lib/rails/test_unit/reporter.rb:23:in `record'
   1: from /Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.0.7.2/lib/rails/test_unit/reporter.rb:70:in `format_rerun_snippet'
/Users/shigerunakajima/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.0.7.2/lib/rails/test_unit/reporter.rb:70:in `method': undefined method `test_that_it_counts_predicates_with_optional_ignore_predicates' for class `Minitest::Result' (NameError)

オプションをつけなければ動くので、最初はスルーしていました。 調べてみると、Rails 5.0はMinitest 5.10.1までしか対応していないようです。 Minitest 5.11でテストの結果のインタフェースが変わったため、Rails 5.0で本現象が起きるようになったようです*1

Rails 5.0が依存するMinitestのバージョン指定

https://github.com/rails/rails/blob/v5.0.7.2/activesupport/activesupport.gemspec#L25

s.add_dependency 'minitest',   '~> 5.1'

Rails 5.0が依存するMinitestのバージョン指定がメジャーバージョンまでの固定なので、何も指定せずにbundle installまたはbundle updateするとMinitest 5.14.4がインストールされて、本現象が起きます。

Rails 5.1.5でMinitest 5.11に対応

Add support for Minitest 5.11 by y-yagi · Pull Request #31624 · rails/rails · GitHub で、Minitest 5.11に対応しています。 Rails 5.1.5以降*2では本現象は起きません。

対応策

Gemfileにgem 'minitest', '5.10.1'を追記して本現象を回避しました。

このあとRails 5.1にアップデートする予定です。 そのとき同時に削除します。