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

Stubber with factory behavior #341

Open
jaanus opened this issue Feb 23, 2023 · 0 comments
Open

Stubber with factory behavior #341

jaanus opened this issue Feb 23, 2023 · 0 comments

Comments

@jaanus
Copy link

jaanus commented Feb 23, 2023

I was expecting this to work:

someMock.given(.aFunction(willProduce: { stubber in
  stubber.return(resultFactory())
}))

It does work, but not as I expect. I was expecting the stubber block to be called every time the method on the mock is invoked, and return a fresh result from the factory.

What actually happens: stubber block is ran only once, correctly (once) runs the factory block, captures its result, and keeps wrapping over it and returning the same result to all method invocations.

I realize why working with static results is OK most of the time. I’m not proposing to change anything about current behavior, but rather, to add a capability to stubber where it would let me return fresh results from a factory. I suppose it would be a new stubbing policy in addition to wrap and drop.

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

No branches or pull requests

1 participant