Skip to content

Commit

Permalink
refactor: rename _cleanup_spy_calls as _clean_all_spy_calls
Browse files Browse the repository at this point in the history
  • Loading branch information
edouard-lopez committed Aug 31, 2023
1 parent 1fce883 commit fe70f3c
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion tests/_pure_check_for_new_release.test.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/mocks/mocks.fish
source (status dirname)/mocks/spectra.fish
source (status dirname)/../functions/_pure_check_for_new_release.fish
@echo (_print_filename (status filename))

Expand Down
4 changes: 2 additions & 2 deletions tests/_pure_detect_container_by_pid_method.test.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/mocks/mocks.fish
source (status dirname)/mocks/spectra.fish
source (status dirname)/../functions/_pure_detect_container_by_pid_method.fish
@echo (_print_filename (status filename))

Expand All @@ -17,7 +17,7 @@ end
function before_each
set --global proc_sched /tmp/1/sched
functions --erase head
_cleanup_spy_calls
_clean_all_spy_calls
end

function _create_proc_sched_file --argument-names proc_sched
Expand Down
4 changes: 2 additions & 2 deletions tests/_pure_k8s_context.test.fish
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/mocks/mocks.fish
source (status dirname)/mocks/spectra.fish
source (status dirname)/../functions/_pure_k8s_context.fish
@echo (_print_filename (status filename))


function before_each
functions --erase head
_cleanup_spy_calls
_clean_all_spy_calls
end

before_each
Expand Down
4 changes: 2 additions & 2 deletions tests/_pure_k8s_namespace.test.fish
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/mocks/mocks.fish
source (status dirname)/mocks/spectra.fish
source (status dirname)/../functions/_pure_k8s_namespace.fish
@echo (_print_filename (status filename))


function before_each
functions --erase head
_cleanup_spy_calls
_clean_all_spy_calls
end


Expand Down
2 changes: 1 addition & 1 deletion tests/_pure_prefix_root_prompt.test.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/mocks/mocks.fish
source (status dirname)/mocks/spectra.fish
source (status dirname)/../functions/_pure_prefix_root_prompt.fish
@echo (_print_filename (status filename))

Expand Down
2 changes: 1 addition & 1 deletion tests/_pure_prompt.test.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/mocks/mocks.fish
source (status dirname)/mocks/spectra.fish
source (status dirname)/../functions/_pure_prompt.fish
source (status dirname)/../functions/_pure_prompt_jobs.fish
source (status dirname)/../functions/_pure_prompt_virtualenv.fish
Expand Down
2 changes: 1 addition & 1 deletion tests/_pure_prompt_container.test.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/mocks/mocks.fish
source (status dirname)/mocks/spectra.fish
source (status dirname)/../functions/_pure_is_inside_container.fish
source (status dirname)/../functions/_pure_user_at_host.fish
source (status dirname)/../functions/_pure_prompt_container.fish
Expand Down
2 changes: 1 addition & 1 deletion tests/_pure_prompt_git_branch.test.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/mocks/mocks.fish
source (status dirname)/mocks/spectra.fish
source (status dirname)/../functions/_pure_prompt_git_branch.fish
source (status dirname)/../functions/_pure_parse_git_branch.fish
@echo (_print_filename (status filename))
Expand Down
2 changes: 1 addition & 1 deletion tests/_pure_prompt_git_dirty.test.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/mocks/mocks.fish
source (status dirname)/mocks/spectra.fish
source (status dirname)/../functions/_pure_prompt_git_dirty.fish
@echo (_print_filename (status filename))

Expand Down
2 changes: 1 addition & 1 deletion tests/_pure_prompt_git_pending_commits.test.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/mocks/mocks.fish
source (status dirname)/mocks/spectra.fish
source (status dirname)/../functions/_pure_prompt_git_pending_commits.fish
@echo (_print_filename (status filename))

Expand Down
2 changes: 1 addition & 1 deletion tests/_pure_prompt_git_stash.test.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/mocks/mocks.fish
source (status dirname)/mocks/spectra.fish
source (status dirname)/../functions/_pure_prompt_git_stash.fish
@echo (_print_filename (status filename))

