diff --git a/tests/functional/doubles_test.sh b/tests/functional/doubles_test.sh new file mode 100644 index 00000000..1bee6f11 --- /dev/null +++ b/tests/functional/doubles_test.sh @@ -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 +} diff --git a/tests/functional/fixtures/doubles_function.sh b/tests/functional/fixtures/doubles_function.sh old mode 100644 new mode 100755 diff --git a/tests/functional/fixtures/doubles_script.sh b/tests/functional/fixtures/doubles_script.sh old mode 100644 new mode 100755 diff --git a/tests/functional/snapshots/doubles_test_sh.test_mock_ps_when_executing_a_script.snapshot b/tests/functional/snapshots/doubles_test_sh.test_mock_ps_when_executing_a_script.snapshot new file mode 100644 index 00000000..77519f53 --- /dev/null +++ b/tests/functional/snapshots/doubles_test_sh.test_mock_ps_when_executing_a_script.snapshot @@ -0,0 +1,3 @@ +firefox 2.0 +Xorg 1.6 +jetbrains-toolbox 1.3 diff --git a/tests/functional/snapshots/doubles_test_sh.test_mock_ps_when_executing_a_sourced_function.snapshot b/tests/functional/snapshots/doubles_test_sh.test_mock_ps_when_executing_a_sourced_function.snapshot new file mode 100644 index 00000000..77519f53 --- /dev/null +++ b/tests/functional/snapshots/doubles_test_sh.test_mock_ps_when_executing_a_sourced_function.snapshot @@ -0,0 +1,3 @@ +firefox 2.0 +Xorg 1.6 +jetbrains-toolbox 1.3