Help us understand the problem. What is going on with this article?

minitestの依存関係(?)問題をbundlerで解決する

More than 1 year has passed since last update.

プロを目指す人のためのRuby入門の第3章のminitestのところで、以下のようなテストクラスを用意するところがあります。

# fizz_buzz_test.rb

require 'minitest/autorun'

class FizzBuzzTest < Minitest::Test
    def test_fizz_buzz
        assert_equal'1', fizz_buzz(1)
        assert_equal'2', fizz_buzz(2)
        assert_equal'Fizz', fizz_buzz(3)
    end
end

環境によっては以下のようなエラーに遭遇する場合があります。

k-3:lib k$ ruby fizz_buzz_test.rb
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/rubygems/specification.rb:2291:in `raise_if_conflicts': Unable to activate railties-5.1.6, because activesupport-5.2.1 conflicts with activesupport (= 5.1.6) (Gem::ConflictError)
        from /usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/rubygems/specification.rb:1411:in `activate'
        from /usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/rubygems.rb:220:in `rescue in try_activate'
        from /usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/rubygems.rb:213:in `try_activate'
        from /usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:126:in `rescue in require'
        from /usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:40:in `require'
        from /usr/local/lib/ruby/gems/2.4.0/gems/railties-5.1.6/lib/minitest/rails_plugin.rb:2:in `<top (required)>'
        from /usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /usr/local/lib/ruby/gems/2.4.0/gems/minitest-5.11.3/lib/minitest.rb:98:in `block in load_plugins'
        from /usr/local/lib/ruby/gems/2.4.0/gems/minitest-5.11.3/lib/minitest.rb:92:in `each'
        from /usr/local/lib/ruby/gems/2.4.0/gems/minitest-5.11.3/lib/minitest.rb:92:in `load_plugins'
        from /usr/local/lib/ruby/gems/2.4.0/gems/minitest-5.11.3/lib/minitest.rb:121:in `run'
        from /usr/local/lib/ruby/gems/2.4.0/gems/minitest-5.11.3/lib/minitest.rb:63:in `block in autorun'

これで解決できます!(本質的な解決ではない)

bundlerを使うことで、Gemfileで指定したバージョンのminitestを実行できる。

gem install bundler
bundle init

Gemfileが作られるので、Gemfileに追記します。

# Edit Gemfile
gem 'minitest'
bundle install
bundle exec ruby fizz_buzz_test.rb
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした