【问题标题】:guard_test_runner.rb:1:in `require': cannot load such fileguard_test_runner.rb:1:in `require': 不能加载这样的文件
【发布时间】:2015-09-15 11:37:29
【问题描述】:

我正在尝试在我的用户目录中创建一个所有 Rails 项目都可以运行的 .Guardfile。

.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 目录的根目录中运行 guard 时,我遇到了以下问题..

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)>

有人有什么想法吗?

【问题讨论】:

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


    【解决方案1】:

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

    gem guard
    gem guard-minitest
    

    到我的Gemfile,然后用guard init minitest生成保护文件,一切都开始正常工作了。

    【讨论】:

      【解决方案2】:

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

      bundle exec guard init
      

      我尝试了很多解决方案来解决这个问题。比如

      1. 卸载 Guard gem
      2. 卸载 Guard-minitest gem
      3. 删除我项目根目录下的Guardfile

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

      我猜是 gem 不兼容的问题。

      就是这样。

      我希望这会有所帮助

      【讨论】:

        猜你喜欢
        • 2012-12-27
        • 2014-06-28
        • 1970-01-01
        • 1970-01-01
        • 2015-11-24
        • 2015-03-25
        • 2019-06-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多