Code re-use in Speclj

109 views
Skip to first unread message

Karsten Schmidt

unread,
Feb 3, 2014, 5:53:12 PM2/3/14
to clo...@googlegroups.com
Hi,

I've been getting quite excited about integrating Speclj via its
auto-runner into my mixed CLJ/CLJS Org-mode/Babel setup, but now
feeling a bit lost how to go about wrapping a number of test
characteristics ("(it)" forms in speclj parlance) into re-usable
units. In the assertions below I'd like to parameterize the "+" calls
(i.e.. replace with other math ops), but the docs are pretty
slim/non-existent about how one could form modules/groups of such
parameterized tests. It doesn't seem to be possible to just wrap those
within a function:

(describe "blah"
(with a2 (vec2 1 2))
(with b2 (vec2 10 20))

;; FIXME how to group these as unit?
(it "a2 n m" (should= (+ @a2 @b2) (+ @a2 10 20)))
(it "a2 b2 m" (should= (+ (+ @a2 @b2) 20) (+ @a2 @b2 20)))
(it "a2 b2 b2" (should= (+ (+ @a2 @b2) @b2) (+ @a2 @b2 @b2)))
(it "a2 n b2" (should= (+ (+ @a2 10) @b2) (+ @a2 10 @b2))))

Any pointers please? Is it even possible? If not, isn't this a fairly
common use case?

Thanks!

Glen Mailer

unread,
Feb 3, 2014, 6:51:56 PM2/3/14
to clo...@googlegroups.com
My usual approach is to use a macro that expands to the appropriate (it) forms, or have a helper function that is called inside each (it)

da...@dsargeant.com

unread,
Feb 4, 2014, 11:11:25 PM2/4/14
to clo...@googlegroups.com
"context" might be what you're looking for.

da...@dsargeant.com

unread,
Feb 4, 2014, 11:14:08 PM2/4/14
to clo...@googlegroups.com
You can also use let instead of with. If you have multiple tests inside let wrap them in a context call.
Reply all
Reply to author
Forward
0 new messages