简体   繁体   English

LoadError:无法加载此类文件 - minitest / rails

[英]LoadError: cannot load such file — minitest/rails

I am using Rails 4.2 and Ruby 2.1.3, while running unit test cases with the following command 我正在使用Rails 4.2和Ruby 2.1.3,同时使用以下命令运行单元测试用例

rake test /../test/models/file_test.rb --trace

I am getting the following error 我收到以下错误

** Invoke test (first_time)
** Execute test
** Invoke test:run (first_time)
** Execute test:run
rake aborted!
LoadError: cannot load such file -- minitest/rails
/opt/library/lib/ruby/gems/2.1.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/opt/library/lib/ruby/gems/2.1.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
/opt/library/lib/ruby/gems/2.1.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/opt/library/lib/ruby/gems/2.1.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/opt/myapp/test/test_helper.rb:4:in `<top (required)>'
/opt/myapp/test/test/controllers/packager_controller_test.rb:1:in `require'
/opt/myapp/test/controllers/packager_controller_test.rb:1:in `<top (required)>'
/opt/library/lib/ruby/gems/2.1.0/gems/railties-4.2.1/lib/rails/test_unit/sub_test_task.rb:114:in `require'
/opt/library/lib/ruby/gems/2.1.0/gems/railties-4.2.1/lib/rails/test_unit/sub_test_task.rb:114:in `block (3 levels) in define'
/opt/library/lib/ruby/gems/2.1.0/gems/railties-4.2.1/lib/rails/test_unit/sub_test_task.rb:114:in `each'
/opt/library/lib/ruby/gems/2.1.0/gems/railties-4.2.1/lib/rails/test_unit/sub_test_task.rb:114:in `block (2 levels) in define'
/opt/library/lib/ruby/gems/2.1.0/gems/railties-4.2.1/lib/rails/test_unit/sub_test_task.rb:113:in `each'
/opt/library/lib/ruby/gems/2.1.0/gems/railties-4.2.1/lib/rails/test_unit/sub_test_task.rb:113:in `block in define'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/task.rb:248:in `call'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/task.rb:248:in `block in execute'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/task.rb:243:in `each'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/task.rb:243:in `execute'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/opt/library/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/task.rb:180:in `invoke_with_call_chain'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/task.rb:173:in `invoke'
/opt/library/lib/ruby/gems/2.1.0/gems/railties-4.2.1/lib/rails/test_unit/sub_test_task.rb:20:in `invoke_rake_task'
/opt/library/lib/ruby/gems/2.1.0/gems/railties-4.2.1/lib/rails/test_unit/testing.rake:8:in `block in <top (required)>'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/task.rb:248:in `call'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/task.rb:248:in `block in execute'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/task.rb:243:in `each'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/task.rb:243:in `execute'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/opt/library/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/task.rb:180:in `invoke_with_call_chain'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/task.rb:173:in `invoke'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/application.rb:152:in `invoke_task'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/application.rb:108:in `each'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/application.rb:108:in `block in top_level'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/application.rb:117:in `run_with_threads'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/application.rb:102:in `top_level'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/application.rb:80:in `block in run'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/application.rb:178:in `standard_exception_handling'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/lib/rake/application.rb:77:in `run'
/opt/library/lib/ruby/gems/2.1.0/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
/opt/library/bin/rake:23:in `load'
/opt/library/bin/rake:23:in `<main>'
Tasks: TOP => test:run

Gemfile 的Gemfile

gem 'minitest', '~> 5.1'

Tried the following command as per suggestion available in SO but still getting error. 根据SO中提供的建议尝试以下命令,但仍然出现错误。

require File.expand_path('../../test_helper', __FILE__) in file_test.rb

Also tried this way to run the test: 也试过这种方式来运行测试:

ruby -Itest test/models/file_test.rb

test_helper.rb test_helper.rb中

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require "minitest/rails"

# To add Capybara feature tests add `gem "minitest-rails-capybara"`
# to the test group in the Gemfile and uncomment the following:
# require "minitest/rails/capybara"

# Uncomment for awesome colorful output
require "minitest/pride"

class ActiveSupport::TestCase
  # ActiveRecord::Migration.check_pending!

  # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
  #
  # Note: You'll currently still have to declare fixtures explicitly in integration tests
  # -- they do not yet inherit this setting
  # fixtures :all

  # Add more helper methods to be used by all tests here...
end

Thanks in advance. 提前致谢。 Please let me know if I need to provide any more explanation. 如果我需要提供更多解释,请告诉我。

I suspect the problem is here: 我怀疑问题在这里:

/opt/myapp/test/test_helper.rb:4

What is that line? 那条线是什么? Is it by any chance a minitest/rails include line? minitest / rails是否包含线路?

Also note minitest-rails is not minitest. 另请注意,minitest-rails不是最小的。 If you have added minitest-rails it I would try removing it (and the include line) and see where it gets you. 如果你已经添加了minitest-rails,我会尝试删除它(以及包含行)并查看它的位置。

Checking a fresh install of a 4.2 Rails app, I don't see such an include line in the test_helper - did you add it? 检查4.2 Rails应用程序的全新安装,我在test_helper中没有看到这样的包含行 - 你是否添加了它? Also, minitest is already a dependency of Rails so I don't think you need to add it to your Gem file. 此外,minitest已经是Rails的依赖项,所以我认为你不需要将它添加到你的Gem文件中。

The way I use Minitest is this in the Gemfile , notice that it's minitest-rails , not just minitest . 我使用Minitest的方式是在Gemfile ,注意它是minitest-rails ,而不仅仅是minitest You can of course skip capybara if you don't want that, but it's nice for feature/integration tests. 如果你不想要它,你当然可以跳过capybara ,但它对于功能/集成测试很有用。

group :development, :test do
  gem 'minitest-rails'
  gem 'minitest-rails-capybara'
end

and then in the test_helper.rb 然后在test_helper.rb

require "minitest/rails"
require "minitest/rails/capybara"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM