Skip to content

Commit

Permalink
update to use new test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
duck1123 committed Mar 8, 2012
1 parent 68308c1 commit 6203657
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 98 deletions.
19 changes: 19 additions & 0 deletions ciste-core/src/ciste/test_helper.clj
@@ -0,0 +1,19 @@
(ns ciste.test-helper
(:use (ciste [config :only [load-config with-environment]]
[triggers :only [*thread-pool*]])
midje.sweet))

(defmacro test-environment-fixture
"Wrapper to ensure tests are run in the test environment"
[& body]
`(do
(println " ")
(println "****************************************************************************")
(println (str "Testing " *ns*))
(println "****************************************************************************")
(println " ")
(load-config)

(with-environment :test
~@body
(.shutdown @*thread-pool*))))
48 changes: 24 additions & 24 deletions ciste-core/test/ciste/config_test.clj
Expand Up @@ -3,30 +3,30 @@
ciste.test-helper
midje.sweet))

(test-environment-fixture)
(test-environment-fixture

(fact "get-host-name"
(fact "should return a string"
(get-host-name) => string?))

(fact "get-host-name"
(fact "should return a string"
(get-host-name) => string?))
(fact "get-host-address"
(fact "should return a string"
(get-host-address) => string?))

(fact "get-host-address"
(fact "should return a string"
(get-host-address) => string?))
(fact "environment"
(environment) => :test)

(fact "environment"
(environment) => :test)

(fact "merge-config"
(let [m1 {:key1 "value1"
:key2 {:sub-key1 "value2"
:sub-key2 "value3"}}
m2 {:key2 {:sub-key2 "value4"
:sub-key3 "value5"}
:key3 "value6"}
result (merge-config m1 m2)]
result => (contains {:key1 "value1"})
result => (contains {:key3 "value6"})
(let [key2 (:key2 result)]
key2 => (contains {:sub-key1 "value2"})
key2 => (contains {:sub-key2 "value4"})
key2 => (contains {:sub-key3 "value5"}))))
(fact "merge-config"
(let [m1 {:key1 "value1"
:key2 {:sub-key1 "value2"
:sub-key2 "value3"}}
m2 {:key2 {:sub-key2 "value4"
:sub-key3 "value5"}
:key3 "value6"}
result (merge-config m1 m2)]
result => (contains {:key1 "value1"})
result => (contains {:key3 "value6"})
(let [key2 (:key2 result)]
key2 => (contains {:sub-key1 "value2"})
key2 => (contains {:sub-key2 "value4"})
key2 => (contains {:sub-key3 "value5"})))))
34 changes: 17 additions & 17 deletions ciste-core/test/ciste/core_test.clj
Expand Up @@ -3,24 +3,24 @@
ciste.test-helper
midje.sweet))

(test-environment-fixture)
(test-environment-fixture

(fact "with-serialization"
*serialization* => nil
(with-serialization :http
*serialization* => :http)
*serialization* => nil)
(fact "with-serialization"
*serialization* => nil
(with-serialization :http
*serialization* => :http)
*serialization* => nil)

(fact "with-format"
*format* => nil
(with-format :html
*format* => :html)
*format* => nil)
(fact "with-format"
*format* => nil
(with-format :html
*format* => :html)
*format* => nil)

(fact "#'defaction"
(fact "should define the var"
(defaction foo
[]
true)
(fact "#'defaction"
(fact "should define the var"
(defaction foo
[]
true)

(foo) => true))
(foo) => true)))
11 changes: 7 additions & 4 deletions ciste-core/test/ciste/predicates_test.clj
@@ -1,7 +1,10 @@
(ns ciste.predicates-test
(:use ciste.predicates
(:use (ciste [test-helper :only [test-environment-fixture]])
ciste.predicates
midje.sweet))

(fact "name-matches?"
(name-matches?
{:name "foo"} {:name "foo"}) => (contains {:name "foo"}))
(test-environment-fixture

(fact "name-matches?"
(name-matches?
{:name "foo"} {:name "foo"}) => (contains {:name "foo"})))
68 changes: 34 additions & 34 deletions ciste-core/test/ciste/routes_test.clj
Expand Up @@ -2,39 +2,39 @@
(:use (ciste test-helper routes)
midje.sweet))

(test-environment-fixture)
(test-environment-fixture

(fact "when the predicate is a function"
(fact "should apply that function"
(fact "when the predicate is a function"
(fact "should apply that function"

(let [invoked? (ref false)
request {:method :get :path "/"}
matcher {:method :get :path "/"}
predicate (fn [request matcher]
(dosync (ref-set invoked? true))
request)]
(try-predicate request matcher predicate)
@invoked? => truthy)))
(fact "when the predicate is a sequence"
(fact "and the first predicate fails"
(fact "should not invoke the second"
(let [invoked? (ref false)
request {:method :get :path "/"}
matcher {:method :get :path "/"}
first-pred (fn [request matcher] nil)
second-pred (fn [request matcher]
(dosync (ref-set invoked? true))
request)
predicate [first-pred second-pred]]
(try-predicate request matcher predicate)
@invoked? => falsey))))
(fact "when the first predicate returns a request"
(fact "should pass that result to the next predicate"
(let [request {:method :get :path "/"}
request2 {:method :get :path "/foo"}
matcher {:method :get :path "/"}]
(letfn [(first-pred [_ _] request2)
(second-pred [r _] r)]
(let [predicate [first-pred second-pred]
response (try-predicate request matcher first-pred)]
response => request2)))))
(let [invoked? (ref false)
request {:method :get :path "/"}
matcher {:method :get :path "/"}
predicate (fn [request matcher]
(dosync (ref-set invoked? true))
request)]
(try-predicate request matcher predicate)
@invoked? => truthy)))
(fact "when the predicate is a sequence"
(fact "and the first predicate fails"
(fact "should not invoke the second"
(let [invoked? (ref false)
request {:method :get :path "/"}
matcher {:method :get :path "/"}
first-pred (fn [request matcher] nil)
second-pred (fn [request matcher]
(dosync (ref-set invoked? true))
request)
predicate [first-pred second-pred]]
(try-predicate request matcher predicate)
@invoked? => falsey))))
(fact "when the first predicate returns a request"
(fact "should pass that result to the next predicate"
(let [request {:method :get :path "/"}
request2 {:method :get :path "/foo"}
matcher {:method :get :path "/"}]
(letfn [(first-pred [_ _] request2)
(second-pred [r _] r)]
(let [predicate [first-pred second-pred]
response (try-predicate request matcher first-pred)]
response => request2))))))
16 changes: 8 additions & 8 deletions ciste-core/test/ciste/sections_test.clj
Expand Up @@ -3,13 +3,13 @@
ciste.test-helper
midje.sweet))

(test-environment-fixture)

(defrecord User [])

(fact "record-class-serialization"
(fact "should return the parameters in order"
(let [record (User.)
format :html
serialization :http]
(record-class-serialization record format serialization) => [User :html :http])))
(test-environment-fixture

(fact "record-class-serialization"
(fact "should return the parameters in order"
(let [record (User.)
format :html
serialization :http]
(record-class-serialization record format serialization) => [User :html :http]))))
11 changes: 0 additions & 11 deletions ciste-core/test/ciste/test_helper.clj

This file was deleted.

0 comments on commit 6203657

Please sign in to comment.