Fork me on GitHub
#babashka
<
2020-10-02
>
danielgrosse11:10:58

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"))))))

jeroenvandijk11:10:47

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

borkdude11:10:01

Could be pod impl related, but I think we should support that, so feel free to post an issue

borkdude11:10:56

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)

borkdude11:10:02

it prints :my-glob

borkdude11:10:21

so if you can make a repo that I can run, I'll take another look, can't repro now

danielgrosse12:10:47

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") ))

borkdude12:10:32

@U068SUJNT 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"

danielgrosse12:10:00

Okay then I have to test it again. Thanks

danielgrosse11:10:22

What did I do wrong?