-
Notifications
You must be signed in to change notification settings - Fork 100
Description
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:
fake.functionReturnsOnCall(0, 5)
fake.functionReturnsOnCall(1, 6)
You'd be able to simply:
fake.functionReturns(5)
fake.functionReturns(6)
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!