Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Using ring-mock for unit tests

  • Loading branch information...
commit 697058cab113da1c5c6839af2733e2e8221ebc41 1 parent dcaf892
@weavejester authored
Showing with 11 additions and 13 deletions.
  1. +2 −1  project.clj
  2. +9 −12 test/compojure/test/core.clj
View
3  project.clj
@@ -5,4 +5,5 @@
[org.clojure/clojure-contrib "1.2.0"]
[clout "0.3.1"]
[ring/ring-core "0.3.4"]]
- :dev-dependencies [[ring/ring-jetty-adapter "0.3.4"]])
+ :dev-dependencies [[ring/ring-jetty-adapter "0.3.4"]
+ [ring-mock "0.1.1"]])
View
21 test/compojure/test/core.clj
@@ -1,5 +1,6 @@
(ns compojure.test.core
(:use clojure.test
+ ring.mock.request
clojure.contrib.mock.test-adapter
clojure.contrib.with-ns
compojure.core
@@ -13,9 +14,8 @@
(is (= x "bar"))
(is (= y "baz"))
nil)
- {:request-method :get
- :uri "/foo"
- :params {"x" "bar", "y" "baz"}}))
+ (-> (request :get "/foo")
+ (assoc :params {"x" "bar", "y" "baz"}))))
(testing "vector '& more' arguments"
((GET "/:x" [x y & more]
@@ -23,23 +23,20 @@
(is (= y "bar"))
(is (= more {"z" "baz"}))
nil)
- {:request-method :get
- :uri "/foo"
- :params {"y" "bar", "z" "baz"}}))
+ (-> (request :get "/foo")
+ (assoc :params {"y" "bar", "z" "baz"}))))
(testing "map arguments"
((GET "/foo" {params :params}
(is (= (params {:x "a", :y "b"})))
nil)
- {:request-method :get
- :uri "/foo"
- :params {"x" "a", "y" "b"}})))
+ (-> (request :get "/foo")
+ (assoc :params {"x" "a", "y" "b"})))))
(deftest route-matching
(testing "_method parameter"
- (let [req {:request-method :post
- :form-params {"_method" "PUT"}
- :uri "/foo"}
+ (let [req (-> (request :post "/foo")
+ (assoc :form-params {"_method" "PUT"}))
resp {:status 200, :headers {}, :body "bar"}
route (PUT "/foo" [] resp)]
(is (= (route req) resp))))
Please sign in to comment.
Something went wrong with that request. Please try again.