[英]Error when trying to run a minitest unit test
I get the following error when trying to run a minitest unit test with ruby test/test_foo.rb
: 尝试使用
ruby test/test_foo.rb
运行最小单元测试时出现以下错误:
Warning: you should require 'minitest/autorun' instead.
Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
From:
/home/emile/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/autorun.rb:15:```
test_foo.rb looks like this: test_foo.rb看起来像这样:
require 'minitest/autorun'
class TestFoo < MiniTest::Test
#stuf
end
My Gemfile does contain gem 'minitest'
and test_foo.rb does contain require 'minitest/autorun'
, yet I still get the warning. 我的Gemfile确实包含
gem 'minitest'
,test_foo.rb确实包含require 'minitest/autorun'
,但我仍然收到警告。
Is this a bug? 这是一个错误吗? Any ideas?
有任何想法吗?
Run your test using bundle exec ruby test/test_foo.rb
to make sure you use your bundled gems (in this case minitest). 使用
bundle exec ruby test/test_foo.rb
运行测试,以确保使用捆绑的gem(在本例中为minitest)。
Just running ruby test/test_foo.rb
will use your globally installed Rubygems. 只运行
ruby test/test_foo.rb
将使用全局安装的Rubygems。
If you want to dig around a little more, try looking in /home/emile/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/autorun.rb
, around line 15. 如果你想再挖掘一下,可以尝试查看
/home/emile/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/autorun.rb
,第15行。
▲ ▲
I've interepreted the warning literally and added the line gem 'minitest' before the line require 'minitest/autorun', and that seems to work.
我在字面上解释了这个警告,并在该行需要'minitest / autorun'之前添加了行'gem'minitest',这似乎有效。 Odd, or is this expected?
奇怪,或者这是预期的?
This is expected. 这是预料之中的。 It tells ruby to use the gem version and not the standard library version.
它告诉ruby使用gem版本而不是标准库版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.