Skip to content

Add assert_not_called test double #410

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

Merged
merged 3 commits into from
May 30, 2025
Merged
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
23 changes: 23 additions & 0 deletions docs/test-doubles.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,26 @@ function test_failure() {
}
```
:::

## assert_not_called
> `assert_not_called "spy"`

Reports an error if `spy` has been executed at least once.

::: code-group
```bash [Example]
function test_success() {
spy ps

assert_not_called ps
}

function test_failure() {
spy ps

ps

assert_not_called ps
}
```
:::
6 changes: 6 additions & 0 deletions src/test_doubles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,9 @@ function assert_have_been_called_times() {

state::add_assertions_passed
}

function assert_not_called() {
local command=$1
local label="${2:-$(helper::normalize_test_function_name "${FUNCNAME[1]}")}"
assert_have_been_called_times 0 "$command" "$label"
}
18 changes: 18 additions & 0 deletions tests/unit/test_doubles_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,21 @@ function test_spy_called_with_different_arguments() {
assert_have_been_called_with "first_a first_b" ps 1
assert_have_been_called_with "second" ps 2
}

function test_spy_successful_not_called() {
spy ps

assert_not_called ps
}

function test_spy_unsuccessful_not_called() {
spy ps

ps

assert_same \
"$(console_results::print_failed_test "Spy unsuccessful not called" "ps" \
"to has been called" "0 times" \
"actual" "1 times")" \
"$(assert_not_called ps)"
}
Loading