This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-10
Channels
- # beginners (151)
- # cider (41)
- # cljdoc (7)
- # cljs-dev (6)
- # clojure (92)
- # clojure-dev (5)
- # clojure-italy (26)
- # clojure-losangeles (1)
- # clojure-nl (10)
- # clojure-russia (3)
- # clojure-spec (23)
- # clojure-uk (82)
- # clojurescript (56)
- # clojutre (1)
- # core-async (3)
- # cursive (15)
- # datomic (26)
- # editors (3)
- # emacs (3)
- # events (2)
- # figwheel-main (192)
- # fulcro (66)
- # leiningen (12)
- # mount (1)
- # off-topic (131)
- # portkey (6)
- # re-frame (38)
- # reagent (10)
- # reitit (7)
- # ring-swagger (55)
- # shadow-cljs (21)
- # spacemacs (11)
- # tools-deps (48)
I have a function that takes 2 arguments, the second of which needs to conform to a spec:
(s/def ::MySpec (s/cat ::foo string? ::bar keyword? ::baz vector?))
(defn myFunc [one two])
(s/fdef myFunc :args (s/cat :one ::One :two ::MySpec))
When running stest/check
on this function, I get an ArityException because the (s/cat a (s/cat b c d))
is becoming 4 arguments
I listened to the REPL podcast today and the interviewee (Higginbotham) said there were benefits with putting specs in their own namespace. How exactly? For fdefs I find it useful to have them close to the function as documentation?
@borkdude It means your code can still be used without spec since the specs -- and those namespaces -- are optional.
clojure.java.jdbc
does that so it can still support back to Clojure 1.7.
Also, most of our specs at work are data specs, not function specs -- and we find it easier to have a namespace for data specs. One place to go read them all (for a given data concern).
I instrument the java.jdbc
lib for the tests within that lib -- which slows things down dramatically.
At work, we tend to instrument specific functions (that have fdef specs) only within their specific tests.
We use the data specs in production code (to validate/conform data).
I find it annoying to get the wrong keys. Whenever I encounter that I tend to put an fdef now and instrument it (only for dev)
We also use the data specs in tests -- for generative testing, or just for random example-based test data.
Is there anyway to force a specific path with a call to s/gen
?
Here’s a trivial example:
(s/def ::value (s/or :a map? :b int?)
(s/def ::message :req-un [::value])
(gen/generate (s/gen ::message))
I want the final line to always return with the ::value
codepath of :a
for the purpose of generating data for a test. Is this possible?take a look at the 2-arity version of s/gen
https://clojuredocs.org/clojure.spec.alpha/gen, it takes an overrides map