0

我通常使用以下命令运行我的测试套件Rake

耙文件

require 'rake/testtask'

namespace :spec do
  desc "Run all specs"
  task all: [:units]

  desc "Run all unit specs"
  Rake::TestTask.new :units do |t|
    t.pattern = "spec/unit/**/*_spec.rb"
    t.libs = ['app', 'spec']
  end
end

上面的 rake 任务效果很好。现在我希望运行它guard-minitest

保护文件

guard 'minitest' do
  watch(%r{^app/(.+)\.rb$}) { |m| "spec/app/#{m[1]}_spec.rb" }
  watch(%r{^spec/(.+)\.rb$}) { |m| "spec/#{m[1]}.rb" }
end

但是,这样做会导致我的加载路径未设置:

/vagrant/spec/unit/helper.rb:5:in `require': cannot load such file -- repository (LoadError)

...因为我需要我的文件喜欢require 'repository'而不是require './app/repository'.

如何配置警卫以使用我需要的加载路径,就像我在 rake 任务中所做的那样?

4

1 回答 1

2

您可以将app目录LOAD_PATH直接添加到您的test/test_helper.rb(或spec/spec_helper.rb)中,例如:

$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'app')))

guard-minitest 将你的测试助手添加到 minitest 中,即使在 drb 上运行时也是如此。

于 2012-07-21T09:07:14.790 回答