Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update of atticus for clojure 1.3 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<modelVersion>4.0.0</modelVersion>
<groupId>atticus</groupId>
<artifactId>atticus</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.1.1-ANNADALE</version>
<name>Atticus mock and test helpers</name>
<description>Mocking library and test helpers</description>
<url>http://github.com/hugoduncan/atticus</url>
<url>http://github.com/m-dec/atticus</url>
<build>
<resources>
<resource>
Expand Down Expand Up @@ -62,17 +62,22 @@
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
</dependency>
<!--dependency>
<groupId>com.github.slingshot</groupId>
<artifactId>slingshot</artifactId>
<version>0.8.1</version>
</dependency-->
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure-contrib</artifactId>
<version>1.2.0</version>
<artifactId>tools.logging</artifactId>
<version>0.2.3</version>
</dependency>
<dependency>
<groupId>swank-clojure</groupId>
<artifactId>swank-clojure</artifactId>
<version>1.2.1</version>
<version>1.3.0</version>
<optional>true</optional>
</dependency>
</dependencies>
Expand Down
6 changes: 3 additions & 3 deletions src/main/clojure/atticus/mock.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ lambda.
"
(:use clojure.test))

(def *expectations*)
(def ^:dynamic *expectations*)

(defn equality-checker
[actual expected msg]
(is (= actual expected) msg))

(def *equality-checker* equality-checker)
(def ^:dynamic *equality-checker* equality-checker)

(defn verify-expectations
[checks]
Expand Down Expand Up @@ -123,7 +123,7 @@ lambda.
"Binds a list of mocks, checling any expectations on exit of the block."
[mocks & body]
`(with-expectations
(binding ~(construct-bindings mocks)
(with-redefs ~(construct-bindings mocks)
(let ~(construct-protocol-bindings mocks)
~@body))
(verify-expectations *expectations*)))
2 changes: 1 addition & 1 deletion src/main/clojure/atticus/utils.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns atticus.utils
(:require
[clojure.contrib.logging :as logging])
[clojure.tools.logging :as logging])
(:use clojure.test))

(defmacro with-private-vars [[ns fns] & tests]
Expand Down
21 changes: 11 additions & 10 deletions src/test/clojure/atticus/mock_test.clj
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
(ns atticus.mock-test
(:use atticus.mock :reload-all)
(:use clojure.test)
(:require
[clojure.contrib.condition :as condition]))
(:use clojure.test))

;;; unmaintained condition lib removed here
;;; considering slingshot or simply (is (thrown-with-msg? ...))

(deftest verify-expectations-test
(is (thrown?
clojure.contrib.condition.Condition
(verify-expectations [(fn [] (condition/raise :error 1))])))
Exception
(verify-expectations [(fn [] (throw (Exception. "error 1")))])))
(is (nil?
(verify-expectations [(fn [] true)]))))

(defn equality-condition
[a b msg]
(when-not (= a b)
(condition/raise :message msg)))
(throw (Exception. msg))))

(deftest add-expectation-test
(with-expectations
Expand All @@ -26,14 +27,14 @@
(with-expectations
(let [f (once v1 [] (once 1))]
(is (thrown?
clojure.contrib.condition.Condition
Exception
((first *expectations*))))
(is (= 1 (f)))
(is (nil? ((first *expectations*))))))
(with-expectations
(let [f (once v1 [x] (once (inc x)))]
(is (thrown?
clojure.contrib.condition.Condition
Exception
((first *expectations*))))
(is (= 1 (f 0)))
(is (nil? ((first *expectations*))))))))
Expand All @@ -43,15 +44,15 @@
(with-expectations
(let [f (times v1 [x] (times 2 (inc x)))]
(is (thrown?
clojure.contrib.condition.Condition
Exception
((first *expectations*))))
(is (= 1 (f 0)))
(is (= 2 (f 1)))
(is (nil? ((first *expectations*))))))
(with-expectations
(let [f (times v1 [x] (times 2 (inc x)))]
(is (thrown?
clojure.contrib.condition.Condition
Exception
((first *expectations*))))
(is (= 1 (f 0)))
(is (= 2 (f 1)))
Expand Down
7 changes: 3 additions & 4 deletions src/test/clojure/atticus/utils_test.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
(ns atticus.utils-test
(:use atticus.utils :reload-all)
(:use clojure.test)
(:require
[clojure.contrib.condition :as condition]))
(:use clojure.test))


(deftest tmpfile-test
(let [t (tmpfile)]
Expand All @@ -16,7 +15,7 @@
(.delete t)))


(def *fn*)
(def ^:dynamic *fn*)

(deftest with-temporary-file-test
(binding [*fn* nil]
Expand Down