#file-content #fixture #test

dev expectorate

Library for comparing output to file contents with simple updating

9 stable releases

2.0.1 Mar 25, 2021
1.1.0 Sep 25, 2023
1.0.7 Apr 17, 2023
1.0.6 Dec 27, 2022
1.0.2 Nov 14, 2020

#49 in Testing

Download history 6227/week @ 2024-01-05 4927/week @ 2024-01-12 6316/week @ 2024-01-19 4083/week @ 2024-01-26 5281/week @ 2024-02-02 4831/week @ 2024-02-09 5105/week @ 2024-02-16 4542/week @ 2024-02-23 3916/week @ 2024-03-01 5571/week @ 2024-03-08 6410/week @ 2024-03-15 5719/week @ 2024-03-22 5251/week @ 2024-03-29 6384/week @ 2024-04-05 6494/week @ 2024-04-12 5841/week @ 2024-04-19

25,108 downloads per month
Used in 15 crates

Apache-2.0

96KB
135 lines

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

Predicates (feature: predicates)

Expectorate can be used in places where you might use the predicates crate. If you're using predicates::path::eq_file you can instead use expectorate::eq_file or expectorate::eq_file_or_panic. Populate or update the specified file as above.

Dependencies

~0.9–9MB
~67K SLoC