Extend stub_command to functions
Hi,
here is a little enhancement that provides a way to stub the shpec assert function. It is useful to check its behaviour when it is nested in a function body, like in a matcher for example.
Best regards
Eric
Perhaps this is more useful as added functionality to stub_command, in cases where the command in question is an existing function that would be lost if we stubbed it. They feel like very similar use cases, and I'd prefer a uniform interface if possible.
While it would still be possible to override shpec functions with this, I struggle to find a reason why you'd want to do so.
@rylnd, you're right and it's done.
Stubbing shpec assert is interesting when writing a complex matcher calling assert from within its body.
Then it's possible to check the arguments effectively passed to assert and compare the result to what is expected.
best regards
@rylnd, I've just noticed that the last build of this PR is marked as passed under travis while it should not be. I will investigate and hope to provide a patch soon.
Eric
@eviweb what is the status of this PR?
hi @rylnd, still at the same point, I'm sincerely sorry but I'm too busy for now. Eric
@rylnd,
I don't find any way to retrieve the function definition under Dash.
The type command does not provide the same information under Dash as it does under the other supported shells.
Do you have any idea on how to fix this ?
@rylnd,
in fact the title of this PR does no more represent really what it now tries to address.
I started to provide a way to stub the assert function, but I noticed that stubbed functions (not commands) are lost after having been unstubbed.
Putting aside the issue of the type command under Dash, I should be able to solve this problem under the other supported shells.
Maybe should it effectively be done as a plugin as suggested, instead of being part of the core for now.
What do you think about this?
In that case, do you want to integrate plugins in this repo?
Should plugins be considered as custom matchers or do you plan to provide a new entrypoint for plugins as you have done for custom matchers? Or is there another preferable way to go?
Best
Eric
@eviweb my mistake; I thought I had seen typeset work under dash, but I was mistaken.
@hlangeveld you had done some research for #89 into how to obtain a command's type with various POSIX(ish) builtins; are you aware of any way to obtain the function declaration in dash?
If not, then we either drop dash support or we move this work to a plugin. I will give #108 some thought; I would love to hear others' thoughts/ideas there as well.