问题
I am following along the Make your own Gem Guide from RubyGems. Executing the rake test
instructions fails as follows:
> rake test
~/.rbenv/versions/2.1.2/lib/ruby/2.1.0/minitest/unit.rb:26:in `const_missing': uninitialized constant MiniTest::Test (NameError)
<rest of output truncated>
I figured that it is because the minitest version being used is 4.7.5
and not 5.6.0
(or any of the 5.0.0 series that is needed to have MiniTest::Test
be valid). So I installed minitest 5.6.0
and now I have both versions of minitest
. However rake test
will still only use the 4.7.5
version.
How do I make it so that running rake test
uses the right minitest
within the setting of the Guide?
Using ruby directly works:
> ruby -Ilib test/test_hola.rb
Run options: --seed 48777
# Running:
...
Finished in 0.002862s, 1048.3550 runs/s, 1048.3550 assertions/s.
3 runs, 3 assertions, 0 failures, 0 errors, 0 skips
Deleting minitest 4.7.5 is nigh impossible ;).
Setup
- Ruby 2.1.2 under rbenv 0.4.0-129-g7e0e85b
- rake (10.1.0)
- minitest (5.6.0, 4.7.5)
- Ubuntu 14.04
Edit
Adding gem "minitest"
in Rakefile
and/or test_hola.rb
does not fix the issue.
回答1:
The solution I used was to delete the old minitest directory located at:
~/.rbenv/versions/2.1.2/lib/ruby/2.1.0/minitest/
.
Indeed, despite gem list minitest -d
returning:
*** LOCAL GEMS ***
minitest (5.6.0, 4.7.5)
Author: Ryan Davis
Homepage: https://github.com/seattlerb/minitest
License: MIT
Installed at (5.6.0): ~/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0
(4.7.5, default): ~/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0
minitest provides a complete suite of testing facilities supporting
TDD, BDD, mocking, and benchmarking
the default minitest
location was actually ~/.rbenv/versions/2.1.2/lib/ruby/2.1.0/minitest/
. The reported location for the newer minitest
(5.6.0
in this case) is correct.
回答2:
And the following line to your Rakefile:
gem "minitest"
来源:https://stackoverflow.com/questions/29736396/how-to-make-rake-test-not-use-the-default-minitest