This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-05
Channels
- # aleph (190)
- # bangalore-clj (4)
- # beginners (31)
- # boot (127)
- # braid-chat (2)
- # cider (2)
- # cljs-dev (79)
- # cljsrn (7)
- # clojure (81)
- # clojure-dev (1)
- # clojure-greece (40)
- # clojure-italy (3)
- # clojure-korea (8)
- # clojure-new-zealand (5)
- # clojure-russia (5)
- # clojure-spec (87)
- # clojure-uk (13)
- # clojurescript (50)
- # cloverage (10)
- # component (4)
- # core-async (37)
- # cursive (26)
- # datascript (20)
- # datomic (29)
- # editors (2)
- # emacs (12)
- # hoplon (63)
- # jobs (2)
- # lein-figwheel (1)
- # leiningen (17)
- # liberator (2)
- # off-topic (19)
- # om (31)
- # onyx (9)
- # pedestal (4)
- # proton (1)
- # re-frame (22)
- # reagent (13)
- # ring (1)
- # ring-swagger (9)
- # spacemacs (5)
- # specter (4)
- # untangled (24)
- # vim (29)
Is there a workaround to http://dev.clojure.org/jira/browse/CLJ-2033 for un-namespaced keys ?
I guess a workaround would be to do the composition at a higher level, and not rely on spec/merge for merging specs like this, which is... odd
I think it's encouraged to wrap protocol fn invocation, so you can instrument/spec the wrapper fn. otherwise if you mean spec predicate it's just #(satisfies? %), possibly with (s/spec pred :gen ... ) if you want to have the gen part
Anyone used spec with DataScript? Need tips on how to deal with the fact that entities are not maps, and specifically how to get the same functionality as clojure.spec/keys but for Datascript entities
Is it possible to define a spec
that references itself in the definition - like in Context-Free Grammars?
Sure, via it's registered keyword
Recursive and mutually recursive specs are fine
Could you share an example?
There are several in clojure.core.specs - destructuring is recursive
Some of the ns stuff with prefix lists , etc
::prefix-list there is self-recursive
::binding-form can be ::seq-binding-form or ::map-binding-form, which can both include ::binding-form
I’m looking at it
A really good example to try is just a simple tree of leaf and branch
Where branches can contain either leaf or branch
What's the best way to trigger clojure.spec tests with lein test? I.e. I have a namesapce with (stest/check (stest/enumerate-namespace 'wwai.common.util.instant))
, I want it run those checks when I do lein test
.
I'm really using expectations
, but if I see how to make it work with standard test, I should be able to adapt from their.
@ag i’d love to see an example of that on github if you have one, np if not, just figured i’d check 🙂
I came up with this hack, which kind of works, although the output in the error case, isn't very friendly:
(defmacro is-result-ok?
[result]
`(is (not (:failure (first ~result)))))
(deftest auto
(doseq [spec-fn-sym (stest/enumerate-namespace 'wwai.common.util.instant)]
(is-result-ok? (stest/check spec-fn-sym))))
I would've expected this to throw: https://gist.github.com/luxbock/532a19f75553ae938c0a998e3be47851
it runs the function a bunch of times with generated args (in this case always nothing) and checks the result conforms to :ret and that any supplied :fn relationship between :args and :ret is true
boot.user=> (s/def ::number int?)
:boot.user/number
boot.user=> (s/def ::number-list (s/coll-of ::number :min-count 1))
:boot.user/number-list
boot.user=> (s/fdef foobar
#_=> :args (s/cat)
#_=> :ret ::number-list)
boot.user/foobar
boot.user=> (defn foobar [] [])
#'boot.user/foobar
boot.user=> (clojure.spec.test/check `foobar)
({:spec #object[clojure.spec$fspec_impl$reify__13891 0x222df61e "clojure.spec$fspec_impl$reify__13891@222df61e"], :clojure.spec.test.check/ret {:result #error {
:cause "Specification-based check failed"
:data {:clojure.spec/problems [{:path [:ret], :pred (clojure.core/<= 1 (clojure.core/count %) Integer/MAX_VALUE), :val [], :via [], :in []}], :clojure.spec.test/args (), :clojure.spec.test/val [], :clojure.spec/failure :check-failed}
:via
[{:type clojure.lang.ExceptionInfo
:message "Specification-based check failed"
thanks, yeah the function which I simplified here probably won't need a spec at all, but it's good to know this for the future
so far I have (s/keys :req-un [::start-date ::end-date]) but I need to add in a predicate
perhaps you could write a constructor function rather than making instances of that map by hand, and it’s got an (s/fdef) that encodes that information?
maybe you could use s/and and a predicate, something like:
(s/and (s/keys :req-un [::start-date ::end-date]) #( date-before? (:start-date %) (:end-date %)))
boot.user=> (s/def ::thing (s/conformer {1 "foo"}))
:boot.user/thing
boot.user=> (s/unform ::thing (s/conform ::thing 1))
java.lang.IllegalStateException: no unform fn for conformer
boot.user=> (s/def ::thing (s/conformer {1 "foo"} {"foo" 1}))
:boot.user/thing
boot.user=> (s/unform ::thing (s/conform ::thing 1))
1
e.g. (s/and (s/keys :req-un [::start-date ::end-date]) "start date must come before end date" #( date-before? (:start-date %) (:end-date %)))
has anyone else had trouble doing eg
(stest/instrument (stest/enumerate-namespace ‘my.ns))
in cljs?i see a stacktrace with error messages like java.lang.RuntimeException: No such namespace: stest, compiling:(/private/var/folders/zl/bh7pbyz95rg7pmcvcc_f_kdm0000gn/T/form-init2230077429322923281.clj:6:19)
; gonna dig into it a bit, just curious if this is known / expected / if anyone else has dealt with this
if i do eg
(let [syms (stest/enumerate-namespace 'voke.events)]
(stest/instrument syms))
then i get
Caused by: clojure.lang.ExceptionInfo: java.lang.RuntimeException: Unable to resolve symbol: syms in this context
feels like i must be doing something wrongperhaps related to the (eval) call in https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/spec/test.cljc#L110 ?
should i just instrument vars by hand, naming one at a time, or is there some better way?
when i do
(stest/instrument (stest/enumerate-namespace 'my.ns))
, i get an error message complaining that stest doesn’t exist
Today's random spec experiment: Can you define an SQL schema from a clojure.spec definition?
Here's what I came up with: https://gist.github.com/olivergeorge/27e9fced404f5ddef371ea3376456f2f
(do
(s/def ::name string?)
(s/def ::address (varchar 256))
(s/def ::age integer?)
(s/def ::gender #{"M" "F"})
(s/def ::example-table (s/keys :req-un [::name ::age ::gender]
:opt-un [::address]))
(spec->sql-table ::example-table))
oooh I should bookmark this. I'm definitely going to need spec->avro schema at some point
Produces
[["name" "varchar2(4000)" "not null"]
["age" "int" "not null"]
["gender" "varchar2(1)" "not null"]
["address" "varchar2(256)"]]