我已经为您实施了@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”代表未决。
代码远非完美,请随意批评和更改。
希望这会有所帮助。如果您有任何问题,请告诉我。