Pregunta

I am using Ruby 2.0.

Sometimes I encounter cases where I can't just simply require 'minitest'. It gives me

irb> require 'minitest'
LoadError: cannot load such file -- minitest
from rubygems/core_ext/kernel_require.rb:55:in `require'

I need to install minitest gem first. However I thought minitest is bundled in the Ruby standard library.

When do we need to explicitly install minitest gem via gem install or Gemfile?

If installing explicitly is required, should Gemfile bundle install preferred over gem install?

update

I myself use rbenv. I install my Ruby through rbenv as well.
My ruby version is ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin13.0.2]

¿Fue útil?

Solución

So I realized MiniTest had some incompatible updates from 4.x to 5.x And somehow I was using version 5.x but my problem seems to occur when 4.x is used.

Here is when it works as expected:

irb> require 'minitest'
=> true
irb> require 'minitest/autorun'
=> true
irb> MiniTest::Test
=> Minitest::Test
irb> MiniTest.constants
=> [:Parallel, :VERSION, :Runnable, :AbstractReporter, :Reporter, :ProgressReporter, :StatisticsReporter, :SummaryReporter, :CompositeReporter, :Assertion, :Skip, :UnexpectedError, :Guard, :BacktraceFilter, :Test, :Assertions, :Unit, :Spec, :Expectations, :Mock]
irb> MiniTest::Unit::VERSION
=> "5.3.2"

Here is when it is not. I installed a fresh copy of Ruby 2.1 and reproduced the following.

irb> require 'minitest'
LoadError: cannot load such file -- minitest
irb> require 'minitest/autorun'
=> true
irb> MiniTest::Test
NameError: uninitialized constant MiniTest::Test
irb> MiniTest.constants
=> [:Assertion, :Skip, :BacktraceFilter, :Assertions, :Unit, :Spec, :Expectations, :Mock]
irb> MiniTest::Unit::VERSION
=> "4.7.5"

Summary

So I guess when an older minitest version is used, I should install version 5 explictly via Gemfile/bundler.

Otros consejos

If you install through gem, all system wide gem will depend upon that version. While bundle install make sure all dependencies in your gem file are available to your application.

sunspot_rails
  nokogiri (>= 1.2.0)

webrat
  nokogiri (>= 1.3) 

Both gem require nokogiri but they do have preferred version number. In this scenario if you install through gem, you will get version conflict. But bundle will intelligently handle that version demand for you.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top