This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-21
Channels
- # aleph (5)
- # aws (3)
- # bangalore-clj (1)
- # beginners (8)
- # boot (198)
- # cider (4)
- # cljsjs (5)
- # cljsrn (2)
- # clojure (14)
- # clojure-argentina (1)
- # clojure-dusseldorf (8)
- # clojure-greece (29)
- # clojure-italy (10)
- # clojure-japan (1)
- # clojure-poland (4)
- # clojure-russia (8)
- # clojure-spec (51)
- # clojure-uk (8)
- # clojurescript (97)
- # cursive (4)
- # datomic (6)
- # emacs (2)
- # events (2)
- # figwheel (3)
- # hoplon (32)
- # lein-figwheel (5)
- # leiningen (1)
- # luminus (2)
- # off-topic (29)
- # om (109)
- # other-languages (38)
- # proton (3)
- # re-frame (3)
- # ring (1)
- # slack-help (10)
- # testing (1)
- # uncomplicate (1)
- # untangled (21)
- # vim (10)
- # yada (11)
If I want to make sure that a map does not contain a specific attribute, for example :user/password, how do I do that?
My first one is how to "compose" or programmatically generate specs, I have a multi spec with a lot of repetitive code
so i'd like to be able to do something along the lines of
(defn base-op [& ks] (spec/keys :req (concat [::base1 ::base2] ks)))
This works but doesn't feel right, if there's a better approach, happy to hear about it 🙂
there's also s/merge
for this purpose, but I can't say really, haven't used it much so far
(s/def ::foo string?)
(s/def ::bar string?)
(s/def ::base (s/keys :req [::foo]))
(s/def ::stuff (s/keys :req [::bar]))
(s/def ::n (s/and ::base ::stuff))
(s/valid? ::n {::foo "0" ::bar "1"}) => true
I did it wrong again: (gen/large-integer* {:min 1e6 ...})
-> Doubles (my fault I know), but maybe there could be an assert (or casting) there
Is it possible to "share" a generator value for multiple keys in a map (or values in a spec) -> ex: a user profile with N fields?
Hi! How do I override generators for test/check? doc says we can pass :gen parameter in there, but can’t find any example. passing something like (stest/check split-operation {:gen {:onair.ot/count (s/gen :onair.ot/bounded-count)}})
shows that it is not generator which is expected as a value, but what then?
getting error like clojure.test.check.generators.Generator cannot be cast to clojure.lang.IFn
the problem I’m trying to address is actually testing for interger overflow, I don’t care about it, but generator for int passes huge numbers to a function, which causes it to fail with overflow exception. bounding value with predicate in spec causes a fail in conforming results =(
looks like (stest/check split-operation {:gen {:onair.ot/count #(s/gen :onair.ot/bounded-count)}})
helps 😃
clojure.spec.gen wraps clojure.test.check.generators, and the way it wraps it results in generators becoming no argument functions that return generators (this is to make the dependency on test.check optional). It can make it kind of confusing about when to use a test.check generator and when to use a function returning a generator, most notably when using the generator combinators in clojure.spec.gen
the answer is to always use a function returning a generator
I only find it to be confusing when using both spec.gen and test.check.generators at the same time
so I mostly try not to do that :)
i’m trying to s/exercise
a function i spec’d and i’m getting:
ExceptionInfo Unable to construct gen at: [] for: feefi.handler$option_settings__GT_environment_variables@39a0e135 clojure.core/ex-info (core.clj:4725)
what does it mean “`at: []`"
user=> (require '[clojure.spec :as s])
nil
user=> (s/def ::foo (constantly false))
:user/foo
user=> (s/exercise ::foo)
ExceptionInfo Unable to construct gen at: [] for: :user/foo clojure.core/ex-info (core.clj:4725)
user=>
Where are you guys putting your clojure.spec.test/check
calls? Are they in an is
where you check if :result
is true?
When using test.check I would use defspec
. Is there some similar integration point with clojure.spec.test?
Maybe something like this?
(defmacro defspec-test
[name & test-check-args]
(when t/*load-tests*
`(def ~(vary-meta name assoc :test `(fn [] (clojure.spec.test/check ~@test-check-args)))
(fn [] (t/test-var (var ~name))))))
this is right beneath it:
(s/fdef option-settings->environment-variables
:args :elb/option-settings
:ret :elb/option-setting
:fn #(= "EnvironmentVariables" (-> % :ret :option-name)))
i followed this exactly https://asciinema.org/a/87157 to use exercise-fn
and get:
IllegalArgumentException No implementation of method: :specize* of protocol: #'clojure.spec/Specize found for class: nil clojure.core/-cache-protocol-fn (core_deftype.clj:583)
=/@kenny i haven’t seen official guidance on this. have you seen the summarize-results function, though?
I wrote a version of defspec
that uses abbrev-result
. So you could do something like
(defspec-test qc-myfn? `myfn)