I'm trying out Clojure web development with Ring + Compojure + lib-noir, and I can't figure out how to test the session state.
Asked
Active
Viewed 633 times
4
-
4by "test the session state" you mean creating unit tests or just peeking at the contents of the current session? – Denis Fuenzalida Mar 18 '13 at 16:05
2 Answers
0
I think you can just mimic the style used for the actual session tests in 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 assert the handlers respond accordingly. Given you are also using lib-noir, perhaps this example is more appropriate: https://github.com/noir-clojure/lib-noir/blob/master/test/noir/session_test.clj.

dgtized
- 3,192
- 2
- 24
- 23
0
If you mean for unit tests, you can use binding
, which will create new bindings for the vars.
You can check a good explanation that can be found here.
A sample 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"))))
You can check the source code of noir.session
here.

Community
- 1
- 1

Robin Carlo Catacutan
- 13,249
- 11
- 52
- 85