1
我想为Pedestal网络服务编写测试。Clojure - 测试Pedestal路线
如果我有:
(defn pong
[request]
(ring-resp/response "pong"))
(defroutes routes[[["/" {:get pong}]]])
我怎么会写一个测试?
(deftest alive-system
(testing "ping-pong route"
;; How do I test my route ?
;; If possible :
;; - I would like to have direct access to it
;; ie. no need to bind pedestal to a port would be nice
;; - The ability to omit some interceptors would be nice also,
;; as it would allow me to receive plain Clojure data structures
;; instead of, for instance, JSON which I would have to parse.
...)
编辑: 这里是我的尝试:
(deftest alive-system
(testing "ping-pong route"
(let [response (my-other.ns/routes (mock/request :get "/ping"))]
(is (= (:status response) 200))
(is (= (:body response) "pong")))))
但我得到一个异常:
ERROR in (alive-system) (service_test.clj:13)
Uncaught exception, not in assertion.
expected: nil
actual: java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to clojure.lang.IFn
你看过https://github.com/ring-clojure/ring-mock吗? – ez121sl
@ ez121sl我做了,我已经使用它与compojure应用程序,让我编辑我的问题。 – nha
Compojure的'defroutes'创建一个戒指处理器或其他类似的东西。基座的版本显然不同。他们的示例测试不使用ring-mock:https://github.com/pedestal/pedestal/blob/master/samples/hello-world/test/hello_world/service_test.clj – ez121sl