Closed kartik-prakash closed 1 year ago
I was going crazy trying to figure out why my test wasn't working but this drawback to the library made everything make sense. Hope this gets fixed soon as it is a pretty common practice for any mocking library 😄
This is not possible the way you are proposing, but the library already offers an API for what you are trying to achieve (documented here]:
val everyBar = every { foo.bar() }
everyBar returns true
val actual1 = foo.bar() // This will be true
everyBar returns false
val actual2 = foo.bar() // This will be false
The reason that this is not possible is that argument constraints are functional, therefore, there is no way to know if multiple mocking calls are the same. Furthermore, it would lead to very complicated cases where some redeclarations would mean override, and some would mean specialization.
It would be nice if the
every{}
call can be overridden via multiple consecutive calls? Not sure if it can be done straight out of the box though.For example:
Currently with latest version, actual2 will be equal to
true
, however it would be nice if the return value ofbar()
get's modified by the second call toevery {}
. This will help in setting up tests with basic return types in@Before()
hook and then modify things as needed in the test.