Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pattern matching when arguments contain '*' #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tommarshall
Copy link

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 $pattern in the arguments case comparison as this appears
    to resolve the issue.

Fixes #7

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 `$pattern` in the arguments case comparison as this appears
  to resolve the issue.
@tommarshall
Copy link
Author

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.

@lox
Copy link

lox commented Apr 25, 2017

@jasonkarns Any chance of getting this merged in?

@jasonkarns
Copy link
Owner

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.

@lox
Copy link

lox commented Apr 27, 2017

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!

@tommarshall
Copy link
Author

Thanks for the update @jasonkarns. Understood. Unfortunately there's isn't anything telling in the rbenv/ruby-build history either.

@Flamefire
Copy link

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'"

@Flamefire
Copy link

Another method to fix this: Match both quoted and unquoted:

  case "$argument" in
    $pattern ) ;;
    "$pattern" ) ;;
    * ) match_found=0 ;;
  esac

@warmfire540
Copy link

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 >

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stub fails to recognise call when arguments contain an asterisk character
5 participants