如何格式化“Diff”黄瓜输出

发布于 2024-11-06 05:54:17 字数 481 浏览 0 评论 0原文

我有一个场景大纲,它将方法的结果与应返回的数组进行比较。因此,当它们不匹配时,我会得到一系列这样的语句:

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"]

这不是最简洁或最有用的输出。像这样显示会更有帮助:

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

这样我可以立即看到哪些值是附加的或缺失的。

I have a scenario outline that compares the results of a method 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〃安静 2024-11-13 05:54:17

使用数组差分法:

(expected_array - actual_array).should == []

Use the Array difference method:

(expected_array - actual_array).should == []
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文