Gem::ConflictErrorについて（activesupport）

今回はminitestを実行しようとした際に急にエラーが出始めましたのでその経緯と解決策を記載します。

環境は下記でした。

```ruby
ruby 2.6.3
Rails 5.1.7
minitest (5.14.1, 5.14.0, 5.11.3, 5.10.3, 5.10.1)
```

この記事は以下のテキストを進めていた際に発生したエラーについての執筆です。

- [プロを目指す人のためのRuby入門](https://gihyo.jp/book/2017/978-4-7741-9397-7)

※書籍内容に誤り等があるわけではなく、他の作業と並行して進めていた際に意図せずgemを更新してしまったことによるエラーとその解決法についての執筆です


minitestのエラーに関しては著者様のほうでも各種の解決策を投稿していただいておりましたが、どれにも当てはまらない状況でした。
書籍進行中に急にテストでエラーが出るようになったので、おそらく、合間に行った別の作業が要因かと思いましたのでそのような経験がある方のみ、参考にしてください。

以下、エラー内容です。

```ruby
ec2-user:~/environment/ruby-book $ ruby lib/sample_test.rb
Traceback (most recent call last):
        9: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/minitest-5.14.1/lib/minitest.rb:68:in `block in autorun'
        8: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/minitest-5.14.1/lib/minitest.rb:126:in `run'
        7: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/minitest-5.14.1/lib/minitest.rb:97:in `load_plugins'
        6: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/minitest-5.14.1/lib/minitest.rb:97:in `each'
        5: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/minitest-5.14.1/lib/minitest.rb:103:in `block in load_plugins'
        4: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `                   require'
        3: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        2: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/railties-5.1.7/lib/minitest/rails_plugin.rb:2:in `<top (required)>'
        1: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:117:in `require'
/home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:117:in `require': cannot load such file -- rails/test_unit/reporter (LoadError)
        12: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/minitest-5.14.1/lib/minitest.rb:68:in `block in autorun'
        11: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/minitest-5.14.1/lib/minitest.rb:126:in `run'
        10: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/minitest-5.14.1/lib/minitest.rb:97:in `load_plugins'
         9: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/minitest-5.14.1/lib/minitest.rb:97:in `each'
         8: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/minitest-5.14.1/lib/minitest.rb:103:in `block in load_plugins'
         7: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
         6: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
         5: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/railties-5.1.7/lib/minitest/rails_plugin.rb:2:in `<top (required)>'
         4: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require'
         3: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:123:in `rescue in require'
         2: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems.rb:218:in `try_activate'
         1: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/specification.rb:1415:in `activate'
/home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/specification.rb:2298:in `raise_if_conflicts': Unable to activate railties-5.1.7, because activesupport-6.0.3.1 conflicts with activesupport (= 5.1.7) (Gem::ConflictError)
        13: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/minitest-5.14.1/lib/minitest.rb:68:in `block in autorun'
        12: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/minitest-5.14.1/lib/minitest.rb:126:in `run'
        11: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/minitest-5.14.1/lib/minitest.rb:97:in `load_plugins'
        10: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/minitest-5.14.1/lib/minitest.rb:97:in `each'
         9: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/minitest-5.14.1/lib/minitest.rb:103:in `block in load_plugins'
         8: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
         7: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
         6: from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/railties-5.1.7/lib/minitest/rails_plugin.rb:2:in `<top (required)>'
         5: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require'
         4: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:123:in `rescue in require'
         3: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems.rb:217:in `try_activate'
         2: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems.rb:224:in `rescue in try_activate'
         1: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/specification.rb:1415:in `activate'
/home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/specification.rb:2298:in `raise_if_conflicts': Unable to activate railties-5.1.7, because activesupport-6.0.3.1 conflicts with activesupport (= 5.1.7) (Gem::ConflictError)
```

activesupportの6.0.3.1と5.1.7がコンフリクトしているよというもの。

思い当たる要因としては、前日にsinatraでのアプリ制作時にいろいろと作業したことかと。

結果的にはgemをアンインストールすることで解決しました。

```ruby
ec2-user:~/environment/ruby-book $ gem uninstall activesupport -v 6.0.3.1

You have requested to uninstall the gem:
        activesupport-6.0.3.1

activemodel-6.0.3.1 depends on activesupport (= 6.0.3.1)
activerecord-6.0.3.1 depends on activesupport (= 6.0.3.1)
If you remove this gem, these dependencies will not be met.
Continue with Uninstall? [yN]  y
Successfully uninstalled activesupport-6.0.3.1
```

上記で6.0.3.1のほうをアンインストールしました。

```ruby
ec2-user:~/environment/ruby-book $ ruby lib/sample_test.rb
Run options: --seed 27045

# Running:

E

Finished in 0.002129s, 469.6838 runs/s, 0.0000 assertions/s.

  1) Error:
SampleTest#test_sample:
NoMethodError: undefined method `upcase' for nil:NilClass
Did you mean?  case
    lib/sample_test.rb:5:in `test_sample'

1 runs, 0 assertions, 0 failures, 1 errors, 0 skips

ec2-user:~/environment/ruby-book $ ruby test/deep_freezable_test.rb
Run options: --seed 56480

# Running:

.

Finished in 0.002055s, 486.6611 runs/s, 486.6611 assertions/s.

1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

```

結果的に無事、テスト検証できました。

参考に、アンインストール後のバージョンを再度掲載します。

```ruby
ec2-user:~/environment/ruby-book $ gem list | grep activesupport
activesupport (5.1.7, 5.1.6, 5.0.0)
```


同じように詰まった方の参考になれば。