Expand Down
2 changes: 1 addition & 1 deletion tests/_pure_prompt_jobs.test.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/mocks/mocks.fish
source (status dirname)/mocks/spectra.fish
source (status dirname)/../functions/_pure_prompt_jobs.fish
@echo (_print_filename (status filename))

Expand Down
2 changes: 1 addition & 1 deletion tests/_pure_prompt_k8s.test.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/mocks/mocks.fish
source (status dirname)/mocks/spectra.fish
source (status dirname)/../functions/_pure_prompt_k8s.fish
source (status dirname)/../functions/_pure_k8s_context.fish
source (status dirname)/../functions/_pure_k8s_namespace.fish
Expand Down
4 changes: 2 additions & 2 deletions tests/_pure_prompt_new_line.test.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/mocks/mocks.fish
source (status dirname)/mocks/spectra.fish
source (status dirname)/../functions/_pure_is_single_line_prompt.fish
source (status dirname)/../functions/_pure_prompt_beginning.fish
source (status dirname)/../functions/_pure_prompt_new_line.fish
Expand All @@ -14,7 +14,7 @@ before_all

function before_each
source (status dirname)/../functions/_pure_prompt_beginning.fish # restore function
_cleanup_spy_calls
_clean_all_spy_calls
end


Expand Down
2 changes: 1 addition & 1 deletion tests/_pure_prompt_symbol.test.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/mocks/mocks.fish
source (status dirname)/mocks/spectra.fish
source (status dirname)/../functions/_pure_prompt_symbol.fish
source (status dirname)/../functions/_pure_get_prompt_symbol.fish
@echo (_print_filename (status filename))
Expand Down
2 changes: 1 addition & 1 deletion tests/_pure_user_at_host.test.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/mocks/mocks.fish
source (status dirname)/mocks/spectra.fish
source (status dirname)/../functions/_pure_user_at_host.fish
@echo (_print_filename (status filename))

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/constants.fish
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source (status dirname)/../mocks/mocks.fish
source (status dirname)/../mocks/spectra.fish

set --global SUCCESS 0
set --global FAILURE 1
Expand Down
22 changes: 11 additions & 11 deletions tests/mocks/mocks.fish → tests/mocks/spectra.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# See: https://en.wikipedia.org/wiki/Phasmatodea

function _mock \
--description "Invoke a mock function located in tests/mocks/" \
--description "Mock a function using the mock in `tests/mocks/`" \
--argument-names \
function_name # name of the method to mock

Expand All @@ -10,7 +12,7 @@ function _mock \
end
end

function backup \
function _backup_before_mocking \
--description "Backup a function by copying to prefixed function" \
--argument-names \
function_name
Expand All @@ -29,7 +31,7 @@ function _mock_exit_status \
status_code # response to return

echo $status_code >/tmp/$function_name.mock_status_code
backup $function_name
_backup_before_mocking $function_name

# redefine function to return mock status_code
function $function_name \
Expand All @@ -49,7 +51,7 @@ function _mock_response \
response # response to return

echo "$response" >/tmp/$function_name.mock_response
backup $function_name
_backup_before_mocking $function_name

# redefine function to return mock response
function $function_name \
Expand All @@ -62,9 +64,8 @@ function _mock_response \
set --global --append __mocks_backup __backup_$function_name
end


function _clean_mock \
--description "Clean a mock function" \
--description "Clean a mock function (warning: erase the function)" \
--argument-names \
function_name

Expand All @@ -88,19 +89,18 @@ function _clean_all_mocks \
end

function _spy \
--description "Create a spy around method" \
--description "Create a spy method so you can check it's been called with `_has_called`" \
--argument-names \
function_name # name of the method to spy

backup $function_name
_backup_before_mocking $function_name

function $function_name
echo (status current-function) >/tmp/(status current-function).mock_calls
end # spy
end


function _cleanup_spy_calls
function _clean_all_spy_calls
for mock_calls in /tmp/*.mock_calls
if test -r $mock_calls
rm -f $mock_calls
Expand All @@ -109,7 +109,7 @@ function _cleanup_spy_calls
end

function _has_called \
--description "check spy method XYZ write to the /tmp/$function_name.mock_calls file when called" \
--description "check spy method has been called, i.e has written to the /tmp/$function_name.mock_calls" \
--argument-names \
function_name \
function_args # arguments to passed to the spy
Expand Down

0 comments on commit fe70f3c

Please sign in to comment.