[LRUG] Joined-up unit tests
Frederick Cheung
frederick.cheung at gmail.com
Thu Jun 6 05:15:08 PDT 2024
On Thu, Jun 6, 2024 at 12:01 PM Patrick Gleeson <patrick.c.gleeson at gmail.com>
wrote:
>
> Are there any good patterns for constraining the arguments and return
> values stated in mocks somehow? I'd love it if something would check that
> the inputs and outputs I specify when mocking service B have been "proven"
> to be accurate in my unit tests for B. That way my unit tests could give me
> some of the benefits of (slower, unwieldier) integration tests "for free".
> Or am I being hopelessly naive and misguided here?
>
>
Semi non answer (in that it doesn't help with mocks that don't behave the
same as their thing[1]) but i find that a type system is helpful here -
ensuring that foo is only passed an instance of X and that it always
returns a Y (& not nil in some case). I use sorbet i some apps and i don't
always love it, but it has its moments
Fred
[1] although one could imagine a `sorbet_double(Foo)` class that when you
do `receive(:bar).with(baz).and_return(z)` checks whether those are valid
arguments / return tipes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20240606/cd8a1ffb/attachment.htm>
More information about the Chat
mailing list