From 117162a6f7712ac1d72d0d52adf8c2e49851fc75 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Thu, 8 Dec 2016 15:42:36 +0100 Subject: [PATCH] Create (and use) assert_contains --- test/helpers.bash | 12 ++++++++++++ test/test-bash-completion.bats | 8 ++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/test/helpers.bash b/test/helpers.bash index 829edf6..e76c451 100644 --- a/test/helpers.bash +++ b/test/helpers.bash @@ -6,6 +6,18 @@ refute_exists() { assert [ ! -e "$1" ] } +assert_contains() { + local item + local items=(${@:2}) + for item in "${items[@]}"; do + if [[ "$item" == "$1" ]]; then + return 0 + fi + done + + fail "$1 not found in: ${items[@]}" +} + setupNotesEnv() { export NOTES_DIRECTORY="$(mktemp -d)" export NOTES_HOME="$(mktemp -d)" diff --git a/test/test-bash-completion.bats b/test/test-bash-completion.bats index 438d319..3b07cf9 100755 --- a/test/test-bash-completion.bats +++ b/test/test-bash-completion.bats @@ -17,10 +17,10 @@ teardown() { @test "Should list all commands" { touch $NOTES_DIRECTORY/note1.md _notes_complete_commands "" - assert_equal "${COMPREPLY[0]}" 'new' - assert_equal "${COMPREPLY[1]}" 'find' - assert_equal "${COMPREPLY[2]}" 'grep' - assert_equal "${COMPREPLY[3]}" 'open' + assert_contains "new" ${COMPREPLY[@]} + assert_contains "find" ${COMPREPLY[@]} + assert_contains "grep" ${COMPREPLY[@]} + assert_contains "open" ${COMPREPLY[@]} } @test "Should show matching note when found" {