Fork me on GitHub
#clojure-spec
<
2019-12-29
>
ho0man07:12:44

Hi, everyone is using spec/assert in production a good practice ? I want to produce detailed exceptions like spec/assert does for mismatches but do not want to allow some erroneous code to be able to disable the asserts by calling spec/check-asserts . Am I getting something wrong ? Thanks a alot

vlaaad08:12:59

I use spec/assert in dev and custom function which is a mostly a valid? + throw in production

ho0man11:12:33

Hi @vlaaad but this way I won't have descriptive exceptions like those thrown by spec/assert. Am I right ?

vlaaad11:12:11

@ho0man that's configurable by you. when I throw, I store spec/explain-data as error data and use spec/explain-str as error message — all the bits are there

ho0man11:12:54

Thanks a lot @vlaaad, I didn’t know about them Thanks

unbalanced14:12:42

Curious if there's a way in spec to do the following:

{:a (s/coll-of int?)
 :b (s/coll-of int? :count <3 times (count (:a this))>)}
or for that matter is it even possible to specify multiples instead of :count in coll-of?

unbalanced14:12:27

(need 3 coordinates per vertex ID, ideally, is what I'm going for)

codonnell15:12:10

@goomba Any predicate function is a spec, so you could use s/and to combine a spec like you typed above (but without the bit about counts) with a predicate function checking that the counts are valid. If you want generation to work, you'll likely want to provide a custom generator that does something like generate a map with the proper types and then truncate things to make the counts work out.

👍 2
unbalanced15:12:10

ahhh okay thank you! I'll look into this.