-
-
Save FossiFoo/f98f2eaf920c3481d9fdf9bdeb41c420 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; db.clj | |
(s/def :server.db/select-result any?) | |
(defn select | |
"fdef wrapper for select" | |
[db selector] | |
(adi/select db selector)) | |
(s/fdef select | |
:args (s/cat :db ::db :selector any?) | |
:ret :server.db/select-result) | |
;; prj.clj | |
(s/def :sexpress/project-name string?) | |
(s/def :sexpress/project (s/keys :req [:sexpress/project-name])) | |
(s/def :sexpress/project-list (s/coll-of :sexpress/project)) | |
(defn list | |
[db] | |
(let [val (s/conform :sexpress/project-list (spy :error (db/select db :project)))] | |
(if (= :clojure.spec/invalid val) | |
(s/explain :sexpress/project-list val) | |
val))) | |
(s/fdef list | |
:args (s/cat :db any?) | |
:ret :sexpress/project-list) | |
(deftest checks-spec | |
(stest/instrument `server.db/insert! {:stub #{`server.db/insert!}}) | |
(stest/instrument `server.db/select {:stub #{`server.db/select} | |
:spec {`server.db/select (s/fspec :args (s/cat :db :server.db/db :selector any?) | |
:ret :sexpress/project-list)} | |
;; :gen {:server.db/select-result :sexpress/project-list} | |
;; :replace {`server.db/select (fn [_ _] (gen/generate (gen/fmap (fn [a] [{:sexpress/project-name a}]) (gen/string))))} | |
}) | |
(let [checks (stest/summarize-results (stest/check (stest/enumerate-namespace 'server.projects)))] | |
(is (= (:total checks) (:check-passed checks)) checks) | |
(is (> (:total checks) 0)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment