guard_test_runner.rb:1:在`require':无法加载这样的文件

时间:2015-09-15 11:37:30

标签: ruby-on-rails ruby tdd minitest guard

我正在尝试使用.Guard文件,我的所有Rails项目都可以在我的用户目录中运行。

.Guardfile内容概述如下:

# Defines the matching rules for Guard.
guard :test, all_on_start: false do
  watch(%r{^test/(.*)/?(.*)_test\.rb$})
  watch('test/test_helper.rb') { 'test' }
  watch('config/routes.rb')    { 'test' }
  watch(%r{^app/models/(.*?)\.rb$}) do |matches|
    "test/models/#{matches[1]}_test.rb"
  end
  watch(%r{^app/controllers/(.*?)_controller\.rb$}) do |matches|
    resource_tests(matches[1])
  end
  watch(%r{^app/views/([^/]*?)/.*\.html\.erb$}) do |matches|
    ["test/controllers/#{matches[1]}_controller_test.rb"] +
    integration_tests(matches[1])
  end
  watch(%r{^app/helpers/(.*?)_helper\.rb$}) do |matches|
    integration_tests(matches[1])
  end
  watch('app/views/layouts/application.html.erb') do
    'test/integration/site_layout_test.rb'
  end
  watch('app/helpers/sessions_helper.rb') do
    integration_tests << 'test/helpers/sessions_helper_test.rb'
  end
  watch('app/controllers/sessions_controller.rb') do
    ['test/controllers/sessions_controller_test.rb',
     'test/integration/users_login_test.rb']
  end
  watch('app/controllers/account_activations_controller.rb') do
    'test/integration/users_signup_test.rb'
  end
end

# Returns the integration tests corresponding to the given resource.
def integration_tests(resource = :all)
  if resource == :all
    Dir["test/integration/*"]
  else
    Dir["test/integration/#{resource}_*.rb"]
  end
end

# Returns the controller tests corresponding to the given resource.
def controller_test(resource)
  "test/controllers/#{resource}_controller_test.rb"
end

# Returns all tests for the given resource.
def resource_tests(resource)
  integration_tests(resource) << controller_test(resource)
end

但是当我在rails目录的根目录中运行后卫时,我遇到了以下问题..

11:53:04 - INFO - Guard::Test 2.0.6 is running, with Test::Unit 3.1.3!
11:53:04 - INFO - Guard is now watching at       '/../../Documents/Projects/..'
[1] guard(main)>
11:53:06 - INFO - Run all
11:53:06 - INFO - Running all tests
/*/*/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/guard-test-2.0.6/lib/guard/test/guard_test_runner.rb:1:in `require': cannot load such  file -- test/unit/ui/console/testrunner (LoadError)
from /../../.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/guard-test-2.0.6/lib/guard/test/guard_test_runner.rb:1:in `<top (required)>'
from -e:1:in `require'
[1] guard(main)>

有人有任何想法吗?

2 个答案:

答案 0 :(得分:0)

我在使用minitest和Rails 4时遇到了同样的问题。我补充道:

gem guard
gem guard-minitest

到我的Gemfile,然后使用guard init minitest生成保护文件,一切正常。

答案 1 :(得分:0)

我也有类似的经历。在我通过在终端中运行以下代码初始化项目中的 Guard gem后,问题就开始了。

bundle exec guard init

我尝试了很多解决此问题的方法。如

  1. 卸载 Guard 宝石
  2. 卸载 Guard-minitest 宝石
  3. 在项目的根目录中删除 Guardfile

但是似乎没有一个起作用,因为我仍然面临着同样的问题。我要做的就是重新创建项目,并跳过了 Guard gem和 Guard-minitest gem的安装和初始化。

我猜这是宝石的不兼容问题。

仅此而已。

我希望这会有所帮助