Skip to content

Commit

Permalink
chore: add test of spies failing to fix on main
Browse files Browse the repository at this point in the history
  • Loading branch information
khru committed Oct 17, 2024
1 parent 1a6d915 commit ef61f1f
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/functional/doubles_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

function test_mock_ps_when_executing_a_script() {
skip "The mock is not been able to cat the output of the cat"
return
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() {
skip "The mock is not been able to cat the output of the cat"
return
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() {
skip "The spies can not spy inside the scope of the function"
return

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
}
5 changes: 5 additions & 0 deletions tests/functional/fixtures/doubles_function.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

function top_mem() {
ps -eo cmd,%mem --sort=-%mem | awk '$2 >= 1.0 {print $0}' | head -n 3
}
8 changes: 8 additions & 0 deletions tests/functional/fixtures/doubles_ps_output
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CMD %MEM
firefox 2.0
Xorg 1.6
jetbrains-toolbox 1.3
vitepress 1.0
bashunit 0.1
bash 0.0
ps 0.0
3 changes: 3 additions & 0 deletions tests/functional/fixtures/doubles_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

ps -eo cmd,%mem --sort=-%mem | awk '$2 >= 1.0 {print $0}' | head -n 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
firefox 2.0
Xorg 1.6
jetbrains-toolbox 1.3

0 comments on commit ef61f1f

Please sign in to comment.