【发布时间】:2011-10-16 14:30:29
【问题描述】:
是否有类似于自动测试的 ctrl+c 来强制运行所有规范?我仍在努力微调我的 .Guardfile,但目前我可以在不重新启动保护的情况下强制运行所有规范吗? ctrl+c 退出守卫。
【问题讨论】:
-
所选答案现已过期。
标签: ruby-on-rails testing rspec guard
是否有类似于自动测试的 ctrl+c 来强制运行所有规范?我仍在努力微调我的 .Guardfile,但目前我可以在不重新启动保护的情况下强制运行所有规范吗? ctrl+c 退出守卫。
【问题讨论】:
标签: ruby-on-rails testing rspec guard
Mark 建议的 posix 信号不再用于与警卫交互。有关新的交互方式,请参阅README 中标题为“交互”的部分。
要触发每个守卫的run_all 方法,只需在守卫终端中按回车即可。要触发 rspec 的 run_all 方法,请输入 rspec 并回车。
【讨论】:
可能最简单的做法是use Spork,然后简化您的 Guardfile:
# Guardfile
guard 'rspec', :version => 2, :cli => '--drb' do # :cli => is important!
watch(%r{^spec/}) { "spec" }
watch(%r{^app/}) { "spec" }
watch('config/routes.rb') { "spec" }
end
当您保存 spec、app 或 routes.rb 中的任何内容时,这将运行 spec 文件夹中的任何内容,并且会为您节省大量时间。
使用growl (mac) 或libnotify (linux) gem 来获取弹出通知。然后您只需在编辑器中编写代码,每次保存后不久您都会收到弹出式通过/失败通知。如果是通过,您只需继续编码 - 如果是失败,您会弹出到终端并检查错误是什么。
【讨论】:
https://github.com/guard/guard#interactions
Guard 无事可做时,您可以与 Guard 交互并输入命令。 Guard 理解以下命令:
↩: Run all Guards.
h, help: Show a help of the available interactor commands.
r, reload: Reload all Guards.
n, notification: Toggle system notifications on and off.
p, pause: Toggles the file modification listener. The prompt will change to p> when paused. This is useful when switching Git branches, rebase Git or change whitespace.
e, exit: Stop all Guards and quit Guard.
所以,基本上你进入 Guard 正在运行的终端并按回车键。
【讨论】:
r 来保护它即可重新加载并运行所有测试。例如:[5] guard(main)> r。现在我想知道是否有一种方法可以添加一个从 sublime-text 2 触发 guard(main)> r 的快捷键?