{"repo":"jasonkarns/bats-mock","free":true,"listed":false,"github":"https://github.com/jasonkarns/bats-mock","clone":"git clone https://github.com/jasonkarns/bats-mock.git","description":"Mocking/stubbing library for BATS (Bash Automated Testing System)","language":"Shell","stars":98,"topics":["bash","bats","mock","shell","stub","testing"],"license":"MIT","category":"cli-tools","readme_excerpt":"bats-mock Mocking/stubbing library for [BATS (Bash Automated Testing System)][bats-core] Installation Git The recommended installation is with git-subtree. Assuming your project's bats tests are in test/ : then in test/test helper.bash : npm Also available as an npm module if you're into that sort of thing. then in test/test helper.bash : Usage After loading bats-mock/stub you have two new functions defined: - stub : for creating new stubs, along with a plan with expected args and the results to return when called. - unstub : for cleaning up, and also verifying that the plan was fullfilled. Stubbing The stub function takes a program name as its first argument; any remaining arguments go into the stub plan. Each plan line represents an expected invocation: a list of expected arguments followed by the command to execute, separated with a colon. The expected args (and the colon) is optional. So, in order to stub date , we could use something like this in a test case (where format date is the function under test, relying on data from the date command): This verifies that format date indeed called date using the args defined in ${ DATE ARGS} (which can not be declared in the test-case with local), and made proper use of the output of it. The plan is verified, one by one, as the calls come in. Finally, when the stub is removed with unstub , there is a final check to ensure there are no remaining un-met plans (which would indicated an expected invocation that did not occur). Unstubb","default_branch":null,"files":null,"tree":[],"storefront":"/r/jasonkarns","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/jasonkarns/bats-mock/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}