Fork me on GitHub
#clojure-spec
<
2017-10-29
>
olivergeorge10:10:22

Quick sanity check. I think this code should stub a function (in second case). It does on CLJ but doesn't on CLJS.

olivergeorge10:10:32

(defn add2 [a b] 1.1)
(s/fdef add2 :args (s/cat :a int? :b int?) :ret int?)
(println ::a (add2 1 2))
(stest/instrument `add2 {:stub #{`add2}})
(println ::b (add2 1 2))
(stest/unstrument `add2)
(println ::c (add2 1 2))

olivergeorge10:10:00

Am I doing something obviously wrong?

eoliphant15:10:29

Is it possible to do ‘cross’ specification/validation with spec? If I have a map

{:a "even"
:b 2}
Where say :b should be odd? if :a is "odd" and vice versa?

mingp15:10:54

@eoliphant Perhaps treat them as separate cases and combine with spec/or.

mingp15:10:40

It would depend more on what the more immediate problem you're trying to solve is.

eoliphant15:10:51

hmm ah I see, when you’re doing the ‘map’ spec cover both cases with the or

eoliphant15:10:58

i’ll give that a try

mrchance16:10:03

Hi, is there a way to generate self contained specs? I want to turn a swagger.json into a spec and run it on some data at runtime, and it looks like that requires eval with the way the spec registry currently works?

mrchance16:10:52

Oh, and https://clojure.github.io/core.specs.alpha/ appears to be broken, I arrived there from the overall clojure api page https://clojure.org/api/api

alexmiller16:10:06

This is a known issue in the doc build process

mrchance16:10:36

Ok, just wanted to let you know. Any insights into the other problem? I feel pretty dirty if I have to fiddle with global mutable state just to get some spec validation working...

drewverlee22:10:17

If i want to use spec in order to pass the user of my application a error msg how would i do that? Is there a place to override the error msg with a custom one?

drewverlee22:10:13

Does that even fit with the rational? Like if i have a command line app and i want to validate the input and send back an error msg, would spec fit into?

seancorfield23:10:25

The idea is to use the explain-data result and map it to whatever error messages you want in your app @drewverlee

bbrinck23:10:26

@drewverlee Perhaps https://github.com/alexanderkiel/phrase would be a good fit?

bbrinck23:10:39

But yes, if your specs are fairly simple, it might be easies to just map explain-data to error messages. It gets a little trickier if your specs are more deeply nested

drewverlee23:10:58

@bbrinck phrase is in the spirit of what i want. Its odd i couldn't search it down.