#test #fixture

expectorate

Library for comparing output to file contents with simple updating

5 stable releases

2.0.1 Mar 25, 2021
1.0.4 Oct 1, 2021
1.0.3 Mar 25, 2021
1.0.2 Nov 14, 2020
1.0.1 Aug 7, 2020

#46 in Testing

Download history 49/week @ 2021-06-30 97/week @ 2021-07-07 51/week @ 2021-07-14 34/week @ 2021-07-21 115/week @ 2021-07-28 120/week @ 2021-08-04 54/week @ 2021-08-11 26/week @ 2021-08-18 66/week @ 2021-08-25 89/week @ 2021-09-01 143/week @ 2021-09-08 132/week @ 2021-09-15 187/week @ 2021-09-22 231/week @ 2021-09-29 360/week @ 2021-10-06 386/week @ 2021-10-13

393 downloads per month
Used in dropshot

Apache-2.0

250KB

Expectorate

This is a little library to validate expected output saved in files. It makes it easy to update that content when it should be updated to match the new results.

Validating Output

Say you have a function compose() that produces a string and you have a file named lyrics.txt that contain the expected output. You can compare the actual output like this:

    let actual: &str = compose();
    assert_content("lyrics.txt", actual);

If the output doesn't match, you'll see output like this:

White means that the content matches. Red means that content from the file was missing. Green means that content not in the file was added.

If we want to accept the changes from compose() we'd simply run with EXPECTORATE=overwrite. Assuming lyrics.txt is checked in, git diff will show you something like this:

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

Dependencies

~155KB