diff --git a/tests/_pure_check_for_new_release.test.fish b/tests/_pure_check_for_new_release.test.fish index 8efbee89..e6a84c90 100644 --- a/tests/_pure_check_for_new_release.test.fish +++ b/tests/_pure_check_for_new_release.test.fish @@ -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)) diff --git a/tests/_pure_detect_container_by_pid_method.test.fish b/tests/_pure_detect_container_by_pid_method.test.fish index 19f6efea..9894816b 100644 --- a/tests/_pure_detect_container_by_pid_method.test.fish +++ b/tests/_pure_detect_container_by_pid_method.test.fish @@ -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)) @@ -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 diff --git a/tests/_pure_k8s_context.test.fish b/tests/_pure_k8s_context.test.fish index 7233247e..823e31d1 100644 --- a/tests/_pure_k8s_context.test.fish +++ b/tests/_pure_k8s_context.test.fish @@ -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 diff --git a/tests/_pure_k8s_namespace.test.fish b/tests/_pure_k8s_namespace.test.fish index fc0cc80f..7edc68a4 100644 --- a/tests/_pure_k8s_namespace.test.fish +++ b/tests/_pure_k8s_namespace.test.fish @@ -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 diff --git a/tests/_pure_prefix_root_prompt.test.fish b/tests/_pure_prefix_root_prompt.test.fish index ccae25b8..b898ffc1 100644 --- a/tests/_pure_prefix_root_prompt.test.fish +++ b/tests/_pure_prefix_root_prompt.test.fish @@ -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)) diff --git a/tests/_pure_prompt.test.fish b/tests/_pure_prompt.test.fish index f3151675..ab20e978 100644 --- a/tests/_pure_prompt.test.fish +++ b/tests/_pure_prompt.test.fish @@ -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 diff --git a/tests/_pure_prompt_container.test.fish b/tests/_pure_prompt_container.test.fish index e9e5404b..d685ee2a 100644 --- a/tests/_pure_prompt_container.test.fish +++ b/tests/_pure_prompt_container.test.fish @@ -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 diff --git a/tests/_pure_prompt_git_branch.test.fish b/tests/_pure_prompt_git_branch.test.fish index 2fb01b2a..0b45fe90 100644 --- a/tests/_pure_prompt_git_branch.test.fish +++ b/tests/_pure_prompt_git_branch.test.fish @@ -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)) diff --git a/tests/_pure_prompt_git_dirty.test.fish b/tests/_pure_prompt_git_dirty.test.fish index 9ac2cc53..752d78ba 100644 --- a/tests/_pure_prompt_git_dirty.test.fish +++ b/tests/_pure_prompt_git_dirty.test.fish @@ -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)) diff --git a/tests/_pure_prompt_git_pending_commits.test.fish b/tests/_pure_prompt_git_pending_commits.test.fish index 805c2003..2507a2ca 100644 --- a/tests/_pure_prompt_git_pending_commits.test.fish +++ b/tests/_pure_prompt_git_pending_commits.test.fish @@ -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)) diff --git a/tests/_pure_prompt_git_stash.test.fish b/tests/_pure_prompt_git_stash.test.fish index 64476d9c..fdcea997 100644 --- a/tests/_pure_prompt_git_stash.test.fish +++ b/tests/_pure_prompt_git_stash.test.fish @@ -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)) diff --git a/tests/_pure_prompt_jobs.test.fish b/tests/_pure_prompt_jobs.test.fish index 102a75e2..bdd39b3c 100644 --- a/tests/_pure_prompt_jobs.test.fish +++ b/tests/_pure_prompt_jobs.test.fish @@ -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)) diff --git a/tests/_pure_prompt_k8s.test.fish b/tests/_pure_prompt_k8s.test.fish index a8190217..0a59d2a8 100644 --- a/tests/_pure_prompt_k8s.test.fish +++ b/tests/_pure_prompt_k8s.test.fish @@ -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 diff --git a/tests/_pure_prompt_new_line.test.fish b/tests/_pure_prompt_new_line.test.fish index 397b044e..32f0e4f4 100644 --- a/tests/_pure_prompt_new_line.test.fish +++ b/tests/_pure_prompt_new_line.test.fish @@ -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 @@ -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 diff --git a/tests/_pure_prompt_symbol.test.fish b/tests/_pure_prompt_symbol.test.fish index 5bb11635..a98f57bc 100644 --- a/tests/_pure_prompt_symbol.test.fish +++ b/tests/_pure_prompt_symbol.test.fish @@ -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)) diff --git a/tests/_pure_user_at_host.test.fish b/tests/_pure_user_at_host.test.fish index 1cd55283..e31006f8 100644 --- a/tests/_pure_user_at_host.test.fish +++ b/tests/_pure_user_at_host.test.fish @@ -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)) diff --git a/tests/fixtures/constants.fish b/tests/fixtures/constants.fish index 1cfaeee8..64c1a210 100644 --- a/tests/fixtures/constants.fish +++ b/tests/fixtures/constants.fish @@ -1,4 +1,4 @@ -source (status dirname)/../mocks/mocks.fish +source (status dirname)/../mocks/spectra.fish set --global SUCCESS 0 set --global FAILURE 1 diff --git a/tests/mocks/mocks.fish b/tests/mocks/spectra.fish similarity index 86% rename from tests/mocks/mocks.fish rename to tests/mocks/spectra.fish index 54364d67..ce3c1185 100644 --- a/tests/mocks/mocks.fish +++ b/tests/mocks/spectra.fish @@ -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 @@ -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 @@ -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 \ @@ -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 \ @@ -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 @@ -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 @@ -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