Fork me on GitHub
Oliver George10: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.

Oliver George10: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))

Oliver George10:10:00

Am I doing something obviously wrong?


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?


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


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


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


i’ll give that a try


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?


Oh, and appears to be broken, I arrived there from the overall clojure api page

Alex Miller (Clojure team)16:10:06

This is a known issue in the doc build process


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...

Drew Verlee22: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?

Drew Verlee22: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?


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


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

Drew Verlee23:10:58

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