【问题标题】:Rails: Why isn't Guard waiting?Rails:为什么 Guard 不等待?
【发布时间】:2014-01-07 23:35:11
【问题描述】:

我正在尝试使用Guard 而不是Autotest 代替RSpec,但我对它的行为有些困惑。当我运行bundle exec guard 时,它只会启动一个pry 窗口。我认为它应该表现得像 Autotest 一样,每次发生变化时它都会继续在后台运行测试。我在这里错过了什么?

当我启动 bundle exec guard 时,我得到了:

18:52:44 - INFO - Guard is using TerminalTitle to send notifications.
18:52:44 - INFO - Guard::RSpec is running
18:52:44 - INFO - Guard is now watching at '/path/to/my/application'
[1] guard(main)> 

我真的不知道该怎么做。

【问题讨论】:

  • 你安装了guard-rspec吗?
  • 是的 - 我只是不确定如何运行它。
  • 这就是你应该得到的。让该窗口在后台保持打开状态,每当您进行更改并且 Guard 运行您的测试时,它都会在那里显示测试输出。
  • 但它弹出了一个交互式外壳 - 似乎没有任何进程正在运行,我应该在后台运行。
  • 你看过截屏视频吗?见github.com/guard/guard#screencast

标签: ruby-on-rails rspec guard autotest


【解决方案1】:

您是否生成了 Guardfile? (./Guardfile 在您的应用程序目录中)。我的看起来像这样:

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard :rspec do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

  # Rails example
  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$})          { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }

  # Capybara features specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$})     { |m| "spec/features/#{m[1]}_spec.rb" }

  # Turnip features and steps
  watch(%r{^spec/acceptance/(.+)\.feature$})
  watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$})   { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end

您上面列出的输出看起来是正确的,Guard 为您提供了一个交互式 shell 并在文件更改时触发。

【讨论】:

    【解决方案2】:

    Guard 正在运行 Pry 以供用户与之交互。可能你还没有设置在启动时运行 RSpec 守卫。要手动运行它,请键入rspec 并按回车键。它会运行你的 Guard。要运行所有守卫(如果您有多个守卫),只需键入 all 并按回车键。

    PS Guard 仍在监视并会在文件更改时运行您的Guard,但它显示 Pry 提示以允许用户交互(如上所述)。

    【讨论】:

      【解决方案3】:

      使用-i 选项运行它应该会有所帮助

      bundle exec guard -i
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-12
        • 2022-01-21
        • 2021-05-29
        • 1970-01-01
        • 2021-08-02
        相关资源
        最近更新 更多