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

Generic stubs #15

Open
toote opened this issue Jul 1, 2023 · 2 comments
Open

Generic stubs #15

toote opened this issue Jul 1, 2023 · 2 comments

Comments

@toote
Copy link

toote commented Jul 1, 2023

It is quite common to have to stub commands only for them to be called multiple times with a set of arguments that are known or small.

I believe those scenarios may be better served by generic stubs. Instead of calls defining exact and sorted matches to compare against on calls, they just define a set of patterns to match against and their corresponding replacement commands. In my idea:

  • only if none of the patterns match would the stub call fail
  • unstubbing a generic stub would never fail
  • ideally, there would be a way to check how many times a generic stub was called (though this could be achieved through output checking or external accounting in the replacement command)
@adrianmace
Copy link

Any chance of this being added? I can't tell if it's a regression in bats-mock v4.

Here's a common use case to avoid having to actually sleep for 10 seconds each time:

stub sleep "10 : echo sleep for 10 seconds"

In our command under test, we're calling sleep 10 in a while loop to check the result of a command and break, until a max timeout of 900 seconds.

This actually worked fine in bats-mock v3, but in v4 I am required to set up 90 stub plans.

@toote
Copy link
Author

toote commented Jun 26, 2024

Any chance of this being added?

There is a definitive non-zero chance as long as this issue is still open. Unfortunately, I can't be any more specific that that 🤷

I can't tell if it's a regression in bats-mock v4.

I don't think it is a regression. Most likely it was unspecified behaviour that changed but would love to hear arguments either way

Here's a common use case to avoid having to actually sleep for 10 seconds each time:

stub sleep "10 : echo sleep for 10 seconds"

In our command under test, we're calling sleep 10 in a while loop to check the result of a command and break, until a max timeout of 900 seconds.

This actually worked fine in bats-mock v3, but in v4 I am required to set up 90 stub plans.

I am quite puzzled at your v3 vs v4 versioning, specially as this repository's latest release is v2.1.1

On the other hand, I do understand the annoyance of setting up 90 stub plans. Luckily, since #11 - thanks to @flamefire's efforts (see #7) - you can use incremental stub plans to setup 90 stub plans in a loop:

for ITER in seq 90; do
  stub sleep "10: echo sleep for 10 seconds #${ITER}"
done

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

No branches or pull requests

2 participants