Skip to content

Commit

Permalink
Create (and use) assert_contains
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Dec 8, 2016
1 parent 05c4a75 commit 117162a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions test/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
8 changes: 4 additions & 4 deletions test/test-bash-completion.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit 117162a

Please sign in to comment.