I have a question, kinda related to Babashka, but also to Clojure in common.
In my namespace I use the bootleg pod and the glob
namespace to parse a directory. Now I tried with refdef to mock the namespace, but the function isn't called.
(ns static-website.core-test
(:require [babashka.pods :as pods]
[clojure.test :refer [deftest testing is]]
[static-website.core :as sw]
))
(pods/load-pod "bootleg")
(require '[pod.retrogradeorbit.bootleg.glob :refer [glob]])
(deftest path->glob
(testing "correct parsing of a path"
(with-redefs [glob (fn [path] [(str path "file1.yaml" )])]
(is (= ["resource/file1.yaml"] (sw/path->glob "resource"))))))
What did I do wrong?
Where is glob
being called? The one you redefine is probably not the same as the one you call indirectly. I’m guessing this would be because of the nature of how pods work
Could be pod impl related, but I think we should support that, so feel free to post an issue
in this repo: https://github.com/babashka/babashka.pods
Hmm, this does seem to work:
(ns static-website.core-test
(:require [babashka.pods :as pods]
[clojure.test :as t :refer [deftest testing is]]))
(pods/load-pod "bootleg")
(require '[pod.retrogradeorbit.bootleg.glob :refer [glob]])
(deftest path->glob
(testing "correct parsing of a path"
(with-redefs [glob (fn [path] :my-glob)]
(prn (glob 1)))))
(path->glob)
it prints :my-glob
so if you can make a repo that I can run, I'll take another look, can't repro now
The function to test is implemented as this:
(ns static-website.core
(:require [babashka.pods :as pods]))
(pods/load-pod "bootleg")
(require '[pod.retrogradeorbit.bootleg.glob :refer [glob]])
(defn path->glob
""
[path]
(glob (str path "/data/*.yaml") ))
@danielgrosse seems to work:
(ns static-website.core-test
(:require [babashka.pods :as pods]))
(pods/load-pod "bootleg")
(require '[pod.retrogradeorbit.bootleg.glob :refer [glob]])
(defn path->glob
""
[path]
(glob (str path "/data/*.yaml") ))
(with-redefs [glob (fn [x] (str "my-glob/" x))]
(path->glob "my-path"))
"my-glob/my-path/data/*.yaml"
Okay then I have to test it again. Thanks