おぴよの気まぐれ日記

おぴよの気まぐれ日記

岡山やプログラミング、ファッションのこと、子育てや人生、生き方についての備忘録。

Railsチュートリアルの「3.3.1 最初のテスト」のテストをエラーになる

こんちには、opiyoです。

Railsチュートリアルの第3章に取り組んでいる最中ですが、ハマリポイントがあったので共有したいと思います。

https://railstutorial.jp/chapters/static_pages?version=5.0#sec-our_first_test

エラーの内容

$ rails test
# Running:

..

Finished in 0.633771s, 3.1557 runs/s, 3.1557 assertions/s.
/Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/test_unit/minitest_plugin.rb:9:in `aggregated_results': wrong number of arguments (given 1, expected 0) (ArgumentError)
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/minitest-5.10.2/lib/minitest.rb:597:in `report'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/minitest-reporters-1.1.9/lib/minitest/minitest_reporter_plugin.rb:26:in `each'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/minitest-reporters-1.1.9/lib/minitest/minitest_reporter_plugin.rb:26:in `report'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/minitest-5.10.2/lib/minitest.rb:687:in `each'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/minitest-5.10.2/lib/minitest.rb:687:in `report'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/minitest-5.10.2/lib/minitest.rb:141:in `run'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/test.rb:9:in `<top (required)>'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:138:in `require_command!'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:95:in `test'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/taku/rails/railstutorial/sample_app/bin/rails:9:in `<top (required)>'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/taku/.rbenv/versions/2.3.3/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'

原因

どうやらgemのminitestが5.10.2(2017/5/9リリース)にアップデートされたことで発生したらしいです。

解決方法

1. gemのminitestを追加します。

group :test do
  gem 'rails-controller-testing', '0.1.1'
  gem 'minitest-reporters',       '1.1.9'
  gem 'guard',                    '2.13.0'
  gem 'guard-minitest',           '2.4.4'
  gem 'minitest', '~> 5.10', '!= 5.10.2' # これですね 多分5.10.2以外のバージョンでマイナーバージョンへアップデートかな?
end

2. bundle updateしてgemを更新します。

$ bundle update
Resolving dependencies...
Using rake 12.0.0
Using concurrent-ruby 1.0.5
Using i18n 0.8.4
Using minitest 5.10.1 (was 5.10.2)
.
.
Bundle updated!
Gems in the group production were not installed.

3. rails testを再実行する

$ rails test
Run options: --seed 57994

# Running:

..
Finished in 0.648009s, 3.0864 runs/s, 3.0864 assertions/s.
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips

めでたし、めでたし