Skip the rest of checks in a "facts" block in case of a failure/exception

19 views
Skip to first unread message

Alex

unread,
Apr 24, 2016, 6:51:43 PM4/24/16
to Midje
I'd like to use Midje for intergration tests.
(I like it's error-reporting and slick API VS what standard clojure.test offers).

I am looking for a way to stop execution of facts in a "facts" block,
if any of (preceeding) facts within that "facts" block fails or there was an exception.

Q: How do I do this in Midje?

Here is a typical scenario:

(facts "...some API tests"
   
; ensure that there are no users
   
(for [id [1 2 3 4 5]] (api/get-user id)) => [nil nil nil nil nil]


   
; ^^^ if the above check fails, there is no reason to continue with the rest
   
; the rest of checks in this "facts" block should not be executed


   
; create 5 users
   
(for [id [1 2 3 4 5]] (api/create-user id))


   
; ^^^ same thing, if the above check fails due to an exception,
   
; the rest of checkers in this "facts" block should not be executed
   
; (but the next "facts" block outside should


   
; load 5 users
   
(map :id (for [id [1 2 3 4 5]] (api/get-user id))) => [1 2 3 4 5] )



Currently, the code above will run all "=>" checks, regardless if a preceding check fails (I'd like to skip the rest of checks within this "facts" block).
Also, if there is an exception, the the whole test procedure stops (I'd like it to continue with the next "facts" block instead).

ChrisCruft

unread,
May 25, 2016, 11:48:47 AM5/25/16
to Midje
Checking for side effects always seems a bit clunky (not just in midje).   And taking actions based on the outcomes of those side effects is even less mainstream for testing libraries.

Nevertheless, I think you can reasonably couch your problem in midje.  Here's what I would do:  the first checker seems to be less of a check and more of an assertion about the resting state of the user store.  That should be managed in a background/against-background wrapper.  Failures there *will* stop the whole fact block.  For that matter, given that no check is performed on the create-user call, that too should be in the background.
Reply all
Reply to author
Forward
0 new messages