-
-
Notifications
You must be signed in to change notification settings - Fork 46
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Right now bashunit::spy thing essentially creates a no-op mock that always returns 0. It would be useful to be able to add an optional exit code or mock implementation, e.g.: bashunit::spy thing 1 or bashunit::spy thing mock_thing for testing different branches in a function while also being able to make assertions on the spy itself.
Larger example of what I'm trying to do:
# function being spied upon
function thing() {
if [ "${#1}" -lt 3 ]; then
return 0
else
return 1
fi
}
# function being tested
function do_things() {
for word in "$@"; do
if ! thing "$word"; then
return 0
fi
done
return 1
}
# test cases
function test_do_things() {
bashunit::spy thing
do_things "hi" "my" "name" "is" "bob"
# FAILS because thing spy always returns 0
assert_exit_code 0
# FAILS because do_things didn't return early
assert_have_been_called_times 3 thing
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Projects
Status
No status