[英]Clojure Speclj with-redefs and a stub from a different thread
我正在測試一個函數,以確保它調用另一個名稱空間中的函數。 我想將函數存根(使用speclj stub ),這樣我就可以記錄調用。
(defn fn-under-test []
(p/helper-fn))
(describe "test"
(with-stubs)
(around [it]
(with-redefs [p/helper-fn (stub :helper)]
(it)))
(it "should call the helper-fn"
(fn-under-test)
(should-have-invoked :helper {:times 1})))
我有一個例外:
java.lang.Exception: Stub recoding not bound. Please add (with-stubs) to the decribe/context.
如果在當前名稱空間中定義了helper-fn
,則一切都會按預期進行。 如何使用speclj在另一個命名空間中添加函數?
編輯:從另一個線程調用存根函數時,會發生異常。 我創建了一個拉取請求來解決此問題。
我為您的示例編寫了代碼,規范運行良好; 順利通過。 我想不出將fns存入另一個命名空間的原因是行不通的。 我一直都在做。
這是展示我工作的要點: https : //gist.github.com/slagyr/2aed1ccfd8ec702d7051
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.