This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-26
Channels
- # announcements (1)
- # babashka (106)
- # beginners (11)
- # biff (7)
- # calva (16)
- # clj-kondo (40)
- # clj-on-windows (5)
- # clj-yaml (10)
- # clojars (4)
- # clojure (37)
- # clojure-austin (22)
- # clojure-australia (1)
- # clojure-europe (40)
- # clojure-nl (1)
- # clojure-norway (10)
- # clojure-spec (6)
- # clojure-uk (6)
- # clojurescript (13)
- # conjure (11)
- # cursive (14)
- # datalevin (8)
- # datascript (5)
- # emacs (39)
- # events (1)
- # fulcro (55)
- # gratitude (4)
- # holy-lambda (2)
- # humbleui (9)
- # instaparse (1)
- # lsp (3)
- # malli (12)
- # meander (2)
- # membrane (7)
- # nbb (1)
- # off-topic (16)
- # pathom (9)
- # releases (3)
- # sci (14)
- # shadow-cljs (25)
Hi Team, In Clojure test, How do we assert for an Error thrown during insertion of a duplicate record, e.g. org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "unique_constraint_name"
two straightforward ways:
• check out (doc clojure.test/is)
. It has a way to assert exceptions are thrown:
> (is (thrown-with-msg? c re body)) checks that an instance of c is
> thrown AND that the message on the exception matches (with
> re-find) the regular expression re.
• Another way is to just (let [e (try (insert! record) (catch Exception e … )
and just have the exception as a value in your test. You can do whatever you want with it
In the https://clojure.github.io/clojure/clojure.test-api.htmlhttps://clojure.github.io/clojure/clojure.test-api.html it is also explained how to test exceptions the way @U11BV7MTK describes.
Hey! Suppose I wanna write a macro to call a Java object method, by specifying the object and the method.
(defmacro java-call [method object]
`(. ~object ~method))
Now I'd like to write a helper function that would pin the object, something like this:
(defn java-call-on [method]
(java-call method defined-somewhere-else))
But I can't really get how do I do that, since the parameter passed to the function will be evaluated, and I can't seem to find a way to retrieve a symbol for a method of a given instance. Is this possible at all?Just learned something while reading the reitit code base:
(-> result method :handler (or default-handler))
Never thought about using (or) in a threaded macro to handle fallback values.
Feels very idiomatic. I think I will overuse this going forward. 😄(-> result method (doto (prn)) :handler (or default-handler))
into this stack of threading macro tips 🙂
add debug logging without changing threading macro result