未使用minitest加载测试服务的夹具

时间:2014-10-21 08:23:35

标签: ruby-on-rails unit-testing minitest

我在我的Rails应用程序中添加了一个/ app / services目录,其中我放置了一些与特定数据库表无关的业务逻辑和/或可能调用某些外部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"。

现在所有的测试都可以使用"弹簧拉力测试"进行,除了装置根本没有加载服务。最糟糕的是,如果我尝试添加"灯具:全部"在服务测试类的顶部,我得到一个"未定义的方法`fixture'为#

您是否了解如何为非常规目录中的测试加载灯具?

1 个答案:

答案 0 :(得分:3)

是的,谢谢Chris Kottom你得到了答案!诀窍就是使用它:

require 'test_helper'

class VatTest < ActiveSupport::TestCase

    # My test code

end

而不是:

require 'test_helper'

describe Vat do

    # My test code

end

虽然编写测试的最新方法有效,但这并不会加载灯具。