MakeAWishFoundation/SwiftyMocky

Stubber with factory behavior

jaanus opened this issue · 0 comments

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.