I'm trying to stub the RabbitMQ interactions, as those aren't really the main purpose of the application I'm writing.
So, I've tried rebinding the langohr functions in my tests like so:
(defn stub [ch]
(langohr.basic/ack ch 1))
(deftest test-stub
(with-redefs [langohr.basic/ack (fn [a1 a2] true)]
(is (= true (stub "dummy")))))
When I run the test with lein test
, I get a
java.lang.ClassCastException:
redwood.env_test$fn__2210$fn__2211 cannot be cast to clojure.lang.IFn$OLO
I've been trying several other ways including different test frameworks to redefine or rebind the langohr lib functions with no progress.
I've tested other scenarios and I've successfully stubbed cheshire (json parsing clojure lib) functions with the above code structure. I humbly request assistance in understanding why my langohr stubs aren't working and for tips on how I can do this in an elegant manner.
The ClassCastException occurs because langohr.basic/ack is a function that takes a primitive argument - specifically, it is of type clojure.lang.IFn$OLO, where the OLO stands for "object, long, object".
You have to redef it be of the same type. Try this:
(with-redefs [langohr.basic/ack (fn [a1 ^long a2] true)] ...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With