This commit is contained in:
Tommi Reiman 2017-12-31 11:34:13 +02:00
parent 708fa24590
commit 07bcd2ea59
5 changed files with 29 additions and 31 deletions

View file

@ -1,7 +1,6 @@
(ns reitit.spec
(:require [clojure.spec.alpha :as s]
[clojure.spec.gen.alpha :as gen]
[clojure.string :as str]
[reitit.core :as reitit]))
;;

View file

@ -48,4 +48,3 @@
(is (= nil (coercion/coerce! m))))
(let [m (r/match-by-path r "/none/kikka/abba")]
(is (= nil (coercion/coerce! m))))))))

View file

@ -16,7 +16,7 @@
(is (= name (r/router-name router)))
(is (= [["/api/ipa/:size" {:name ::beer} nil]]
(r/routes router)))
(is (= true (map? (r/options router))))
(is (map? (r/options router)))
(is (= (r/map->Match
{:template "/api/ipa/:size"
:data {:name ::beer}
@ -39,7 +39,7 @@
:required #{:size}
:params nil})
(r/match-by-name router ::beer)))
(is (= true (r/partial-match? (r/match-by-name router ::beer))))
(is (r/partial-match? (r/match-by-name router ::beer)))
(is (thrown-with-msg?
ExceptionInfo
#"^missing path-params for route /api/ipa/:size -> \#\{:size\}$"
@ -72,7 +72,7 @@
(is (= name (r/router-name router)))
(is (= [["/api/ipa/large" {:name ::beer} nil]]
(r/routes router)))
(is (= true (map? (r/options router))))
(is (map? (r/options router)))
(is (= (r/map->Match
{:template "/api/ipa/large"
:data {:name ::beer}

View file

@ -12,9 +12,9 @@
(deftest route-data-validation-test
(testing "validation is turned off by default"
(is (true? (r/router?
(is (r/router?
(r/router
["/api" {:handler "identity"}])))))
["/api" {:handler "identity"}]))))
(testing "with default spec validates :name, :handler and :middleware"
(is (thrown-with-msg?
@ -40,11 +40,11 @@
{:validate rrs/validate-spec!}))))
(testing "spec can be overridden"
(is (true? (r/router?
(is (r/router?
(ring/router
["/api" {:handler "identity"}]
{:spec (s/spec any?)
:validate rrs/validate-spec!}))))
:validate rrs/validate-spec!})))
(testing "predicates are not allowed"
(is (thrown-with-msg?
@ -56,7 +56,7 @@
:validate rrs/validate-spec!})))))
(testing "middleware can contribute to specs"
(is (true? (r/router?
(is (r/router?
(ring/router
["/api" {:get {:handler identity
:roles #{:admin}}}]
@ -64,7 +64,7 @@
:data {:middleware [{:spec (s/keys :opt-un [::roles])
:wrap (fn [handler]
(fn [request]
(handler request)))}]}}))))
(handler request)))}]}})))
(is (thrown-with-msg?
ExceptionInfo
#"Invalid route data"

View file

@ -16,7 +16,7 @@
(testing "route-data"
(are [data]
(is (= true (r/router? (r/router data))))
(is (r/router? (r/router data)))
["/api" {}]
@ -45,12 +45,12 @@
["/ipa"]])))
(testing "routes conform to spec (can't spec protocol functions)"
(is (= true (s/valid? ::rs/routes (r/routes (r/router ["/ping"]))))))
(is (s/valid? ::rs/routes (r/routes (r/router ["/ping"])))))
(testing "options"
(are [opts]
(is (= true (r/router? (r/router ["/api"] opts))))
(is (r/router? (r/router ["/api"] opts)))
{:path "/"}
{:data {}}
@ -78,8 +78,8 @@
(deftest route-data-validation-test
(testing "validation is turned off by default"
(is (true? (r/router? (r/router
["/api" {:handler "identity"}])))))
(is (r/router? (r/router
["/api" {:handler "identity"}]))))
(testing "with default spec validates :name and :handler"
(is (thrown-with-msg?
@ -96,7 +96,7 @@
{:validate rs/validate-spec!}))))
(testing "spec can be overridden"
(is (true? (r/router? (r/router
(is (r/router? (r/router
["/api" {:handler "identity"}]
{:spec any?
:validate rs/validate-spec!}))))))
:validate rs/validate-spec!})))))