9 个稳定版本
| 2.0.1 |
|
|---|---|
| 1.1.0 | 2023 年 9 月 25 日 |
| 1.0.7 | 2023 年 4 月 17 日 |
| 1.0.6 | 2022 年 12 月 27 日 |
| 1.0.2 | 2020 年 11 月 14 日 |
#55 in 测试
31,397 个月下载量
用于 16 crates
96KB
135 代码行
Expectorate
这是一个用于验证保存在文件中的预期输出的小型库。当需要更新内容以匹配新结果时,它可以使更新内容变得容易。
验证输出
假设你有一个名为 compose() 的函数,它生成一个字符串,你有一个名为 lyrics.txt 的文件,其中包含预期的输出。你可以这样比较实际输出
let actual: &str = compose();
assert_content("lyrics.txt", actual);
如果不匹配,你会看到这样的输出

白色表示内容匹配。红色表示文件中缺少内容。绿色表示文件中添加了内容。
如果我们想接受 compose() 的更改,我们可以简单地运行 EXPECTORATE=overwrite。假设 lyrics.txt 已检查入库,git diff 将显示类似以下内容
diff --git a/examples/lyrics.txt b/examples/lyrics.txt
index e4104c1..ea6beaf 100644
--- a/examples/lyrics.txt
+++ b/examples/lyrics.txt
@@ -1,5 +1,2 @@
-No one hits like Gaston
-Matches wits like Gaston
-In a spitting match nobody spits like Gaston
+In a testing match nobody tests like Gaston
I'm especially good at expectorating
-Ten points for Gaston
谓词(特性:谓词)
Expectorate 可用于你可能使用 predicates crate 的地方。如果你正在使用 predicates::path::eq_file,你可以改用 expectorate::eq_file 或 expectorate::eq_file_or_panic。像上面一样填充或更新指定的文件。
依赖项
~1.1–8.5MB
~59K SLoC