Permalink
Browse files

Port tests to clojure.test.

  • Loading branch information...
1 parent 9fb5ee7 commit 4eedbc977d4195859268afc5dda35c993a178719 @mmcgrana committed Jan 25, 2010
View
3 project.clj
@@ -11,5 +11,4 @@
[clj-html "0.1.0-SNAPSHOT"]
[clj-stacktrace "0.1.0-SNAPSHOT"]]
:repositories [["mvnrepository" "http://mvnrepository.com/"]]
- :dev-dependencies [[lein-clojars "0.5.0-SNAPSHOT"]
- [clj-unit "0.1.0-SNAPSHOT"]])
+ :dev-dependencies [[lein-clojars "0.5.0-SNAPSHOT"]])
View
8 test/ring/handler/dump_test.clj
@@ -1,5 +1,5 @@
(ns ring.handler.dump-test
- (:use (clj-unit core)
+ (:use (clojure test)
(ring.handler dump))
(:import (java.io ByteArrayInputStream)))
@@ -12,8 +12,8 @@
{:uri "/foo/bar"
:request-method :get})
-(deftest "handle-dump"
+(deftest handler-dump
(let [{:keys [status]} (handle-dump post-req)]
- (assert= 200 status))
+ (is (= 200 status)))
(let [{:keys [status]} (handle-dump get-req)]
- (assert= 200 status)))
+ (is (= 200 status))))
View
54 test/ring/middleware/cookies_test.clj
@@ -1,57 +1,57 @@
(ns ring.middleware.cookies-test
- (:use clj-unit.core
+ (:use clojure.test
ring.middleware.cookies))
-(deftest "wrap-cookies: basic cookie"
+(deftest wrap-cookies-basic-cookie
(let [req {:headers {"cookie" "a=b"}}
resp ((wrap-cookies :cookies) req)]
- (assert= {"a" {:value "b"}} resp)))
+ (is (= {"a" {:value "b"}} resp))))
-(deftest "wrap-cookies: multiple cookies"
+(deftest wrap-cookies-multiple-cookies
(let [req {:headers {"cookie" "a=b; c=d,e=f"}}
resp ((wrap-cookies :cookies) req)]
- (assert= {"a" {:value "b"}, "c" {:value "d"}, "e" {:value "f"}}
- resp)))
+ (is (= {"a" {:value "b"}, "c" {:value "d"}, "e" {:value "f"}}
+ resp))))
-(deftest "wrap-cookies: quoted cookies"
+(deftest wrap-cookies-quoted-cookies
(let [req {:headers {"cookie" "a=\"b=c;e=f\""}}
resp ((wrap-cookies :cookies) req)]
- (assert= {"a" {:value "b=c;e=f"}}
- resp)))
+ (is (= {"a" {:value "b=c;e=f"}}
+ resp))))
-(deftest "wrap-cookies: escaped quotes"
+(deftest wrap-cookies-escaped-quotes
(let [req {:headers {"cookie" "a=\"\\\"b\\\"\""}}
resp ((wrap-cookies :cookies) req)]
- (assert= {"a" {:value "\"b\""}}
- resp)))
+ (is (= {"a" {:value "\"b\""}}
+ resp))))
-(deftest "wrap-cookies: extra attrs"
+(deftest wrap-cookies-extra-attrs
(let [req {:headers {"cookie" "a=b;$Path=\"/\";$Domain=localhost"}}
resp ((wrap-cookies :cookies) req)]
- (assert= {"a" {:value "b", :path "/", :domain "localhost"}}
- resp)))
+ (is (= {"a" {:value "b", :path "/", :domain "localhost"}}
+ resp))))
-(deftest "wrap-cookies: set basic cookie"
+(deftest wrap-cookies-set-basic-cookie
(let [handler (constantly {:cookies {"a" "b"}})
resp ((wrap-cookies handler) {})]
- (assert= {"Set-Cookie" (list "a=\"b\"")}
- (:headers resp))))
+ (is (= {"Set-Cookie" (list "a=\"b\"")}
+ (:headers resp)))))
-(deftest "wrap-cookies: set multiple cookies"
+(deftest wrap-cookies-set-multiple-cookies
(let [handler (constantly {:cookies {"a" "b", "c" "d"}})
resp ((wrap-cookies handler) {})]
- (assert= {"Set-Cookie" (list "a=\"b\"" "c=\"d\"")}
- (:headers resp))))
+ (is (= {"Set-Cookie" (list "a=\"b\"" "c=\"d\"")}
+ (:headers resp)))))
-(deftest "wrap-cookies: set keyword cookie"
+(deftest wrap-cookies-set-keyword-cookie
(let [handler (constantly {:cookies {:a "b"}})
resp ((wrap-cookies handler) {})]
- (assert= {"Set-Cookie" (list "a=\"b\"")}
- (:headers resp))))
+ (is (= {"Set-Cookie" (list "a=\"b\"")}
+ (:headers resp)))))
-(deftest "wrap-cookies: set extra attrs"
+(deftest wrap-cookies-set-extra-attrs
(let [cookies {"a" {:value "b", :path "/", :secure true}}
handler (constantly {:cookies cookies})
resp ((wrap-cookies handler) {})]
- (assert= {"Set-Cookie" (list "a=\"b\";Path=\"/\";Secure")}
- (:headers resp))))
+ (is (= {"Set-Cookie" (list "a=\"b\";Path=\"/\";Secure")}
+ (:headers resp)))))
View
39 test/ring/middleware/file_info_test.clj
@@ -1,5 +1,5 @@
(ns ring.middleware.file-info-test
- (:use (clj-unit core)
+ (:use (clojure test)
(ring.middleware file-info))
(:import (java.io File)))
@@ -16,23 +16,20 @@
(constantly {:headers {} :body known-file})
{"txt" "custom/type"}))
-(deftest "wrap-file-info: non-file response"
- (assert= {:headers {} :body "body"} (non-file-app {})))
-
-(deftest "wrap-file-info: known file response"
- (assert=
- {:headers {"Content-Type" "text/plain" "Content-Length" "6"}
- :body known-file}
- (known-file-app {})))
-
-(deftest "wrap-file-info: unknown file resonse"
- (assert=
- {:headers {"Content-Type" "application/octet-stream" "Content-Length" "7"}
- :body unknown-file}
- (unknown-file-app {})))
-
-(deftest "wrap-file-info: custom mime types"
- (assert=
- {:headers {"Content-Type" "custom/type" "Content-Length" "6"}
- :body known-file}
- (custom-type-app {})))
+(deftest wrap-file-info-non-file-response
+ (is (= {:headers {} :body "body"} (non-file-app {}))))
+
+(deftest wrap-file-info-known-file-response
+ (is (= {:headers {"Content-Type" "text/plain" "Content-Length" "6"}
+ :body known-file}
+ (known-file-app {}))))
+
+(deftest wrap-file-info-unknown-file-response
+ (is (= {:headers {"Content-Type" "application/octet-stream" "Content-Length" "7"}
+ :body unknown-file}
+ (unknown-file-app {}))))
+
+(deftest wrap-file-info-custom-mime-types
+ (is (= {:headers {"Content-Type" "custom/type" "Content-Length" "6"}
+ :body known-file}
+ (custom-type-app {}))))
View
46 test/ring/middleware/file_test.clj
@@ -1,43 +1,43 @@
(ns ring.middleware.file-test
- (:use (clj-unit core)
+ (:use (clojure test)
(ring.middleware file))
(:import (java.io File)))
-(deftest "wrap-file: no directory"
- (assert-throws #"Directory does not exist"
- (wrap-file (constantly :response) (File. "not_here"))))
+(deftest wrap-file-no-directory
+ (is (thrown-with-msg? Exception #".*Directory does not exist.*"
+ (wrap-file (constantly :response) (File. "not_here")))))
(def public-dir "test/ring/assets")
(def index-html (File. #^String public-dir "index.html"))
(def foo-html (File. #^String public-dir "foo.html"))
(def app (wrap-file (constantly :response) public-dir))
-(deftest "wrap-file: unsafe method"
- (assert= :response (app {:request-method :post :uri "/foo"})))
+(deftest wrap-file-unsafe-method
+ (is (= :response (app {:request-method :post :uri "/foo"}))))
-(deftest "wrap-file: forbidden url"
+(deftest wrap-file-forbidden-url
(let [{:keys [status body]} (app {:request-method :get :uri "/../foo"})]
- (assert= 403 status)
- (assert-match #"Forbidden" body)))
+ (is (= 403 status))
+ (is (re-find #"Forbidden" body))))
-(deftest "wrap-file: directory"
+(deftest wrap-file-directory
(let [{:keys [status headers body]} (app {:request-method :get :uri "/"})]
- (assert= 200 status)
- (assert= {} headers)
- (assert= index-html body)))
+ (is (= 200 status))
+ (is (= {} headers))
+ (is (= index-html body))))
-(deftest "wrap-file: file without extension"
+(deftest wrap-file-sans-extension
(let [{:keys [status headers body]} (app {:request-method :get :uri "/foo"})]
- (assert= 200 status)
- (assert= {} headers)
- (assert= foo-html body)))
+ (is (= 200 status))
+ (is (= {} headers))
+ (is (= foo-html body))))
-(deftest "wrap-file: file with extension"
+(deftest wrap-file-with-extension
(let [{:keys [status headers body]} (app {:request-method :get :uri "/foo.html"})]
- (assert= 200 status)
- (assert= {} headers)
- (assert= foo-html body)))
+ (is (= 200 status))
+ (is (= {} headers))
+ (is (= foo-html body))))
-(deftest "wrap-file: no file"
- (assert= :response (app {:request-method :get :uri "/dynamic"})))
+(deftest wrap-file-no-file
+ (is (= :response (app {:request-method :get :uri "/dynamic"}))))
View
26 test/ring/middleware/lint_test.clj
@@ -1,5 +1,5 @@
(ns ring.middleware.lint-test
- (:use (clj-unit core)
+ (:use (clojure test)
(ring.middleware lint))
(:import (java.io File InputStream ByteArrayInputStream)))
@@ -32,40 +32,42 @@
[constant-response]
(wrap-lint (fn [req] constant-response)))
+(defn is-lint-error [f]
+ (is (thrown-with-msg? Exception #"Ring lint error:.*" (f))))
+
(defmacro lints-req
[key goods bads]
- (let [good-name (str "request " key " valid values")
- bad-name (str "request " key " invalid values")]
+ (let [good-name (symbol (str "request-" key "-valid-values"))
+ bad-name (symbol (str "request-" key "-invalid-values"))]
`(do
(deftest ~good-name
(doseq [good# ~goods]
- (assert-truth (= valid-response
- (valid-response-app (assoc valid-request ~key good#)))
+ (is (= valid-response
+ (valid-response-app (assoc valid-request ~key good#)))
(format "%s is a valid value for request key %s"
(pr-str good#) ~key))))
(deftest ~bad-name
(doseq [bad# ~bads]
- (assert-throws #"Ring lint error:"
- (valid-response-app (assoc valid-request ~key bad#))))))))
+ (is-lint-error
+ (fn [] (valid-response-app (assoc valid-request ~key bad#)))))))))
(defmacro lints-resp
[key goods bads]
- (let [good-name (str "response " key " valid values")
- bad-name (str "response " key " invalid values")]
+ (let [good-name (symbol (str "response-" key "-valid-values"))
+ bad-name (symbol (str "response-" key "-invalid-values"))]
`(do
(deftest ~good-name
(doseq [good# ~goods]
(let [response# (assoc valid-response ~key good#)
app# (constant-app response#)]
- (assert-truth (= response# (app# valid-request))
+ (is (= response# (app# valid-request))
(format "%s is a valid value for response key %s"
(pr-str good#) ~key)))))
(deftest ~bad-name
(doseq [bad# ~bads]
(let [response# (assoc valid-response ~key bad#)
app# (constant-app response#)]
- (assert-throws #"Ring lint error:"
- (app# valid-request))))))))
+ (is-lint-error (fn [] (app# valid-request)))))))))
(lints-req :server-port
[80 8080]
View
24 test/ring/middleware/params_test.clj
@@ -1,5 +1,5 @@
(ns ring.middleware.params-test
- (:use (clj-unit core)
+ (:use (clojure test)
(ring.middleware params))
(:import (java.io ByteArrayInputStream)))
@@ -8,25 +8,25 @@
(def wrapped-echo (wrap-params identity))
-(deftest "wrap-params: query-params only"
+(deftest wrap-params-query-params-only
(let [req {:query-string "foo=bar&biz=bat%25"}
resp (wrapped-echo req)]
- (assert= {"foo" "bar" "biz" "bat%"} (:query-params resp))
- (assert-nil (:form-params resp))
- (assert= {"foo" "bar" "biz" "bat%"} (:params resp))))
+ (is (= {"foo" "bar" "biz" "bat%"} (:query-params resp)))
+ (is (nil? (:form-params resp)))
+ (is (= {"foo" "bar" "biz" "bat%"} (:params resp)))))
-(deftest "wrap-params: query-params and form-params"
+(deftest wrap-params-query-and-form-params
(let [req {:query-string "foo=bar"
:content-type "application/x-www-form-urlencoded"
:body (str-input-stream "biz=bat%25")}
resp (wrapped-echo req)]
- (assert= {"foo" "bar"} (:query-params resp))
- (assert= {"biz" "bat%"} (:form-params resp))
- (assert= {"foo" "bar" "biz" "bat%"} (:params resp))))
+ (is (= {"foo" "bar"} (:query-params resp)))
+ (is (= {"biz" "bat%"} (:form-params resp)))
+ (is (= {"foo" "bar" "biz" "bat%"} (:params resp)))))
-(deftest "wrap-params: not form encoded"
+(deftest wrap-params-not-form-encoded
(let [req {:content-type "application/json"
:body (str-input-stream "{foo: \"bar\"}")}
resp (wrapped-echo req)]
- (assert-nil (:form-params resp))
- (assert-nil (:params resp))))
+ (is (nil? (:form-params resp)))
+ (is (nil? (:params resp)))))
View
6 test/ring/middleware/reload_test.clj
@@ -1,9 +1,9 @@
(ns ring.middleware.reload-test
- (:use (clj-unit core)
+ (:use (clojure test)
(ring.middleware reload)))
(def app
(wrap-reload (constantly :response) '(ring.middleware.reload)))
-(deftest "wrap-reload"
- (assert= :response (app :request)))
+(deftest wrap-reload-smoke
+ (is (= :response (app :request))))
View
12 test/ring/middleware/stacktrace_test.clj
@@ -1,16 +1,16 @@
(ns ring.middleware.stacktrace-test
- (:use (clj-unit core)
+ (:use (clojure test)
(ring.middleware stacktrace)))
(def app (wrap-stacktrace #(throw (Exception. "fail"))))
(def html-req {})
(def js-req {:headers {"accept" "text/javascript"}})
-(deftest "wrap-stacktrace"
+(deftest wrap-stacktrace-smoke
(let [{:keys [status headers] :as response} (app html-req)]
- (assert= 500 status)
- (assert= {"Content-Type" "text/html"} headers))
+ (is (= 500 status))
+ (is (= {"Content-Type" "text/html"} headers)))
(let [{:keys [status headers]} (app js-req)]
- (assert= 500 status)
- (assert= {"Content-Type" "text/javascript"} headers)))
+ (is (= 500 status))
+ (is (= {"Content-Type" "text/javascript"} headers))))
View
10 test/ring/middleware/static_test.clj
@@ -1,5 +1,5 @@
(ns ring.middleware.static-test
- (:use (clj-unit core)
+ (:use (clojure test)
(ring.middleware static))
(:import (java.io File)))
@@ -13,7 +13,7 @@
(defn app-response-body [uri]
(:body (app {:request-method :get :uri uri})))
-(deftest "wrap-static"
- (assert= foo-html (app-response-body "/foo.html"))
- (assert= nested-foo-html (app-response-body "/bars/foo.html"))
- (assert= :dynamic (app-response-body "/not/static")))
+(deftest wrap-static-smoke
+ (is (= foo-html (app-response-body "/foo.html")))
+ (is (= nested-foo-html (app-response-body "/bars/foo.html")))
+ (is (= :dynamic (app-response-body "/not/static"))))
View
13 test/run.clj
@@ -1,13 +0,0 @@
-(set! *warn-on-reflection* true)
-
-(use 'clj-unit.core)
-(require-and-run-tests
- 'ring.handler.dump-test
- 'ring.middleware.lint-test
- 'ring.middleware.file-test
- 'ring.middleware.file-info-test
- 'ring.middleware.static-test
- 'ring.middleware.reload-test
- 'ring.middleware.stacktrace-test
- 'ring.middleware.params-test
- 'ring.middleware.cookies-test)

0 comments on commit 4eedbc9

Please sign in to comment.