Fork me on GitHub
#clojure-spec
<
2020-08-06
>
Oliver George02:08:14

I keep wanting ::x/blah to expand to :current.namespace$x/blah when there's no x alias. It'd open up "private namespaces" for spec use.

Oliver George02:08:46

My use case is CLJS function arg specs. I have many fns in a ns. They expect different things from a :db key passed in as context. (re-frame handlers)

Oliver George02:08:26

With the proposed change I could do things like this

(ns app.events (:require [clojure.spec.alpha :as s]))
(defn event1 [{:keys [db]}] ...)
(defn event2 [{:keys [db]}] ...)
(s/fdef event1 :args (s/cat :ctx (s/keys :req-un [::event1/db]))
(s/def ::event1/db (s/keys :req-un [::ddb])))
(s/fdef event2 :args (s/cat :ctx (s/keys :req-un [::event2/db]))
(s/def ::event2/db (s/keys :req-un [::form])))

Oliver George02:08:12

Perhaps a macro would do the job so could add to replace keyword namespaces in a form

(rename-keyword-ns {*ns* :app.events$event1)
  (s/fdef event1 (s/cat :ctx (s/keys :req-un [::db]))
  (s/def ::db (s/keys :req-un [::ddb]))))

seancorfield02:08:32

I suspect Spec 2 (a.k.a. what will eventually become just clojure.spec 🙂 ) will help you here because you can define a schema will all the possible keys with their specs, all in one place -- and then you can select the specific keys that are required for each individual handler.

Oliver George04:08:32

Good point. If/when that lands it'll be an improvement.

Oliver George04:08:33

I guess it'd look something like this...

(ns app.events (:require [clojure.spec2 :as s]))
(defn event1 [{:keys [db]}] ...)
(defn event2 [{:keys [db]}] ...)
(s/def ::ctx (s/schema {:db ::db}))
(s/def ::db (s/schema {:ddb ::ddb :form ::form}))
(s/fdef event1 :args (s/cat :ctx (s/select ::ctx [:db {:db [:ddb]}]))
(s/fdef event2 :args (s/cat :ctx (s/select ::ctx [:db {:db [:form]}]))

Oliver George04:08:56

(Guessing at the unqualified key bits)

johanatan17:08:29

hi, does clojure.spec.test.alpha/check run its test cases in sequence or in parallel ?

johanatan18:08:47

any way to tell it to do sequential? because my code under test is already parallel and is kicking off a bunch of promises

johanatan18:08:08

and the combination of the two is overwhelming the browser i'm afraid

johanatan18:08:21

ok, no worries. i can just limit the num-tests to a small amount for now