Good Morning!
Mornin' π:skin-tone-2:
All good over the pond?
Aside from the firestorm burning up California and the out-of-control pandemic, yeah, I guess π
Roll on November 3rd. Although we likely won't know the final result for days. Maybe weeks. Argh!
Oh, I'm thinking it's going to be depressing news - no matter who wins - there's a'trouble brewing methinks.
Β‘mawningΒ‘
Morning :)
morning
mogge
Morning
Hey folks, I started a new contract on Monday (back in Java land for a bit), but a recruiter I have been working with has just sent me a spec for a company looking to hire some Clojure permies. I hope I am not out of line mentioning it in here (I know there is a #jobs), but I do seem to remember a few people mentioning that they were currently on the lookout. Ping me with a DM if anybody wants an intro. Cheers.
I should mention, I wont be asking for or taking any referral fees for this, just thought I would ask in case it helps anybody out.
Morn'
Hi all, the recording of the following event is now available online: William Parker - Logic programming with clara-rules @ LNDCLJ https://youtu.be/aJbdTP5hL0U
Thanks again for organising it @bruno.bonacci π... The talk was interesting!
π
I have discovered with-redefs
Undiscover it
It's useless
oh
seems to do what I want, in a test, I can "mock" out a function that calls to an external API
what would you suggest otherwise?
Write your functions to take the result of the external API directly.
I do
But at some point, you have to invoke something
there is an side effect somewhere
Not necessarily, you will have an orchestrating function that does this:
(-> (call-external-service) a b c)
And your test will do this:
(-> some-map a b c)
Instead of writing code like this:
(defn A [] (println "A") (B))
(defn B [] (println "B"))
Write this:
(defn A [] (println "A"))
(defn B [] (println "B"))
(do (A) (B))
Finally, if you really must do the side effect thing, use a protocol to mock the external service and pass it around. It'll cause you way less headaches, promise. e.g. if you ever turn on parallel tests in eftest.
My function is very simple, I'll have to think how it can be rewritten, i.e.,
(defn filter-for-valid-agreement
[policies to app-config]
(first (filter #(ac/query-for-associations (:agreementId %) to app-config) policies)))
the ac/query-for-associations
does a API lookup and returns a map or nil if an assocation is found.
so I redef'ed ac/query-for-associations
to return data that I'm interested in during my test.
and tested the filter-for-valid-agreement
function
What property are you trying to test?
I wouldn't think it too useful to test given how simple it is :)
it's important to behave the way I expect, i.e., either return the first of policy (that has an associations) or a nil result
a bug was discovered today that didn't take that into account, so I wrote a test specifically for that.
https://cognitect.com/blog/2016/9/15/works-on-my-machine-understanding-var-bindings-and-roots I remember this being more scolding, but it doesn't seem to be now. But yeah, with-redefs is hard.
I'll keep that in mind and see if I can also take into account your suggestions too π
All very helpful
btw, i've updated my startrek projects, using aero and clip to be all the latest
I do like me some clip - it should be promoted more!
https://old.reddit.com/r/Clojure/comments/ble9k4/dont_use_a_protocol_to_make_testing_easier/emo5cjl/ scalding :D
Welp *scolding. Never typed this before. I assumed it was the same word.
So yeah, use protocols if you're testing stateful functions. Try to pass the results of stateful functions around though instead. Avoid with-redefs always.
Will review and try π
Thanks once again! π
> I do like me some clip - it should be promoted more! Promotion is not something I really know how to do :). Happy users go a long way though.
I'm happy π