Ruby on rails 未使用minitest加载夹具以测试服务

Ruby on rails 未使用minitest加载夹具以测试服务,ruby-on-rails,unit-testing,minitest,Ruby On Rails,Unit Testing,Minitest,我在Rails应用程序中添加了一个/app/services目录,在其中我放置了一些与特定DB表无关的业务逻辑和/或可能调用一些外部API的业务逻辑 我还将此添加到我的Rakefile中: namespace :test do desc "Test tests/services/* code" Rails::TestTask.new(:services) do |t| t.pattern = 'test/services/**/*_test.rb' end end Rake

我在Rails应用程序中添加了一个/app/services目录,在其中我放置了一些与特定DB表无关的业务逻辑和/或可能调用一些外部API的业务逻辑

我还将此添加到我的Rakefile中:

namespace :test do
  desc "Test tests/services/* code"
  Rails::TestTask.new(:services) do |t|
    t.pattern = 'test/services/**/*_test.rb'
  end
end

Rake::Task['test:run'].enhance ["test:services"]
如您所见,我的测试位于“/test/services”中

现在,所有的测试都可以使用“spring-rake测试”来执行,只是服务的夹具根本没有加载。最糟糕的是,如果我尝试在服务测试类的顶部添加“fixtures:all”,我会得到一个“undefined method`fixture”#
您知道如何加载位于非常规目录中的测试装置吗?

是的,谢谢Chris Kottom,您已经找到了答案!诀窍就是使用以下方法:

require 'test_helper'

class VatTest < ActiveSupport::TestCase

    # My test code

end

尽管编写测试的最新方法有效,但这不会加载装置。

您的测试是否继承自ActiveSupport::TestCase?直接继承自Minitest::test的测试不会在装置所需的数据库事务中运行。实际上,我使用Minitest,只是以与对模型完全相同的方式启动测试(例如:descripe MyService do…)。如何使它们从ActiveSupport::TestCase继承?它们不像一个普通类,是吗?将外部的“descripe”替换为“Class MyService testdescripe,如@ChrisKottom所说。或者,如果您使用的是minitest rails 2.1+,您可以说
descripe MyService,:model do
,这将使测试从正确的类继承。但是,较旧版本的minitest和minitest rails不支持这一点。
require 'test_helper'

describe Vat do

    # My test code

end