Zentest - 如何在红色时停止自动测试

时间:2011-06-19 22:48:06

标签: ruby-on-rails autotest spork rspec-rails zentest

我正在尝试配置自动测试,以便在运行我的测试套件并且测试失败时,自动测试会停止测试并等待我再次测试之前进行更改。使用我当前的配置,当遇到失败的测试时,自动测试会不断地进行测试,这使得处理时有点麻烦(每次我遇到测试失败时都必须键入终端并停止自动测试服务器)。

我正在使用RSpec,Zentest和Spork开发一个rails应用程序。

相关宝石版本:

autotest (4.4.6)
rspec (2.6.0)
rspec-core (2.6.4)
rspec-expectations (2.6.0)
rspec-mocks (2.6.0)
rspec-rails (2.6.1)
spork (0.9.0.rc8)
ZenTest (4.5.0)

我的.autotest文件:

module Autotest::Notify
  def self.notify title, msg, img, pri='low', time=3000
    `notify-send -i #{img} -u #{pri} -t #{time} '#{msg}'`
  end

  Autotest.add_hook :ran_command do |autotest|
    results = [autotest.results].flatten.join("\n")
    output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/)
    folder = "~/.autotest_icons/"
    if output  =~ /[1-9]\d*\sfailures?/
      notify "FAIL:", "#{output}", folder+"failed.png", 'critical', 10000
    elsif output  =~ /[1-9]\d*\spending?/
      notify "PENDING:", "#{output}", folder+"pending.png", 'normal', 10000
    else
      notify "PASS:", "#{output}", folder+"passed.png"
    end
  end
end

注意:我的.autotest文件的大部分内容都是让linux中的弹出窗口显示,如果我的测试通过或失败。

我一直在寻找这个问题的答案并且没有运气,我发现很难掌握一些关于自动测试的好文档。我一直在为Zentest盯着RDoc已经有一段时间了,我一定是在遗漏一些东西。

非常感谢任何帮助,示例链接等。

2 个答案:

答案 0 :(得分:4)

我遇到了同样的问题,发现我的开发服务器正在写入日志文件。将此添加到我的.autotest文件后,问题就消失了:

Autotest.add_hook :initialize do |at|
  at.add_exception(%r{^\./\.git})
  at.add_exception(%r{^\./log})
end

答案 1 :(得分:1)

当我有一个将数据写入ZenTest正在监控的目录的gem时,我看到了与ZenTest类似的问题。 IIRC,它是一个进行全文搜索的宝石 - 搜索生成的索引文件触发ZenTest再次运行,从而重新生成索引。

我通过修改Growl通知来跟踪问题,告诉我哪些文件正在触发自动测试运行(当时我在Mac上运行)。

解决方案是在.autotest文件中添加异常/排除,告诉它忽略索引。

(我刚刚看到:Spork is repeatedly re-running failing tests in autotest听起来与你的问题非常相似)