This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-24
Channels
- # arachne (3)
- # beginners (39)
- # boot (3)
- # cider (91)
- # cljs-dev (56)
- # cljsrn (4)
- # clojure (267)
- # clojure-dusseldorf (1)
- # clojure-estonia (1)
- # clojure-greece (2)
- # clojure-italy (6)
- # clojure-nl (2)
- # clojure-russia (18)
- # clojure-spec (27)
- # clojure-uk (136)
- # clojurescript (19)
- # core-async (2)
- # cursive (6)
- # datomic (17)
- # emacs (2)
- # fulcro (86)
- # graphql (4)
- # hoplon (13)
- # jobs-discuss (7)
- # jobs-rus (1)
- # keechma (34)
- # keyboards (7)
- # leiningen (5)
- # luminus (4)
- # lumo (8)
- # off-topic (13)
- # om (6)
- # onyx (26)
- # re-frame (22)
- # reagent (1)
- # reitit (2)
- # remote-jobs (8)
- # ring (3)
- # ring-swagger (5)
- # rum (8)
- # shadow-cljs (45)
- # specter (6)
- # unrepl (16)
- # yada (15)
@stathissideris I don’t have to define them twice, but I want to avoid it happening
then you'll get en exception on the next ns reload in repl, would not want that, would you? )
otherwise, write a macro, which throws/warns if spec you are trying to define is already defined in specs registry
defmacro sdefonce [sym form]
`(if (contains? (s/registry) ~sym)
(throw (ex-info "NO!" {:sym ~sym :existing (s/form (get (s/registry) ~sym))}))
(s/def ~sym ~form)))
(sdefonce ::foo string?)
=> :user.specs/foo
(sdefonce ::foo string?)
clojure.lang.ExceptionInfo: NO!
data: {:existing clojure.core/string?, :sym :user.specs/foo}
you might check if form is the same as in registry, and it will not blow up on ns reload for unchanged specs, but still will on the ones you are iterating over (developing)
@misha I only want to deny overrides when I run the tests to make sure I haven’t duplicated it in the code. (Loading some specs from an external lib). Yeah I was considering writing my own macro but then I’d like to override the macro so that normally it uses the normal s/def but when I run my tests it throws the error. I’ll probably go with my own macro actually.
here’s a thing I’ve found useful many times:
(defn validate [spec thing]
(if (s/valid? spec thing)
thing
(throw (ex-info (s/explain-str spec thing)
(s/explain-data spec thing)))))
https://github.com/Datomic/mbrainz-importer/blob/master/src/cognitect/xform/spec.clj#L13-L23
Hi, I want to generate test data based on a swagger spec, but subject to some constraints. Do you think spec is a good tool for that? If yes, how would one best go about that? If not, what would be a better way to do it?
Quick sanity check: in Clojurescript, is cljs.spec.test.alpha working for anyone else? I keep getting compilation errors about clojure.test.check.
(Since it’s still alpha, I wasn’t sure)
In some cases you need to explicitly import [org.clojure/test.check <ver>]
, at least on the clj side
@dadair Thx. Is that based on https://dev.clojure.org/jira/browse/CLJS-1792
I’ll try adding it
@dadair That did it! Thanks