Permalink
Browse files

Fixed clojurescript tests.

  • Loading branch information...
1 parent f0e22dc commit c1e892a23b8f62b680a7b6b10cb9ba1dd3a61662 @r0man committed Aug 10, 2012
View
65 README
@@ -4,43 +4,68 @@ A Clojure & ClojureScript library to build url and path fns.
## Usage
-(use 'routes.core)
+(require '[routes.core :refer :all])
+(require '[routes.params :as params])
+
+;; A server as a Ring like map.
+
+(def example-com
+ {:scheme :https :server-name "example.com" :server-port 443})
;; Define some routes.
-(def europe {:iso-3166-1-alpha-2 "eu" :name "Europe"})
+(defroute root []
+ ["/"] :server example-com)
(defroute continents []
- "/continents")
+ ["/continents"]
+ :root root-route
+ :query-params {:location params/location})
(defroute continent [continent]
- "/continents/:iso-3166-1-alpha-2-:name")
+ ["/:id-:name" params/integer params/string]
+ :root continents-route)
+
+(defroute countries []
+ ["/countries"]
+ :root root-route)
+
+(defroute country []
+ ["/:iso-3166-1-alpha-2-:name" params/iso-3166-1-alpha-2 params/string]
+ :root countries-route)
+
+(defroute countries-of-continent []
+ ["/countries"] :root continent-route)
+
+(defroute country-of-continent [country]
+ ["/:iso-3166-1-alpha-2-:name" params/iso-3166-1-alpha-2 params/string]
+ :root countries-of-continent-route)
-(defroute countries-in-continent [continent]
- "/continents/:iso-3166-1-alpha-2-:name/countries")
+;; Test data.
-;; Build paths.
+(def europe {:id 1 :name "Europe"})
+
+(def spain {:iso-3166-1-alpha-2 "es" :name "Spain"})
+
+;; Build paths and urls.
(continents-path)
;=> "/continents"
-(continent-path europe)
-;=> "/continents/eu-europe"
+(continents-url)
+;=> "https://example.com/continents"
-(countries-in-continent-path europe)
-;=> "/continents/eu-europe/countries"
-
-;; Build urls.
-(with-server {:server-name "example.com"}
+(continent-path europe)
+;=> "/continents/1-europe"
- (continents-url)
- ;=> "https://example.com/continents"
+(continent-url europe)
+;=> "https://example.com/continents/1-europe"
- (continent-url europe)
- ;=> "https://example.com/continents/eu-europe"
+(country-of-continent-path europe spain)
+;=> "/continents/1-europe/countries/es-spain"
- (countries-in-continent-url europe)
- ;=> "https://example.com/continents/eu-europe/countries"
+(country-of-continent-url europe spain)
+;=> "https://example.com/continents/1-europe/countries/es-spain"
## License
View
@@ -1,3 +1,14 @@
#!/usr/bin/env bash
-echo "routes.test.run()" | d8 --shell target/routes-test.js
-echo 'routes.test.run()' | d8 --shell target/routes-test.js
+
+JS_TESTS="target/routes-test.js"
+
+[ ! -f $JS_TESTS ] && lein cljsbuild once
+
+if [ -n "`type d8 2> /dev/null`" ] ; then
+ echo "routes.test.run()" | d8 --shell $JS_TESTS
+elif [ -n "`type v8 2> /dev/null`" ] ; then
+ echo "routes.test.run()" | v8 --shell $JS_TESTS
+else
+ echo "Can't run ClojureScript tests. Looks like V8 is not installed."
+ exit 1
+fi
@@ -139,6 +139,14 @@
(is (= continent-route (:root route)))
(is (= example (:server route)))))
+(deftest test-countries-of-continent-path
+ (is (= "/continents/1-europe/countries"
+ (countries-of-continent-path europe))))
+
+(deftest test-countries-of-continent-url
+ (is (= "https://example.com/continents/1-europe/countries"
+ (countries-of-continent-url europe))))
+
;; COUNTRY OF CONTINENT
(deftest test-country-of-continent-route
@@ -1,4 +1,4 @@
-(ns routes.test.param
+(ns routes.test.params
(:require [clojure.test :refer :all]
[routes.params :refer :all]))
@@ -1,10 +1,6 @@
(ns routes.test
- (:require [routes.test.core :as core]
- [routes.test.helper :as helper]
- [routes.test.server :as server]))
+ (:require [routes.test.core :as core]))
(defn ^:export run []
(core/test)
- (helper/test)
- (server/test)
"All tests passed.")
Oops, something went wrong.

0 comments on commit c1e892a

Please sign in to comment.