Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve the test test_mock_ps_when_executing_a_script #382

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/test_doubles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ function assert_have_been_called_times() {
local actual
actual="${variable}_times"
local label="${3:-$(helper::normalize_test_function_name "${FUNCNAME[1]}")}"

if [[ -z "${!actual-}" && $expected -ne 0 || ${!actual-0} -ne $expected ]]; then
state::add_assertions_failed
console_results::print_failed_test "${label}" "${command}" "to has been called" "${expected} times"
Expand Down
43 changes: 43 additions & 0 deletions tests/functional/doubles_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

function test_mock_ps_when_executing_a_script() {
mock ps cat ./tests/functional/fixtures/doubles_ps_output

assert_match_snapshot "$(source ./tests/functional/fixtures/doubles_script.sh)"
}

function test_mock_ps_when_executing_a_sourced_function() {
source ./tests/functional/fixtures/doubles_function.sh
mock ps cat ./tests/functional/fixtures/doubles_ps_output

assert_match_snapshot "$(top_mem)"
}

function test_spy_commands_called_once_when_executing_a_script() {
skip "not working while executing commands outside a function"
return

spy ps
spy awk
spy head

./tests/functional/fixtures/doubles_script.sh

assert_have_been_called_times 1 ps
assert_have_been_called_times 1 awk
assert_have_been_called_times 1 head
}

function test_spy_commands_called_once_when_executing_a_sourced_function() {

source ./tests/functional/fixtures/doubles_function.sh
spy ps
spy awk
spy head

top_mem

assert_have_been_called_times 1 ps
assert_have_been_called_times 1 awk
assert_have_been_called_times 1 head
}
Loading