RoR 教程第 3 章 - Guard 检测更改但未完全执行测试

RoR Tutorial Chapter 3 - Guard detects changes but doesn't fully execute tests

我目前正在关注这本书和视频,在视频中,Hartl 运行 是一个保护文件,因此它会在进行任何更改后自动 运行 进行测试。所以在视频中,当他在守卫模式下按下 return 时,它说:

17:35:31 - INFO - Running: test/controllers/static_pages_controller_test.rb

接着是

Started 

   2/2 [=======] 100% Time: 00:00:00, Time: 00:00:00

Finished in 0.214142s
2 tests, 2 assumptions, 0 failures, 0 errors, 0 skips
[1] guard(main)>

我假设测试已经实际执行。

但是当我对 /test/controllers/static_pages_controller_test.rb 进行更改时,守卫 运行s 但它 运行s 直到行 where is 说,就是这样:

INFO - Running: test/controllers/static_pages_controller_test.rb

我已经 运行 调试了守卫,这就是发生的事情:

chocoberry4@sample_app:~/workspace (static-pages) $ bundle exec guard -d
19:39:44 - DEBUG - Notiffany: gntp not available (Please add "gem 'ruby_gntp'" to your Gemfile and run your app with "bundle exec".).
19:39:44 - DEBUG - Notiffany: growl not available (Unsupported platform "linux-gnu").
19:39:44 - DEBUG - Notiffany: terminal_notifier not available (Unsupported platform "linux-gnu").
19:39:44 - DEBUG - Notiffany: libnotify not available (Please add "gem 'libnotify'" to your Gemfile and run your app with "bundle exec".).
19:39:44 - DEBUG - Command execution: which notify-send
19:39:44 - DEBUG - Notiffany: notifysend not available (libnotify-bin package is not installed).
19:39:44 - DEBUG - Notiffany: notifu not available (Unsupported platform "linux-gnu").
19:39:44 - DEBUG - Command execution: emacsclient --eval '1'
19:39:44 - DEBUG - Notiffany: emacs not available (Emacs client failed).
19:39:44 - DEBUG - Command execution: tmux -V
19:39:44 - DEBUG - Notiffany: file not available (No :path option given).
19:39:44 - DEBUG - Command execution: tmux -V
19:39:44 - DEBUG - Notiffany is using Tmux to send notifications.
19:39:44 - DEBUG - Command execution: tmux list-clients -F '#{client_tty}'
19:39:44 - DEBUG - Command execution: tmux show -t /dev/pts/1
19:39:44 - DEBUG - Command execution: tmux show -t /dev/pts/2
19:39:44 - DEBUG - Notiffany is using TerminalTitle to send notifications.
19:39:44 - DEBUG - Command execution: hash stty
19:39:44 - DEBUG - Guard starts all plugins
19:39:44 - DEBUG - Hook :start_begin executed for Guard::Minitest
19:39:44 - INFO - Guard::Minitest 2.3.1 is running, with Minitest::Unit 5.7.0!
19:39:44 - DEBUG - Hook :start_end executed for Guard::Minitest
19:39:44 - INFO - Guard is now watching at '/home/ubuntu/workspace'
19:39:44 - DEBUG - Start interactor
19:39:51 - DEBUG - Interactor was stopped or killed
19:39:51 - DEBUG - Hook :run_on_modifications_begin executed for Guard::Minitest
19:39:51 - INFO - Running: test/controllers/static_pages_controller_test.rb
19:39:51 - DEBUG - Command execution: tmux set -q status-left-bg red

然后我在这里对文件"test/controllers/static_pages_controller_test.rb"进行了更改...

19:39:51 - DEBUG - Start interactor
19:39:58 - DEBUG - Interactor was stopped or killed
19:39:58 - DEBUG - Hook :run_on_modifications_begin executed for Guard::Minitest
19:39:58 - INFO - Running: test/controllers/static_pages_controller_test.rb
19:39:58 - DEBUG - Command execution: tmux set -q status-left-bg red

19:39:58 - DEBUG - Start interactor
2 tests, 2 assumptions, 0 failures, 0 errors, 0 skips

表示守卫成功 运行 2个包含两个假设(assertions)的测试。

调试日志中的消息告诉您缺少依赖项。您可以使用 Hartl 建议的免费 cloud 9 和 heroku 设置来避免让自己头疼,因为它会正常工作 'out of the box'。

否则你需要仔细检查并添加调试抱怨的缺少的 gems,ruby_gntp 和 libnotify。之后您可能会遇到其他错误,但这是您需要开始的地方。 运行 bundle install 将它们添加到您的 gem 文件后。

编辑:(因为 OP 使用的是 Cloud9)

springgem 中存在一个错误,它会留下实例 运行ning,直到您的所有 cloud9 RAM 都被消耗并且 Guard 由于内存不足而无法完成。如果是这种情况,您的选择是终止 spring 个实例或重新启动您的应用并重试。但是随着您的测试套件随着教程的增加而增长,杀死 PID 或重新启动将变得太频繁而不必理会。最好的解决方案是不要在内存有限的免费 cloud9 帐户上使用 guard。当教程建议时 运行 bundle exec rake test

如果仍有问题,请检查您的 gem 文件是否与教程中的文件完全匹配。