Re: [midje] Verify slingshot.ExceptionInfo type in throws checker

221 views
Skip to first unread message

Alex Baranosky

unread,
Jul 17, 2012, 10:53:39 AM7/17/12
to mi...@googlegroups.com
Hi Erik,

You can check the exception against any predicate.

So in this case:

```clj
(fact "create accepts custom validator"
  (create :test {:key "value"} (validation-set (presence-of :foo))) => (throws slingshot.ExceptionInfo
        #(= ::mongo-exception (:type %))))
```

Enjoy!

Erik Bakstad

unread,
Jul 17, 2012, 1:03:08 PM7/17/12
to mi...@googlegroups.com
Thanks a lot, that pointed me in the right direction.

The following worked for me, please let me know if I'm making this harder than I have to :)

(defn is-type? [type]
  (fn [exception] (= type (get-in (.getData exception) [:object :type]))))

(fact "create accepts custom validator"
  (create :test {:key "value"} (validation-set (presence-of :foo))) => (throws slingshot.ExceptionInfo (is-type? :my.project/expected-type)))

Alex Baranosky

unread,
Jul 17, 2012, 11:34:43 PM7/17/12
to mi...@googlegroups.com
That looks about right. Glad I could be of help.
Reply all
Reply to author
Forward
0 new messages