babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
danielgrosse 2020-10-02T11:01:58.266300Z

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

danielgrosse 2020-10-02T11:03:22.266800Z

What did I do wrong?

2020-10-02T11:13:47.267100Z

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

borkdude 2020-10-02T11:16:01.267300Z

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

borkdude 2020-10-02T11:16:25.267500Z

in this repo: https://github.com/babashka/babashka.pods

borkdude 2020-10-02T11:18:56.268Z

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)

borkdude 2020-10-02T11:19:02.268200Z

it prints :my-glob

borkdude 2020-10-02T11:38:21.268400Z

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

borkdude 2020-10-02T12:16:35.268600Z

@danielgrosse ^

danielgrosse 2020-10-02T12:18:47.268900Z

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

borkdude 2020-10-02T12:32:32.269100Z

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

danielgrosse 2020-10-02T12:47:00.269300Z

Okay then I have to test it again. Thanks