bats-mock
bats-mock copied to clipboard
Fix pattern matching when arguments contain '*'
Because:
- If the arguments string includes an '*' (asterisk) character then the bats-mock stub appears to fail to recognise the call.
This change:
- Quotes the
$patternin the arguments case comparison as this appears to resolve the issue.
Fixes #7
I'm not sure whether $pattern was left unquoted intentionally, or was an oversight. Unfortunately there's nothing in the history to shed any light on this.
This change appears to resolve the issue in question without causing any problems in my tests, but difficult to be sure of that in all cases without tests for the bats-mock project itself.
@jasonkarns Any chance of getting this merged in?
I'm really hesitant. This repo was created by taking the existing bats-mock "feature" out of the test suite from rbenv/ruby-build. It was extracted so that it could be pulled in as a dev dependency for nodenv/node-build (and other nodenv-* repos).
This is why there isn't any real history. And also why there hasn't been meaningful work in this repo. It's mainly a snapshot in time of an embedded test utility.
Ideally, the future of this module would be as a project that works in hand with https://github.com/ztombol/bats-support (and the other bats-* test libs). However, there hasn't been much thought to how that would occur, nor what bats-mock should actually look like.
I'll try to experiment with this fix as applied to the test suites I know that leverage bats-mock. If it works without issue, I'll consider merging this. And I'll try to add a CONTRIBUTING.md doc outlining what I've said above about project history and future.
Understood @jasonkarns. In the meantime, I'll fork and fix some bugs and tackle some features. If you decide to accept changes, let us know!
Thanks for the update @jasonkarns. Understood. Unfortunately there's isn't anything telling in the rbenv/ruby-build history either.
Found a reason NOT to merge this: It disallows fuzzy matching of inputs. E.g. stub copy "*/foo */bar :"
How about adding a parameter to stub in the sense like https://github.com/capitalone/bash_shell_mock: stub --exact aws \ "ec2 describe-snapshots --query Snapshots[*].{Time:StartTime} : echo 'foo'"
Another method to fix this: Match both quoted and unquoted:
case "$argument" in
$pattern ) ;;
"$pattern" ) ;;
* ) match_found=0 ;;
esac
dang this is my exact issue. @Flamefire's change fixes my issue. I'm running the following arguments to git - describe --tags --abbrev=0 --exclude latest 2>/dev/null and it blows up w/ the >