Crate expectorate

source ·
Expand description

This library is for comparing multi-line output to data stored in version controlled files. It makes it easy to update the contents when should be updated to match the new results.

Use it like this:

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

If the output doesn’t match, the program will panic! and emit the color-coded diffs.

To accept the changes from compose(), 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

Enable the predicates feature for compatibility with predicates via eq_file and eq_file_or_panic.

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.

Structs

Functions

  • Compare the contents of the file to the string provided
  • eq_filepredicates
    Creates a new predicate that ensures equality with the given file.
  • Creates a new predicate that ensures equality with the given file and panics if there’s a mismatch.