ruby-on-rails – 使用Minitest,需要’minitest_helper’加载错误

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 使用Minitest,需要’minitest_helper’加载错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在测试Minitest :: Spec作为RSpec的替代品,但我有一个麻烦的问题我无法找到答案:

我在spec / models / * _ spec.rb中设置了一些基本规格.我的rails应用程序包含minitest-rails,我将rakefile设置如下:

Rake::TestTask.new do |t|
  t.libs.push "lib"
  t.test_files = FileList['spec/**/*_spec.rb']
  t.verbose = true
end
task :default => :test

现在,如果我像这样编写我的spec文件

require 'minitest_helper'

describe User do
  ...
end

…并进行rake测试,我得到:

user_spec.rb:1:in `require': cannot load such file -- minitest_helper (LoadError)

但是,如果我将需求行更改为

require_relative '../minitest_helper'

然后它工作.所以,这是功能性的,但似乎每个使用我在网上找到的最小规格的人的例子都只需要调用require’minitest_helper’,而不是require_relative.那么,我错过了什么让那些为别人工作但不在我的情况下呢?

最后一条信息,我的帮助文件如下所示:

# spec/minitest_helper.rb
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment',__FILE__)

require "minitest/autorun"
require "minitest/rails"

# Uncomment if you want Capybara in accceptance/integration tests
# require "minitest/rails/capybara"

# Uncomment if you want awesome colorful output
# require "minitest/pride"

class MiniTest::Rails::ActiveSupport::TestCase
  # Add more helper methods to be used by all tests here...
end

没有什么花哨.谢谢您的帮助!

解决方法

您的测试没有找到帮助文件,因为您没有告诉您的测试看它在哪里.尝试将您的rake任务更改为:
Rake::TestTask.new do |t|
  t.libs << "lib"
  t.libs << "spec"
  t.test_files = FileList['spec/**/*_spec.rb']
  t.verbose = true
end
task :default => :test
原文链接:https://www.f2er.com/ruby/264760.html

猜你在找的Ruby相关文章