I'm writing tests for a Clojure app using Speclj. I'm accustomed in BDD to do things like this:
context "some context"
stub my-function :return true
it "has behavior one"
should true my-function
it "has behavior two"
should_not false my-function
But in Speclj I can't seem to find an example of how to share the stub across the characteristics, so I'm currently stuck writing code like this:
(describe "this"
(context "that"
(it "accepts nil"
(with-redefs [called-fn (constantly nil)]
(should= nil (my-fn nil)))))
(it "accepts 1"
(with-redefs [called-fn (constantly nil)]
(should= 100 (my-fn 1))))))
(I realize this is a somewhat contrived example and arguably those assertions could all go under one characteristic, but let's suppose for now that I have good reason to write the code like this.)
I want, however, to just have to stub called-fn
once, but moving this up out of the it
s raises errors because the real called-fn
gets called instead of my redef.
Is there a way to reuse redefs (or use Speclj stubs) in Speclj so I'm not stuck pushing them all down inside the characteristics?
Gordan,
You can use the ‘around’ component to remove the duplication. See below.
Micah
(describe “this & that” (around [it] (with-redefs [called-fn (constantly nil)] (it))) (it "accepts nil" (should= nil (my-fn nil))) (it "accepts 1" (should= 100 (my-fn 1))))
--
You received this message because you are subscribed to the Google Groups "speclj" group.
To unsubscribe from this group and stop receiving emails from it, send an email to speclj+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.