【问题标题】:Guard gem - no such file or directory ERRORGuard gem - 没有这样的文件或目录错误
【发布时间】:2017-12-10 06:00:15
【问题描述】:

我目前正在阅读Ruby on Rails Tutorial by Michael Hartl 的第三章。在我们设置 Guard 的最后一节中,当我尝试运行所有测试时出现错误:

21:48:12 - INFO - Running: all tests
guard(main)> - No such file or directory - bin/rails test test/controllers/static_pages_controller_test.rb test/test_helper.rb

我不确定为什么会发生这种情况,因为当我从命令行运行 rails test 命令时,它会按预期工作。

保护文件:

# Defines the matching rules for Guard.
guard :minitest, spring: "bin/rails test", all_on_start: false do
  watch(%r{^test/(.*)/?(.*)_test\.rb$})
  watch('test/test_helper.rb') { 'test' }
  watch('config/routes.rb')    { integration_tests }
  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
  watch(%r{app/views/users/*}) do
    resource_tests('users') +
        ['test/integration/microposts_interface_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

【问题讨论】:

  • 我们需要查看您必须能够发现任何问题的代码。还是书中看到的代码失败了?
  • @OneNeptune 是的,代码和书中的一样。
  • 请在问题中添加您的Guardfile

标签: ruby-on-rails ruby guard


【解决方案1】:

所以在搞砸了很多之后,我只是删除了

spring: "bin/rails test"

在第一行。这修复了所有问题,测试套件现在自动运行。

【讨论】:

  • 似乎它试图将“bin/rails test”添加到查找文件的路径中,但这种模式不起作用。也许 5.1.4 的变化?也许 M.Hartl 会更新示例保护文件 - 我刚刚复制了他的并有那个错误。
【解决方案2】:

我通过切换来让它工作

guard :minitest, spring: 'bin/rails test', all_on_start: false do

guard :minitest, spring: 'rake test', all_on_start: false do

我的设置 导轨:5.0.1 红宝石:2.3.0p0(2015-12-25 修订版 53290

看完this post得到灵感

【讨论】:

    【解决方案3】:

    我在 Windows 10 上,从第二行删除 "bin/" 对我有用。然后它看起来像这样:

    guard :minitest, spring: "rails test", all_on_start: false do
    

    【讨论】:

      猜你喜欢
      • 2021-10-31
      • 1970-01-01
      • 2013-08-08
      • 2013-11-04
      • 2012-02-18
      • 2012-10-21
      • 2011-03-22
      • 2015-12-29
      • 2011-02-06
      相关资源
      最近更新 更多