【问题标题】:Configure guard-minitest load paths?配置 guard-minitest 负载路径?
【发布时间】:2012-07-19 10:33:57
【问题描述】:

我通常使用Rake 运行我的测试套件:

Rakefile

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'

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

【问题讨论】:

    标签: ruby tdd rake guard


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2019-03-27
      • 1970-01-01
      • 2013-03-12
      • 2019-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-29
      • 2017-01-18
      相关资源
      最近更新 更多