-
Notifications
You must be signed in to change notification settings - Fork 20
Usage
Allen Rohner edited this page Apr 14, 2017
·
1 revision
Use clojure.spec as normal. Then, at the repl or during tests:
(require '[spectrum.check :as check])
(check/check 'your.namespace)Returns a seq of Error defrecords.
There is also
(check/type-of '(map inc (range 5)))which is useful when you want to debug the signature of a form.
type-of can optionally also take a map of keywordized variables to spects
(check/type-of '(string? x) {:x (c/pred-spec #'string?)})
#Value[true]
(check/type-of '(string? x) {:x (c/value 3)})
#Value[false]- if you use a predicate in a spec, i.e.
(s/fdef foo :args (s/cat :x bar?)), thenbar?should be spec'd, or you'll get a warning
If you have a predicate that is just a simple simple instance? check for a class, i.e.
(defrecord Foo ...)
(defn foo? [x] (instance? Foo x))You'll want to add:
(:require [spectrum.ann :as ann])
(ann/ann #'foo? (ann/instance-transformer Foo))This tells the system that expressions tagged w/ spec #'foo? are of class Foo, which is useful in java interop, both for Java methods that take Foo, and the defrecord constructors: (->Foo and map->Foo).