Permalink
Browse files

Improved core test layout with testing macro

  • Loading branch information...
1 parent fa6af67 commit 84a16ada60fa025156ea75e8c6acaa11086a73d8 @weavejester committed Jul 13, 2010
Showing with 50 additions and 52 deletions.
  1. +50 −52 test/compojure/test/core.clj
View
102 test/compojure/test/core.clj
@@ -7,61 +7,59 @@
clout.core)
(:require [compojure.test-namespace :as testns]))
-(deftest route-with-vector-arguments
- ((GET "/foo" [x y]
- (is (= x "bar"))
- (is (= y "baz"))
- nil)
- {:request-method :get
- :uri "/foo"
- :params {"x" "bar", "y" "baz"}}))
+(deftest request-destructuring
+ (testing "vector arguments"
+ ((GET "/foo" [x y]
+ (is (= x "bar"))
+ (is (= y "baz"))
+ nil)
+ {:request-method :get
+ :uri "/foo"
+ :params {"x" "bar", "y" "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"}})))
-(deftest route-with-map-arguments
- ((GET "/foo" {params :params}
- (is (= (params {:x "a", :y "b"})))
- nil)
- {:request-method :get
- :uri "/foo"
- :params {"x" "a", "y" "b"}}))
+(deftest route-matching
+ (testing "_method parameter"
+ (let [req {:request-method :post
+ :form-params {"_method" "PUT"}
+ :uri "/foo"}
+ resp {:status 200, :headers {}, :body "bar"}
+ route (PUT "/foo" [] resp)]
+ (is (= (route req) resp))))
-(deftest route-with-method-param
- (let [req {:request-method :post
- :form-params {"_method" "PUT"}
- :uri "/foo"}
- resp {:status 200, :headers {}, :body "bar"}
- route (PUT "/foo" [] resp)]
- (is (= (route req) resp))))
+ (testing "custom regexes"
+ (expect [route-compile
+ (has-args ["/foo/:id" {:id "[0-9]+"}]
+ (times 1))]
+ (eval `(GET ["/foo/:id" :id "[0-9]+"] [])))))
-(deftest route-with-custom-regexes
- (expect [route-compile
- (has-args ["/foo/:id" {:id "[0-9]+"}]
- (times 1))]
- (eval `(GET ["/foo/:id" :id "[0-9]+"] []))))
+(deftest wrap
+ (testing "wrap function"
+ (defn func1 [x] (inc x))
+ (let [wrapper (fn [f] (fn [x] (f (inc x))))]
+ (wrap! func1 wrapper)
+ (is (= (func1 3) 5))))
-(defn func1 [x] (inc x))
+ (testing "wrap keyword"
+ (defn func2 [x] (inc x))
+ (defn wrap-test1 [f]
+ (fn [x] (f (* 2 x))))
+ (wrap! func2 :test1)
+ (is (= (func2 3) 7)))
-(deftest wrap-var-with-funcion
- (let [wrapper (fn [f] (fn [x] (f (inc x))))]
- (wrap! func1 wrapper)
- (is (= (func1 3) 5))))
+ (testing "wrap namespaced keyword"
+ (defn func3 [x] (inc x))
+ (wrap! func3 :testns/test2)
+ (is (= (func3 3) 10)))
-(defn func2 [x] (inc x))
-
-(defn wrap-test1 [f]
- (fn [x] (f (* 2 x))))
-
-(deftest wrap-var-with-keyword
- (wrap! func2 :test1)
- (is (= (func2 3) 7)))
-
-(defn func3 [x] (inc x))
-
-(deftest wrap-var-with-namespaced-keyword
- (wrap! func3 :testns/test2)
- (is (= (func3 3) 10)))
-
-(defn func4 [x] (inc x))
-
-(deftest wrap-var-with-function-and-keyword
- (wrap! func4 wrap-test1 :test1)
- (is (= (func4 3) 13)))
+ (testing "wrap function and keyword"
+ (defn func4 [x] (inc x))
+ (wrap! func4 wrap-test1 :test1)
+ (is (= (func4 3) 13))))

0 comments on commit 84a16ad

Please sign in to comment.