-
-
Notifications
You must be signed in to change notification settings - Fork 10
start! function
start!
(found in stub-http.core
) is a function that is useful if you don't want to use the with-routes! macro, for example if you want to reuse the same server
instance in multiple tests. start!
also allows you to define additional settings (such as a predefined port) which the with-routes!
macro doesn't. Usage example:
(let [server (start! {"/something" {:status 200 :content-type "text/plan" :body "hello" }})
uri (:uri server)]
(try
(is (= "hello" (:body (client/get (str uri "/something")))))
(finally
(.close server)))
This will start the stub server on a free port and return the "server" record/instance. Note that if you use the start!
function like this you need to stop it manually.
The server
record implements Closable which means that you can use the with-open macro in Clojure to automatically having it closed. The previous example could thus be written as:
(with-open [server (start! {"/something" {:status 200 :content-type "text/plan" :body "hello" }})]
(is (= "hello" (:body (client/get (str uri "/something"))))))
which is less verbose.
The start!
functions also allows you to define additional settings