Fork me on GitHub
#clojure-spec
<
2017-04-01
>
lmergen08:04:42

does anyone know whether there’s some “clojure.spec cookbook” ?

lmergen08:04:35

(i.e. a collection of spec examples / community reviewed)

Geoffrey Gaillard11:04:49

Hello ! I have a set of keywords like (def ks #{::email ::password}) and I would like to build a spec from it, like

(s/def ::cred 
  (s/keys :req-un (into [] ks)))
But s/keys and s/def are macros so (into [] ks) is not evaluated… So I tried
(s/def ::cred 
  `(s/keys :req-un [~@ks]))
But the inner part seems to not be expanded and passed "as is" to s/def. I have a feeling telling me that I'm doing something wrong here. Is it sane ? Is there a way to expand the body before s/def is called ?

gfredericks11:04:05

You have to write your own macro

Geoffrey Gaillard11:04:49

A one that wrap s/def and s/keys ?

Geoffrey Gaillard11:04:26

Ah ! I get it ! Sorry for that 😕 Thank you !

mike_ananev12:04:46

Hi! Sorry for dumb question, but how i can run my spec tests as unit tests using clojure.test? My goal is to run tests in some CI tool using lein test.

gfredericks17:04:34

@mike1452 write a regular test that calls spec and asserts about the response

gfredericks18:04:55

Looks plausible

dviramontes21:04:58

hello all, having a little trouble getting up and running with clojure.spec in clojurescript have these dependencies in my project.clj

[  [org.clojure/clojure "1.8.0"]
                 [org.clojure/clojurescript "1.9.494"]
                 [org.clojure/core.async "0.2.391"]
                 ...
                 [org.clojure/test.check “0.9.0”] ]
and my namespace looks like
(ns foo.core
  (:require [cljs.spec :as s]
              [clojure.test.check :as tc]
              [clojure.test.check.generators :as gen]
              [clojure.test.check.properties :as prop :include-macros true]))

dviramontes21:04:57

with all that the following doesnt work it throws an error

(s/def ::node
  (s/or
    :leaf int?
    :branch (s/coll-of ::node :min-count 1 :max-count 2)))

(js/console.log (s/exercise ::node))

dviramontes21:04:42

let me know if you can spot the error, much appriciate

dviramontes21:04:24

tldr; the generator doesnt work which works in clj and does not work in cljs, not sure why or what im missing