【问题标题】:Is there a way to force run all specs with guard + guard-rspec?有没有办法强制使用guard + guard-rspec 运行所有规范?
【发布时间】:2011-10-16 14:30:29
【问题描述】:

是否有类似于自动测试的 ctrl+c 来强制运行所有规范?我仍在努力微调我的 .Guardfile,但目前我可以在不重新启动保护的情况下强制运行所有规范吗? ctrl+c 退出守卫。

【问题讨论】:

  • 所选答案现已过期。

标签: ruby-on-rails testing rspec guard


【解决方案1】:

Mark 建议的 posix 信号不再用于与警卫交互。有关新的交互方式,请参阅README 中标题为“交互”的部分。

要触发每个守卫的run_all 方法,只需在守卫终端中按回车即可。要触发 rspec 的 run_all 方法,请输入 rspec 并回车。

【讨论】:

  • 当我从 Rails 应用程序中对我的规范或代码进行任何更改时,它会触发它的 run_all 方法,我可以这样做吗?
【解决方案2】:

可能最简单的做法是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

当您保存 specapproutes.rb 中的任何内容时,这将运行 spec 文件夹中的任何内容,并且会为您节省大量时间。

使用growl (mac) 或libnotify (linux) gem 来获取弹出通知。然后您只需在编辑器中编写代码,每次保存后不久您都会收到弹出式通过/失败通知。如果是通过,您只需继续编码 - 如果是失败,您会弹出到终端并检查错误是什么。

【讨论】:

  • 完全同意。 spork 是添加到 TDD 工具箱的绝佳工具。
【解决方案3】:

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 正在运行的终端并按回车键。

【讨论】:

  • 我刚刚回过头来注意到@balexand 已经给出了大致相同的答案。起初我并没有注意到他的回答,定位为从属于广告。当接受的答案是错误的(或者在这种情况下,已经过时)时,应该做一些事情。我尝试编辑已接受的答案,但被拒绝了……嗯……这种事情可能已经在 meta 上讨论过(毫无疑问)。
  • 这就是我要找的东西,谢谢。因此,只需添加 r 来保护它即可重新加载并运行所有测试。例如:[5] guard(main)> r。现在我想知道是否有一种方法可以添加一个从 sublime-text 2 触发 guard(main)> r 的快捷键?
猜你喜欢
  • 2012-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-18
  • 2013-04-27
  • 2013-03-05
  • 2014-09-21
  • 1970-01-01
相关资源
最近更新 更多