test-is: is called? [PATCH]

4 views
Skip to first unread message

Allen Rohner

unread,
Jan 6, 2009, 11:06:56 PM1/6/09
to Clojure
I had to revisit my test stubbing/expectation code after the recent
changes to test-is. The good news is, because of the excellent change
to make "is" a multi-method, the expectation code easily fits into
test-is. The following patch adds a new assertion for is, (is
(called?))

;; creates a stub function, binds it to an existing var and asserts
;; the stub fn was called the correct number of times.

(is (called? [[user/foo :times 2 :returns 42]
[user/bar :times 1 :returns 3]]
(user/foo x y z)
(user/bar z)))

Inside of the called? block, user/foo and user/bar are rebound to stub
functions, and then asserts that each function is called the proper
number of times. Currently, the only two options an expectation takes
are :times and :returns. I expect that more will be needed.

http://groups.google.com/group/clojure/web/test_is_called.patch

Allen

Stuart Sierra

unread,
Jan 8, 2009, 11:27:31 AM1/8/09
to Clojure
Nice work, Allen. I want to add stubs/mocks to test-is. One question
-- would it work without Var.pushThreadBindings, maybe using a
combination of "with-local-vars" and "binding"?

I was also thinking of modifying "report" to throw AssertionError,
like your "throwing-report", so that I can get a stack trace for where
the error occurred.

-Stuart Sierra

Allen Rohner

unread,
Jan 8, 2009, 12:27:29 PM1/8/09
to Clojure


On Jan 8, 10:27 am, Stuart Sierra <the.stuart.sie...@gmail.com> wrote:
> Nice work, Allen.  I want to add stubs/mocks to test-is.  One question
> -- would it work without Var.pushThreadBindings, maybe using a
> combination of "with-local-vars" and "binding"?
>

It should be possible to make that work with binding. I did it that
way because I was having problems making the call to binding work
inside the macro. If someone with more macro-fu than I would like to
look at it, I would love to see how it could be improved.

Allen

Allen Rohner

unread,
Feb 5, 2009, 11:43:16 PM2/5/09
to Clojure
I noticed this hasn't been merged in. It's starting to cause some
inconvenience to me because I have tests in my project that depend on
the called? patch. If this still needs work before it's acceptable,
let me know and I'll work on it.

In the mean time, I'll create a fork on github that contains my patch.

Allen
Reply all
Reply to author
Forward
0 new messages