[#5]: tests for (mount/stop-except)

This commit is contained in:
anatoly 2015-11-19 09:11:30 -05:00
parent ae9c343820
commit 992f67397a
2 changed files with 38 additions and 7 deletions

View file

@ -33,13 +33,13 @@
(let [[state params] (macro/name-with-attributes state body)
{:keys [start stop suspend resume] :as lifecycle} (apply hash-map params)]
(validate lifecycle)
(let [s-meta (-> {:mount-state mount-state
:order (make-state-seq state)
:start `(fn [] (~@start))
:started? false}
(cond-> stop (assoc :stop `(fn [] (~@stop))))
(cond-> suspend (assoc :suspend `(fn [] (~@suspend))))
(cond-> resume (assoc :resume `(fn [] (~@resume)))))]
(let [s-meta (cond-> {:mount-state mount-state
:order (make-state-seq state)
:start `(fn [] (~@start))
:started? false}
stop (assoc :stop `(fn [] (~@stop)))
suspend (assoc :suspend `(fn [] (~@suspend)))
resume (assoc :resume `(fn [] (~@resume))))]
`(defonce ~(with-meta state (merge (meta state) s-meta))
(NotStartedState. ~(str state))))))

View file

@ -0,0 +1,31 @@
(ns check.stop-except-test
(:require [mount.core :as mount :refer [defstate]]
[app.config :refer [app-config]]
[app.nyse :refer [conn]]
[app :refer [nrepl]]
[clojure.test :refer :all]))
(deftest stop-except
(testing "should stop all except nrepl"
(let [_ (mount/start)
_ (mount/stop-except #'app.nyse/conn #'app.config/app-config)]
(is (map? app-config))
(is (instance? datomic.peer.LocalConnection conn))
(is (instance? mount.core.NotStartedState nrepl))
(mount/stop)))
(testing "should start normally after stop-except"
(let [_ (mount/start)]
(is (map? app-config))
(is (instance? clojure.tools.nrepl.server.Server nrepl))
(is (instance? datomic.peer.LocalConnection conn))
(mount/stop)))
(testing "should stop all normally after stop-except"
(let [_ (mount/start)
_ (mount/stop-except #'app.nyse/conn #'app.config/app-config)
_ (mount/stop)]
(is (instance? mount.core.NotStartedState app-config))
(is (instance? mount.core.NotStartedState conn))
(is (instance? mount.core.NotStartedState nrepl)))))