From 512c1b7b263136fe2fd9d3422e4faf4cb71a7188 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 15 Jul 2013 21:14:53 +0100 Subject: Add yarn tests for clab --- clab.yarn | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 clab.yarn diff --git a/clab.yarn b/clab.yarn new file mode 100644 index 0000000..2475936 --- /dev/null +++ b/clab.yarn @@ -0,0 +1,83 @@ +Black box tests for clab +======================== + +Clab is a command line address book application. +It has no interactive features, so black box testing it +is fairly easy. + +Let's start with an empty database. + + SCENARIO empty database + GIVEN an empty database + + WHEN listing all records + THEN nothing is listed + + WHEN searching for Alice + THEN output is empty + + WHEN mutt-querying for Alice + THEN no matches + +Next, let's add records for Alice and Bob, and make +sure searches find only the right records. + + SCENARIO database with records + GIVEN an empty database + AND a record for "Alice Atherton" with e-mail alice@example.com + AND a record for "Bob Bobbington" with e-mail bob@example.com + + WHEN listing all records + THEN Alice is found + AND Bob is found + + WHEN searching for Alice + THEN Alice is found + AND Bob is not found + + WHEN mutt-querying for Alice + THEN Alice is found + AND alice@example.com is found + AND Bob is not found + AND bob@example.com is not found + +Implementation +-------------- + +These implement the various steps. + + IMPLEMENTS GIVEN an empty database + mkdir "$DATADIR/db" + + IMPLEMENTS GIVEN a record for "([^"]+)" with e-mail (.*) + cat << EOF > "$DATADIR/db/$MATCH_1.yaml" + name: $MATCH_1 + email: $MATCH_2 + EOF + + IMPLEMENTS WHEN listing all records + ./clab --no-default-config --db "$DATADIR/db" list > "$DATADIR/output" + + IMPLEMENTS WHEN searching for (.*) + ./clab --no-default-config --db "$DATADIR/db" find "$MATCH_1" > "$DATADIR/output" + + IMPLEMENTS WHEN mutt-querying for (.*) + ./clab --no-default-config --db "$DATADIR/db" mutt-query "$MATCH_1" > "$DATADIR/output" || true + + IMPLEMENTS THEN nothing is listed + stat -c %s "$DATADIR/output" | grep -x 0 + + IMPLEMENTS THEN output is empty + stat -c %s "$DATADIR/output" | grep -x 0 + + IMPLEMENTS THEN no matches + diff -u "$DATADIR/output" - << EOF + No matches + EOF + + IMPLEMENTS THEN (.*) is found + set -x + grep -F "$MATCH_1" "$DATADIR/output" + + IMPLEMENTS THEN (.*) is not found + ! grep -F "$MATCH_1" "$DATADIR/output" -- cgit v1.2.1