Quick and powerful fish shell mocks
fish-mock provides a quick and easy way to override the behavior of commands for use when testing. Mocking commands causes them to behave predictably, allowing you isolate and focus on the code being tested.
fisher add matchai/fish-mock
$ mock
Usage
$ mock <command> <argument> [exit code] [executed code]
$ unmock <command>
Arguments
command The command you would like to have mocked
argument The argument the mock should apply to ('*' defines a fallback for all arguments)
exit code The exit code returned when the command executes
executed code Code to be executed when the command is called with the given argument
Examples
$ mock git pull 0 "echo This command successfully echoes"
$ mock git push 1 "echo This command fails with status 1"
$ mock git \* 0 "echo This command acts as a fallback to all git commands"
$ unmock git # Original git functionality is now restored
Tips
To view this manual, use the mock command without providing arguments.
The array of arguments ($argv) is accessible within mocked functions as $args.
Many mocks can be applied to the same command at the same time with different arguments.
Be sure to escape the asterisk symbol when using it as a fallback (\*).
ISC Β© Matan Kushner