Howdy,
I asked this on #clojure and posted a question on Stackoverflow
(
http://stackoverflow.com/questions/4424220/how-do-i-rebind-a-var-in-a-
lazytest-describe-test), but no dice. I'm assuming that it's because
this is so simple and I'm doing it so incorrectly that nobody can even
begin to formulate a response. Feel free to tell me to go back and re-
R all TFMs ;)
First of all, sorry if I am screwing up some terminology; I'm pretty
new to Clojure. I am trying to write a very simple test using Lazytest
that depends on a var binding. I can not seem to rebind a var in the
test file and have the code under test use that binding.
Here is the code I am trying to test:
(ns liar-liar.core
(:gen-class))
(def *input-file-name*)
(defn parse-input
"Just print return a var for now..."
[]
*input-file-name*)
(defn -main [& args]
(binding [*input-file-name* (first args)]
(println (parse-input))))
And here is the test:
(ns liar-liar.test.core
(:use lazytest.describe)
(:use liar-liar.core))
(binding [*input-file-name* "my-input-file"]
(describe parse-input "Just returns a var"
(it "returns a var"
(= "my-input-file" (parse-input)))))
When I try to run this test, I get this error:
java.lang.IllegalStateException: Var liar-liar.core/*input-file-name*
is unbound.
Interestingly enough, if I move the binding form:
(ns liar-liar.test.core
(:use lazytest.describe)
(:use liar-liar.core))
(describe parse-input "Just returns a var"
(it "returns a var"
(binding [*input-file-name* "my-input-file"]
(= "FAIL" (parse-input)))))
The test works as it should, but the reporting isn't ideal, as it
doesn't print the value of the (parse-input) expression (the test
passes if I replace "FAIL" with "my-input-file" though):
FAILURE: Namespaces liar-liar.test.core #'liar-liar.core/parse-input
Just returns a var returns a var
at liar_liar/test/core.clj line 7
Expression: (binding [*input-file-name* my-input-file] (= FAIL (parse-
input)))
Result: false
Local bindings:
{}
Is there some other way I should be going about doing this kind of
testing?
Thanks! Dan