【问题标题】:How to compare results of two RSpec suite runs?如何比较两个 RSpec 套件运行的结果?
【发布时间】:2011-08-12 22:40:50
【问题描述】:

我有一个相当大的规范套件 (watirspec),我正在针对 Ruby gem (safariwatir) 运行它,并且有很多失败:

1002 examples, 655 failures, 1 pending

当我在 gem 中进行更改并再次运行套件时,有时会通过很多以前失败的规范(本例中为 52 个):

1002 examples, 603 failures, 1 pending

我想知道哪些以前失败的规范现在通过了,当然还有以前通过的规范现在是否失败了。我现在比较结果的方法是使用--format documentation 选项运行测试并将结果输出到文本文件,然后对文件进行比较:

rspec --format documentation --out output.txt

有没有更好的方法?比较文本文件并不是查看更改内容的最简单方法。

【问题讨论】:

    标签: ruby rspec rspec2


    【解决方案1】:

    只需像现在一样将结果保存到文件中,然后使用一些随机比较工具来比较这些结果。

    【讨论】:

    • 这就是我现在正在做的,但是文件这么大的时候不容易看到变化。
    【解决方案2】:

    我不知道有什么东西可以做到这一点。说过,如果你非常需要它,你不介意花一些时间破解你自己的格式化程序,看看Spec::Runner::Formatter::BaseFormatter。它有很好的记录。

    【讨论】:

      【解决方案3】:

      我已经为您实施了@Serabe 的解决方案。见要点:https://gist.github.com/1142145

      将文件my_formatter.rb 放入您的规范文件夹并运行rspec --formatter MyFormatter。格式化程序会将当前运行结果与之前的运行结果进行比较,并将差异输出为表格。

      注意:格式化程序在当前文件夹中创建/覆盖文件result.txt

      示例用法:

      D:\Projects\ZPersonal\equatable>rspec spec --format MyFormatter
      ..........
      No changes since last run
      
      Finished in 0.011 seconds
      10 examples, 0 failures
      

      No changes since last run 行已由格式化程序添加。

      现在我故意破坏了一个并重新运行 rspec:

      D:\Projects\ZPersonal\equatable>rspec spec --format MyFormatter
      ..F.......
      Affected tests (1).
      PS CS Description
      .  F  Equatable#== should be equal to the similar sock
      PS - Previous Status
      CS - Current Status
      
      Failures:
      
        1) Equatable#== should be equal to the similar sock
           Failure/Error: subject.should == Sock.new(10, :black, 0)
             expected: #<Sock:0x2fbb930 @size=10, @color=:black, @price=0>
                  got: #<Sock:0x2fbbae0 @size=10, @color=:black, @price=20> (using ==)
             Diff:
             @@ -1,2 +1,2 @@
             -#<Sock:0x2fbb930 @color=:black, @price=0, @size=10>
             +#<Sock:0x2fbbae0 @color=:black, @price=20, @size=10>
           # ./spec/equatable_spec.rb:30:in `block (3 levels) in <top (required)>'
      
      Finished in 0.008 seconds
      10 examples, 1 failure
      
      Failed examples:
      
      rspec ./spec/equatable_spec.rb:29 # Equatable#== should be equal to the similar sock
      

      格式化程序添加了受影响规格的表格:

      Affected tests (1).
      PS CS Description
      .  F  Equatable#== should be equal to the similar sock
      PS - Previous Status
      CS - Current Status
      

      如果当前运行和之前运行的某些规范状态不同,格式化程序会输出之前的状态、当前状态和规范描述。 '。'代表通过的规范,“F”代表失败,“P”代表未决。

      代码远非完美,请随意批评和更改。

      希望这会有所帮助。如果您有任何问题,请告诉我。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多