You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As far as I can tell, we have two ways of issuing return values to a generated fake struct in counterfeiter. The first is to simply record a value which it returns, and the second one is to enumerate on which nth call a certain value is returned.
A feature which I would find useful would be to have a "stack" approach as well, where you would be able to rather than enumerate the return values, just put them on a stack-like object.
My use-case for this is currently to have a fake http client, and I have separate functions which you'd I'd to push a certain return value on it.
func (s object) setupAuthenticate() {
s.httpClient.DoReturns("...")
}
func (s object) setupGetPost() {
s.httpClient.DoReturns("...")
}
func HelloWorldTest(t) {
setupAuthenticate()
setupGetPost()
// this function calls both an "authentication" and a "getPost" endpoint
call('/post/5')
}
I can of course enumerate the return calls inside the functions, but it'd lead to a lot higher coupling between the setup functions. I can also make a wrapper for this, but I think it's not an unreasonable thing to have inside the counterfeiter fake itself either!
The text was updated successfully, but these errors were encountered:
I know this issue is from almost two years ago, but I just wanted to let you know there is actually a third way of specifying return values. You can set the DoStub field to a function that will be called when the Do method is invoked. So you could just make a stack object yourself to keep track of things, and then have DoStub just pop off that stack.
Hi!
As far as I can tell, we have two ways of issuing return values to a generated fake struct in counterfeiter. The first is to simply record a value which it returns, and the second one is to enumerate on which nth call a certain value is returned.
A feature which I would find useful would be to have a "stack" approach as well, where you would be able to rather than enumerate the return values, just put them on a stack-like object.
That is, rather than:
You'd be able to simply:
My use-case for this is currently to have a fake http client, and I have separate functions which you'd I'd to push a certain return value on it.
I can of course enumerate the return calls inside the functions, but it'd lead to a lot higher coupling between the setup functions. I can also make a wrapper for this, but I think it's not an unreasonable thing to have inside the counterfeiter fake itself either!
The text was updated successfully, but these errors were encountered: