adding m/start-without

This commit is contained in:
anatoly 2015-11-15 14:40:34 -05:00
parent 9ee066ed96
commit 4ec7bb5e57
4 changed files with 41 additions and 5 deletions

View file

@ -13,11 +13,12 @@
[clojure.test :as test]
;; [clojure.core.async :refer [>!! <!! >! <! go-loop alt! timeout]]
[clojure.tools.namespace.repl :as tn]
[check.parts-test]
[mount]
[app :refer [create-nyse-schema find-orders add-order]])) ;; <<<< replace this your "app" namespace(s) you want to be available at REPL time
(defn start []
(mount/start))
(mount/start-without #'check.parts-test/should-not-start)) ;; example on how to start app without certain states
(defn stop []
(mount/stop))

View file

@ -1,7 +1,7 @@
(ns mount
(:require [clojure.tools.macro :as macro]
[clojure.tools.namespace.repl :refer [disable-reload!]]
[clojure.tools.logging :refer [info debug error]]))
[clojure.tools.logging :refer [info warn debug error]]))
(disable-reload!)
@ -48,12 +48,13 @@
(intern ns (symbol name) s)
(alter-meta! var assoc :started? true))))
(defn- down [var {:keys [name stop started?]}]
(defn- down [var {:keys [ns name stop started?]}]
(when started?
(info "<< stopping.. " name)
(when stop
(try
(stop)
(intern ns (symbol name) (NotStartedState. name))
(catch Throwable t
(throw (RuntimeException. (str "could not stop [" name "] due to") t)))))
(alter-meta! var assoc :started? false)))
@ -100,3 +101,19 @@
(if (first states)
(start states)
(start)))
(defn start-with [with]
(if (seq with)
(let [app (find-all-states)]
;; needs more thinking on merging, since the ns should not change
;; because it could be used in other states, so only start/stop need to be merged
(warn "substituting states is not _yet_ implemented")
(start))
(start)))
(defn start-without [& states]
(if (first states)
(let [app (set (find-all-states))
without (remove (set states) app)]
(apply start without))
(start)))

View file

@ -3,12 +3,12 @@
[app.nyse :refer [conn]]
[clojure.test :refer :all]))
(defstate should-not-start :start (throw (RuntimeException. "should not have been started!")))
(defstate should-not-start :start (constantly 42))
(defn with-parts [f]
(m/start #'app.config/app-config #'app.nyse/conn)
(f)
(m/stop #'app.config/app-config #'app.nyse/conn))
(m/stop))
(use-fixtures :each with-parts)

View file

@ -0,0 +1,18 @@
(ns check.without-test
(:require [mount :as m]
[app.config :refer [app-config]]
[app.nyse :refer [conn]]
[app :refer [nrepl]]
[clojure.test :refer :all]))
(defn without [f]
(m/start-without #'app.nyse/conn #'app/nrepl)
(f)
(m/stop))
(use-fixtures :each without)
(deftest start-without-states
(is (map? app-config))
(is (instance? mount.NotStartedState nrepl))
(is (instance? mount.NotStartedState conn)))