开发者

How do I format the "Diff" output in cucumber

I have a scenario outline that compares the results of a meth开发者_运维技巧od to the array that should be returned. So I get a series of statements like this when they don't match:

expected: ["a", "b", "c", "d", "e", "f"]
     got: ["c", "d", "e", "f", "g"] (using ==)
Diff:
@@ -1,2 +1,8 @@
-["a", "b", "c", "d", "e", "f"]
+["c",
+ "d",
+ "e",
+ "f",
+ "g"]

This is not the most succinct or helpful output. It would be much more helpful to be dipslay like:

expected: ["a", "b", "c", "d", "e", "f"]
     got: ["c", "d", "e", "f", "g"] (using ==)
Diff:
@@ -1,2 +1,8 @@
-["a", "b"]
+["g"]

This way I could instantly see what values were additional or missing.


Use the Array difference method:

(expected_array - actual_array).should == []
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