{"_id":"bats-mock","_rev":"9-731c6c2376700ecd6e5788201aeefa4e","name":"bats-mock","description":"Mocking/stubbing library for BATS (Bash Automated Testing System)","dist-tags":{"latest":"1.2.5"},"versions":{"1.0.1":{"name":"bats-mock","version":"1.0.1","description":"Mocking/stubbing library for BATS (Bash Automated Testing System)","author":{"name":"Sam Stephenson","email":"sstephenson@gmail.com","url":"http://sstephenson.us/"},"contributors":[{"name":"Mislav Marohnić","email":"mislav.marohnic@gmail.com","url":"http://mislav.net"},{"name":"Jason Karns","email":"jason@karns.name","url":"http://jason.karns.name/"}],"homepage":"https://github.com/jasonkarns/bats-mock#readme","repository":{"type":"git","url":"git+https://github.com/jasonkarns/bats-mock.git"},"bugs":{"url":"https://github.com/jasonkarns/bats-mock/issues"},"main":"stub.bash","files":["binstub","stub.bash"],"peerDependencies":{"bats":"^0.4.2"},"license":"MIT","keywords":["bash","bats","mock","stub","shell","test","unit"],"gitHead":"d10a54ced6667d900d126b75eb641830a1c9cab2","_id":"bats-mock@1.0.1","scripts":{},"_shasum":"f86d7d1fce3e4615382f63de9af5ffdfe74df5d5","_from":".","_npmVersion":"3.3.9","_nodeVersion":"5.0.0","_npmUser":{"name":"jasonkarns","email":"jason@karns.name"},"maintainers":[{"name":"jasonkarns","email":"jason@karns.name"}],"dist":{"shasum":"f86d7d1fce3e4615382f63de9af5ffdfe74df5d5","tarball":"https://registry.npmjs.org/bats-mock/-/bats-mock-1.0.1.tgz","integrity":"sha512-/OOoA9qVw6XlDqTJzHCfYVmE/dMqRUE5Pysps8459Gu4NcNCco/FbjY+FUpqJYVqFRJQx6LBDvMhFKenMa7WBA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCNqTMgYKg2Ri0hd2IcmsaDTGGF/f4uOhLL/YIIbIImbQIgTwMsUo/cN16bG2U7kBd0y++m7cGoiQTsrW0XZ+uCm60="}]},"directories":{}},"1.1.0":{"name":"bats-mock","version":"1.1.0","description":"Mocking/stubbing library for BATS (Bash Automated Testing System)","author":{"name":"Sam Stephenson","email":"sstephenson@gmail.com","url":"http://sstephenson.us/"},"contributors":[{"name":"Mislav Marohnić","email":"mislav.marohnic@gmail.com","url":"http://mislav.net"},{"name":"Jason Karns","email":"jason@karns.name","url":"http://jason.karns.name/"}],"homepage":"https://github.com/jasonkarns/bats-mock#readme","repository":{"type":"git","url":"git+https://github.com/jasonkarns/bats-mock.git"},"bugs":{"url":"https://github.com/jasonkarns/bats-mock/issues"},"main":"stub.bash","peerDependencies":{"bats":"^0.4.2 || ^1"},"license":"MIT","keywords":["bash","bats","mock","stub","shell","test","unit"],"_id":"bats-mock@1.1.0","gitHead":"94549f444bdd18e5fadbb8784ebb7144cbfe6353","_nodeVersion":"22.1.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-FFkHRh3umeuAAh/xUl6UjUFCQamFYiSEUrT8yyKPfrHdtpxNhISYtVaEa4u4OVcyP6PxcNUTzwD8q+EYjG/Q6Q==","shasum":"02d2d998a41cf71027b131369fa78d212abe7275","tarball":"https://registry.npmjs.org/bats-mock/-/bats-mock-1.1.0.tgz","fileCount":5,"unpackedSize":9607,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD+55hLQZUpjPFa9YLP9w56lA4Lsk4U34idXrZgCfnPfAIhAJPlR05Ira66ax7bhWu8g49Yk76S2qshqt6Qg0eu6wM7"}]},"_npmUser":{"name":"jasonkarns","email":"jason.karns@gmail.com"},"directories":{},"maintainers":[{"name":"jasonkarns","email":"jason.karns@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bats-mock_1.1.0_1715615388658_0.7487704364109795"},"_hasShrinkwrap":false},"1.1.2-2":{"name":"bats-mock","description":"Mocking/stubbing library for BATS (Bash Automated Testing System)","version":"1.1.2-2","author":{"name":"Sam Stephenson","email":"sstephenson@gmail.com","url":"http://sstephenson.us/"},"bugs":{"url":"https://github.com/jasonkarns/bats-mock/issues"},"contributors":[{"name":"Mislav Marohnić","email":"mislav.marohnic@gmail.com","url":"http://mislav.net"},{"name":"Jason Karns","email":"jason@karns.name","url":"http://jason.karns.name/"}],"devDependencies":{"fixpack":"^4.0.0"},"homepage":"https://github.com/jasonkarns/bats-mock#readme","keywords":["bash","bats","mock","shell","stub","test","unit"],"license":"MIT","main":"stub.bash","peerDependencies":{"bats":"^0.4.2 || ^1"},"repository":{"type":"git","url":"git+https://github.com/jasonkarns/bats-mock.git"},"scripts":{"lint":"fixpack","posttest":"npm run lint","test":"echo todo"},"_id":"bats-mock@1.1.2-2","gitHead":"6de48546d7d84789dcc2c00557fba656131a6ac3","_nodeVersion":"18.20.2","_npmVersion":"10.5.0","dist":{"integrity":"sha512-FsVpKaUILymUFpDNK7NiPHSVfZSFxL7ldk0TCbSyf04UTR0JsdDlIlnlw9svq0E3zakg/3W2zkb7bzQ18tsovA==","shasum":"fec5313c9a67db8bd7df65ab273bfa106a93a5cf","tarball":"https://registry.npmjs.org/bats-mock/-/bats-mock-1.1.2-2.tgz","fileCount":5,"unpackedSize":9760,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFNx6jpf2RI8z/vFModaJC6Jer4AYqp4b7E70uLm2DwoAiArC2WJQO6mtlPAsDEu6hxRh5YvhVagOBDpWApIVOxm6g=="}]},"_npmUser":{"name":"jasonkarns","email":"jason.karns@gmail.com"},"directories":{},"maintainers":[{"name":"jasonkarns","email":"jason.karns@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bats-mock_1.1.2-2_1715637663296_0.5920975213196238"},"_hasShrinkwrap":false},"1.1.3-0":{"name":"bats-mock","description":"Mocking/stubbing library for BATS (Bash Automated Testing System)","version":"1.1.3-0","author":{"name":"Sam Stephenson","email":"sstephenson@gmail.com","url":"http://sstephenson.us/"},"bugs":{"url":"https://github.com/jasonkarns/bats-mock/issues"},"contributors":[{"name":"Mislav Marohnić","email":"mislav.marohnic@gmail.com","url":"http://mislav.net"},{"name":"Jason Karns","email":"jason@karns.name","url":"http://jason.karns.name/"}],"devDependencies":{"fixpack":"^4.0.0"},"homepage":"https://github.com/jasonkarns/bats-mock#readme","keywords":["bash","bats","mock","shell","stub","test","unit"],"license":"MIT","main":"stub.bash","peerDependencies":{"bats":"^0.4.2 || ^1"},"repository":{"type":"git","url":"git+https://github.com/jasonkarns/bats-mock.git"},"scripts":{"lint":"fixpack","posttest":"npm run lint","test":"echo todo"},"_id":"bats-mock@1.1.3-0","gitHead":"71adf67ceb3b4be1bb53cb3e57f4d2b377a72b0b","_nodeVersion":"18.20.2","_npmVersion":"10.5.0","dist":{"integrity":"sha512-2dIefcVYidz/NNP4F24N728w81oQ3y4/u02Qdf2PfhQtohfMAJCZ80QfgshY5rS70W+7kp6ZRPdyu2nnX9p3Yw==","shasum":"9baf626ab42b0df49bb8f42c3b86c4455fbf6bf0","tarball":"https://registry.npmjs.org/bats-mock/-/bats-mock-1.1.3-0.tgz","fileCount":5,"unpackedSize":9665,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/bats-mock@1.1.3-0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIG0sGk56DAB9MStp6WvacA4lVDEXa3cHoxGnKiSxIbL5AiBIPBpgRfOoWi6oksYatt5UPI2BxWQqE08BnO7ofG5WhA=="}]},"_npmUser":{"name":"jasonkarns","email":"jason.karns@gmail.com"},"directories":{},"maintainers":[{"name":"jasonkarns","email":"jason.karns@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bats-mock_1.1.3-0_1715651187491_0.7115548926695054"},"_hasShrinkwrap":false},"1.2.0":{"name":"bats-mock","description":"Mocking/stubbing library for BATS (Bash Automated Testing System)","version":"1.2.0","author":{"name":"Sam Stephenson","email":"sstephenson@gmail.com","url":"http://sstephenson.us/"},"bugs":{"url":"https://github.com/jasonkarns/bats-mock/issues"},"contributors":[{"name":"Mislav Marohnić","email":"mislav.marohnic@gmail.com","url":"http://mislav.net"},{"name":"Jason Karns","email":"jason@karns.name","url":"http://jason.karns.name/"}],"devDependencies":{"fixpack":"^4.0.0"},"homepage":"https://github.com/jasonkarns/bats-mock#readme","keywords":["bash","bats","mock","shell","stub","test","unit"],"license":"MIT","main":"stub.bash","peerDependencies":{"bats":"^0.4.2 || ^1"},"repository":{"type":"git","url":"git+https://github.com/jasonkarns/bats-mock.git"},"scripts":{"lint":"fixpack","posttest":"npm run lint","test":"echo todo"},"_id":"bats-mock@1.2.0","gitHead":"64498ea03782d7db6d73199dd46e23a69c14720a","_nodeVersion":"22.1.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-ROx+LuFaxSokojIn32jRjqzKYo4jgqwJFPv3EUQart2cdCXqwnHDH5DvBsXQRKYUlyIf/V1TnIw0jCJXVuCD7A==","shasum":"eb214933d73309251496698d7b81af7d047733da","tarball":"https://registry.npmjs.org/bats-mock/-/bats-mock-1.2.0.tgz","fileCount":5,"unpackedSize":10477,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBy/3ZUwqaGTfzFvyAURjQ4C4ZNktRGthC/zKE11iPg/AiEAr2qsXmC+/gZFAqkXAUGk2LOzFwIY1Up8mjX8p840fLc="}]},"_npmUser":{"name":"jasonkarns","email":"jason.karns@gmail.com"},"directories":{},"maintainers":[{"name":"jasonkarns","email":"jason.karns@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bats-mock_1.2.0_1717598338457_0.2533611699283942"},"_hasShrinkwrap":false},"1.2.1":{"name":"bats-mock","description":"Mocking/stubbing library for BATS (Bash Automated Testing System)","version":"1.2.1","author":{"name":"Sam Stephenson","email":"sstephenson@gmail.com","url":"http://sstephenson.us/"},"bugs":{"url":"https://github.com/jasonkarns/bats-mock/issues"},"contributors":[{"name":"Mislav Marohnić","email":"mislav.marohnic@gmail.com","url":"http://mislav.net"},{"name":"Jason Karns","email":"jason@karns.name","url":"http://jason.karns.name/"}],"devDependencies":{"fixpack":"^4.0.0"},"homepage":"https://github.com/jasonkarns/bats-mock#readme","keywords":["bash","bats","mock","shell","stub","test","unit"],"license":"MIT","main":"stub.bash","peerDependencies":{"bats":"^0.4.2 || ^1"},"repository":{"type":"git","url":"git+https://github.com/jasonkarns/bats-mock.git"},"scripts":{"lint":"fixpack","posttest":"npm run lint","postversion":"git push --follow-tags","test":"echo todo"},"_id":"bats-mock@1.2.1","gitHead":"d5835bf78ea5a5ce0980cce2eee0970a4c2bf4ad","_nodeVersion":"22.1.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-N3ed+Ancw74KK6QZFFAjuAKR6VtYum9kYM+tS2Og+A3Zzz6Zc9ENJsMWKuR103+GTejBkPtfkTHwZYUMczidoA==","shasum":"f5f0ea1515555135eb4d258d6ac847cd9afdac61","tarball":"https://registry.npmjs.org/bats-mock/-/bats-mock-1.2.1.tgz","fileCount":5,"unpackedSize":10522,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCaAcYnTyR3sY0dvm3avM+BqDYRBpvaZBZiKsbpU+ZHhwIgZfzmyUWgIvsizOOn/evHHEi0TnmShmrGqORWSJKo1SY="}]},"_npmUser":{"name":"jasonkarns","email":"jason.karns@gmail.com"},"directories":{},"maintainers":[{"name":"jasonkarns","email":"jason.karns@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bats-mock_1.2.1_1717598368246_0.2688802023332879"},"_hasShrinkwrap":false},"1.2.5":{"name":"bats-mock","description":"Mocking/stubbing library for BATS (Bash Automated Testing System)","version":"1.2.5","author":{"name":"Sam Stephenson","email":"sstephenson@gmail.com","url":"http://sstephenson.us/"},"bugs":{"url":"https://github.com/jasonkarns/bats-mock/issues"},"contributors":[{"name":"Mislav Marohnić","email":"mislav.marohnic@gmail.com","url":"http://mislav.net"},{"name":"Jason Karns","email":"jason@karns.name","url":"http://jason.karns.name/"}],"devDependencies":{"fixpack":"^4.0.0"},"homepage":"https://github.com/jasonkarns/bats-mock#readme","keywords":["bash","bats","mock","shell","stub","test","unit"],"license":"MIT","main":"stub.bash","peerDependencies":{"bats":"^0.4.2 || ^1"},"repository":{"type":"git","url":"git+https://github.com/jasonkarns/bats-mock.git"},"scripts":{"lint":"fixpack","posttest":"npm run lint","postversion":"git push --follow-tags","test":"echo todo"},"_id":"bats-mock@1.2.5","gitHead":"24f995f9618b493d0a2db148bea272b3c9133826","_nodeVersion":"18.20.3","_npmVersion":"10.7.0","dist":{"integrity":"sha512-gS6r3XwQnqoDUFQtzSW8rdsD62uHSFRjH1x7g9Q5RnQLnftM3UogfVIboGwvqLk+k0glY5u/qqO/nI4GGU2ZYQ==","shasum":"1990c2cefe67827c56525f6cf46e9ea0dc846987","tarball":"https://registry.npmjs.org/bats-mock/-/bats-mock-1.2.5.tgz","fileCount":5,"unpackedSize":10522,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/bats-mock@1.2.5","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHaWk9s6iEldhUJhPPqptBwJTl0Xjaw2t16eegV28j/XAiEAvgj0mpMH02GeIpWg7ccQxPN6A6M8ZLH/BciRv1ZzNyM="}]},"_npmUser":{"name":"jasonkarns","email":"jason.karns@gmail.com"},"directories":{},"maintainers":[{"name":"jasonkarns","email":"jason.karns@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bats-mock_1.2.5_1717601035333_0.4650735599485265"},"_hasShrinkwrap":false}},"readme":"# bats-mock\n\nMocking/stubbing library for [BATS (Bash Automated Testing System)][bats-core]\n\n## Installation\n\n### git\n\nThe recommended installation is with git-subtree.\nAssuming your project's bats tests are in `test/`:\n\n```console\n# v1 can be any valid ref (tag, branch, commit) of the bats-mock repo\ngit subtree add --prefix test/helpers/bats-mock https://github.com/jasonkarns/bats-mock v1 --squash\n\n# pull a future bats-mock release (say, v2) with:\n# git subtree pull --prefix test/helpers/bats-mock https://github.com/jasonkarns/bats-mock v2 --squash\n\n# bats-mock keeps a \"major version\" tag pinned to the highest corresponding tag\n```\n\nthen in `test/test_helper.bash`:\n\n```bats\nload helpers/bats-mock/stub\n```\n\n### npm\n\nAlso available as an [npm module](https://www.npmjs.com/package/bats-mock)\nif you're into that sort of thing.\n\n```console\nnpm install --save-dev bats-mock\n```\n\nthen in `test/test_helper.bash`:\n\n```bats\nload ../node_modules/bats-mock/stub\n```\n\n## Usage\n\nAfter loading `bats-mock/stub` you have two new functions defined:\n\n- `stub`: for creating new stubs,\n  along with a plan with expected args and the results to return when called.\n- `unstub`: for cleaning up, and also verifying that the plan was fullfilled.\n\n### Stubbing\n\nThe `stub` function takes a program name as its first argument;\nany remaining arguments go into the stub plan.\n\nEach plan line represents an expected invocation:\na list of expected arguments followed by the command to execute,\nseparated with a colon.\n\n```text\narg1 arg2 ... : only_run if args matched\n```\n\nThe expected args (and the colon) is optional.\n\nSo, in order to stub `date`,\nwe could use something like this in a test case\n(where `format_date` is the function under test,\nrelying on data from the `date` command):\n\n```bats\nload helper\n\n# this is the \"code under test\"\n# it would normally be in another file\nformat_date() {\n  date -r 222\n}\n\nsetup() {\n  _DATE_ARGS='-r 222'\n  stub date \\\n      \"${_DATE_ARGS} : echo 'I am stubbed!'\" \\\n      \"${_DATE_ARGS} : echo 'Wed Dec 31 18:03:42 CST 1969'\"\n}\n\nteardown() {\n  unstub date\n}\n\n@test \"date format util formats date with expected arguments\" {\n  result=\"$(format_date)\"\n  [ \"$result\" == 'I am stubbed!' ]\n\n  result=\"$(format_date)\"\n  [ \"$result\" == 'Wed Dec 31 18:03:42 CST 1969' ]\n}\n```\n\nThis verifies that `format_date` indeed called `date`\nusing the args defined in `${_DATE_ARGS}`\n(which can not be declared in the test-case with local),\nand made proper use of the output of it.\n\nThe plan is verified, one by one, as the calls come in.\nFinally, when the stub is removed with `unstub`,\nthere is a final check to ensure there are no remaining un-met plans\n(which would indicated an expected invocation that did not occur).\n\n### Unstubbing\n\nOnce the test case is done,\nyou should call `unstub <program>` in order to clean up the temporary files,\nand make a final check that all the plans have been met for the stub.\n\n## How it works\n\nUnder the covers, `bats-mock` uses three scripts to manage the stubbed programs/functions.\n\nFirst, it is the command (or program) itself,\nwhich when the stub is created is placed in\n(or rather, the `binstub` script is sym-linked to)\n`${BATS_MOCK_BINDIR}/${program}`\n(which is added to your `PATH` when loading the stub library).\nSecondly, it creates a stub plan,\nbased on the arguments passed when creating the stub.\nAnd finally, during execution, the command invocations are\ntracked in a stub run file which is checked once the command is `unstub`'ed.\nThe `${program}-stub-[plan|run]` files are both in `${BATS_MOCK_TMPDIR}`.\n\n### Caveat\n\nIf you stub functions, make sure to unset them,\nor the stub script wan't be called,\nas the function will shadow the binstub script on the `PATH`.\n\n## Credits\n\nExtracted from the [ruby-build][] test suite.\nMany thanks to its author and contributors:\n[Sam Stephenson][sstephenson] and [Mislav Marohnić][mislav].\n\n[ruby-build]: https://github.com/sstephenson/ruby-build\n[sstephenson]: https://github.com/sstephenson\n[mislav]: https://github.com/mislav\n[bats-core]: https://github.com/bats-core\n","maintainers":[{"name":"jasonkarns","email":"jason.karns@gmail.com"}],"time":{"modified":"2024-06-05T15:23:55.989Z","created":"2015-11-03T01:10:27.560Z","1.0.1":"2015-11-03T01:10:27.560Z","1.1.0":"2024-05-13T15:49:48.815Z","1.1.2-2":"2024-05-13T22:01:03.451Z","1.1.3-0":"2024-05-14T01:46:27.641Z","1.2.0":"2024-06-05T14:38:58.660Z","1.2.1":"2024-06-05T14:39:28.384Z","1.2.5":"2024-06-05T15:23:55.496Z"},"homepage":"https://github.com/jasonkarns/bats-mock#readme","keywords":["bash","bats","mock","shell","stub","test","unit"],"repository":{"type":"git","url":"git+https://github.com/jasonkarns/bats-mock.git"},"contributors":[{"name":"Mislav Marohnić","email":"mislav.marohnic@gmail.com","url":"http://mislav.net"},{"name":"Jason Karns","email":"jason@karns.name","url":"http://jason.karns.name/"}],"author":{"name":"Sam Stephenson","email":"sstephenson@gmail.com","url":"http://sstephenson.us/"},"bugs":{"url":"https://github.com/jasonkarns/bats-mock/issues"},"license":"MIT","readmeFilename":"README.md"}