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

Fix test doubles #232

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
64 changes: 64 additions & 0 deletions tests/functional/doubles_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

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

assert_match_snapshot "$(./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_when_executing_a_script() {
spy ps
spy awk
spy head

./tests/functional/fixtures/doubles_script.sh

assert_have_been_called ps
assert_have_been_called awk
assert_have_been_called head
}

function test_spy_commands_called_when_executing_a_sourced_function() {
source ./tests/functional/fixtures/doubles_function.sh
spy ps
spy awk
spy head

top_mem

assert_have_been_called ps
assert_have_been_called awk
assert_have_been_called head
}

function test_spy_commands_called_once_when_executing_a_script() {
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
}
Empty file modified tests/functional/fixtures/doubles_function.sh
100644 β†’ 100755
Empty file.
Empty file modified tests/functional/fixtures/doubles_script.sh
100644 β†’ 100755
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
firefox 2.0
Xorg 1.6
jetbrains-toolbox 1.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
firefox 2.0
Xorg 1.6
jetbrains-toolbox 1.3
Loading