I’m wondering if it’s possible to generate values of a stubbed fdef such that they are a function of its arguments.
Concrete example: In this gist, an outer function calls an inner function twice with the same value ( i). I want to write an fdef for the outer function, using a :fn predicate to assert that the return from the two calls to the inner fn are identical. However, when I try to stub the call to inner with instrumentation, the generated values returned by inner ’s stub are (sensibly) different. Is there any way to express on the fdef of inner that the generated values should be some known function of the input?
Is there any way to express on the fdef of inner that the generated values should be some known function of the input
It could be, but in this case the original unstubbed function is a database call. (We fspec our database functions and other effectful things, exercise them, and then stub them out elsewhere.)
But to answer your question, yes you can. You can either pass an override generator using :gen on instrument, or use :replace