I have a program that will be running several system commands. The simplest way I know how to do this is with the ` ` notation. I’d like to build tests for these tools without it actually having to run those system commands on the system.
Is there a way I can mock the response from the system?
If your code runs a lot of external commands you should create a simple wrapper and mock that:
and test it like this:
If you want to be neater you initialize your object with the command runner instance so you don’t have to pass it to the method, of course.