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
}
Right now
bashunit::spy thingessentially 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 1orbashunit::spy thing mock_thingfor 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: