Fork me on GitHub
#clojure-spec
<
2020-08-09
>
johanatan22:08:18

hi, i have a spec'd function that is taking as input a collection of data where the individual elements have attached metadata via a with-gen for their spec. however, because stest/check conforms these inputs to their constituent components (specified via s/cat) the metadata which was attached to the outer element is lost. what is the recommended way around this? perhaps a way to override "conform" or otherwise propagate the metadata? something else?

johanatan22:08:05

i could manually attach the metadata rather than to the outer value to one of its constituents but this doesn't feel like the proper data modeling for the actual situation. i could also add an extra component to the s/alt but that isn't desirable as it would expose "test-only" data to the code under test (and also generally violate one's tastes with respect to the actual modeling).

seancorfield22:08:09

@johanatan Are you saying that stest/check is passing conformed data into the function under test? That doesn't seem right since the conformed shape won't necessarily match the input shape...

johanatan22:08:47

no, it's passing it into the :fn verifier

johanatan22:08:06

sorry wasn't clear. stest/check is passing the generated data to the actual function

johanatan22:08:22

but that data is slightly deformed via conform to the actual :fn checker

seancorfield22:08:29

Oh, right. So you're trying to rely on input metadata in the :fn verifier?

johanatan22:08:30

(per the labeling)

seancorfield22:08:13

I wouldn't expect metadata to be preserved through that. It doesn't seem like something you should be relying on in :fn.

johanatan22:08:27

it would be very useful for testing purposes

johanatan22:08:44

the generators can then inform the tests what the expected behavior should be

johanatan22:08:51

I can't imagine any better way to accomplish that in fact

johanatan22:08:20

and as long as the generators don't use s/alt s/cat and the like, this is entirely possible

johanatan22:08:28

(i've done it previously)

johanatan22:08:01

i have to step out now so will respond back later this evening. thx

seancorfield22:08:59

Could you use s/conformer in the spec to thread the metadata into the conformed result I wonder?