How to check session state with Ring?

I am testing Clojure web development with Ring + Compojure + lib-noir and I cannot figure out how to check the state of the session.

+4
source share
2 answers

I think you can just mimic the style used for actual session tests in a ring: https://github.com/ring-clojure/ring/blob/master/ring-core/test/ring/middleware/session/test/cookie .clj .

Just create a cookie store and then read / write to it and approve that the handlers respond accordingly. Given that you are also using lib-noir, this example might be more appropriate: https://github.com/noir-clojure/lib-noir/blob/master/test/noir/session_test.clj .

0
source

If you mean for unit tests, you can use binding , which will create new bindings for vars.

You can check out the good explanation that can be found here .

Trial unit tests with lib-noir

 (ns your.test.core (:use [clojure.test]) (:require [noir.session :as s])) (binding [s/*noir-session* (atom {})] ; store new sessions (s/put! "xxxx" {:value "1234"}) (s/put! "my_session" {:value "abcdefg"}) ; run tests (is (= {:value "1234"} (s/get "xxxx"))) (is (= {:value "abcdefg"} (s/get "my_session")))) 

Here you can check the source code of noir.session .

0
source

All Articles