I trying to use clojure.contrib.mock. It says to override the function
report-problem to
integrate it into other test framework like clojure.test.
I've got this working, but the namespace switching looks a bit ugly.
Is there a better
way to handle this? Maybe something like
(ns clojure.contrib.mock
(defn... the override)
)
which avoids the extra code to switch back to the original namespace?
(ns apfloattest
(:use
apfloat
clojure.test
clojure.contrib.mock))
(ns clojure.contrib.mock
(:use
clojure.test))
; delegate mock reporting to clojure.test
(defn report-problem
([function expected actual message]
(is (= expected actual)
(str message " Function name: " function))))
(ns apfloattest)
(deftest test-sqrtf
(expect [apf (times 1 (returns (apf 5)))] (sqrtf 5)))
--
Martin
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
>
--
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?
user=> (ns foo)
nil
foo=> (defn bar [x] (inc x))
#'foo/bar
foo=> (ns user)
nil
user=> (foo/bar 5)
6
user=> (with-bindings {#'foo/bar #(dec %)} (foo/bar 5))
4
On 20 Mrz., 00:34, Kevin Downey <redc...@gmail.com> wrote:
> why are you def'ing your functions in the mock namespace? why are you
> juggling namespaces at all?
Because clojure.contrib.mock says so. The only way that worked for me
was switching the namespace. Without switching the namespace I get:
Name conflict, can't def report-problem because namespace: apfloattest
refers to:#'clojure.contrib.mock/report-problem
I'm not sure why you ask me why I'm using a bad solution when I'm
asking for a better one.. ;-))
--
Martin
yes, better than my solution. :) Wrapping the with-bindings around
the run-tests I can drop the namespace switch.
(with-bindings {#'clojure.contrib.mock/report-problem #'my-report-
problem}
(run-tests))
The only issue left is that when running the test with leiningen
("lein test") I don't have control of the run-tests call.
Oh, I just tried this one:
(with-bindings {#'clojure.contrib.mock/report-problem #'my-report-
problem}
(deftest test-sqrtf
(expect [apf (times 2 (returns (apf 5)))] (sqrtf 5)))
(run-tests) )
which works too. So I can simply wrap all my deftest's inside the with-
binding which also works when running the tests with "lein
test" (removing the run-tests to avoid running the test twice).
Thanks!
--
Martin