Fork me on GitHub

Hello. I can't seem to make stest/instrument's :stub option work. Is that a known limitation by any chance? Can't see any related JIRA tickets.


I've tried a simple test case and also the example given in the spec guide under 'Combining check and instrument'. Seems like the :stub fn is ignored.


This should reproduce what I see (all three invocations return same number but we expect the second number to be a random int)

(defn add2 [a b] 1.1)
(s/fdef add2 :args (s/cat :a int? :b int?) :ret int?)
(println ::a (add2 1 2))
(stest/instrument `add2 {:stub #{`add2}})
(println ::b (add2 1 2))
(stest/unstrument `add2)
(println ::c (add2 1 2))


Code works as expected from clojure repl.


If anybody has ideas on how to conditionally require the crypto API on node please comment! I've looked into it a bit and a try require crypto catch approach would work, but could unintentionally include the module when in a build environment targeting the browser and incorporating commonjs or can't that happen?


Also, for the latter case, we maybe could do some additional checks on window being bound and window being bound to the same object in a closure, but that's not ideal either..


@olivergeorge what is :stub supposed to do. Could probably be made to work, but I’m pretty sure it isn’t currently supported


@abp heya, I will look at it when I have time, it’s a pretty low priority ticket


oh sry, I meant to say I added a new patch again, which could be more efficient than the last one. Now the question is how I can Benchmark the different implementations (maybe on multiple browsers), if needed. Also I could do a proposal on conditional node require if you think it's worth a try. Also no problem, take your time, no one else even has looked into the new patches to catch mistakes, I think.


@dnolen stub should replace the function with a generator (using the :ret spec to generate results).


My use case was isolating a function so side effecting calls were stubbed before running stest/check


There's a section in the Spec Guide covering called "Combining check and instrument" which describes it along with a worked example.


Would you like me to raise a JIRA issue?


Pretty sure the problem is (some #{sym} stub) not matching inside cljs.spec.test.alpha/instrument-choose-fn. How symbols are managed isn't immediately clear but that's my guess at the cause. The stub arg looks like I expect (e.g. #{cljs.spec.test-test/add2}) but the sym arg looks like #object[B0] via nashorn. So no surprise the if statement doesn't do what we expect.


I'll log a ticket and add a patch including a test which fails.


I think the :replace feature has a problem stemming from the same underlying problem. I think resolving stubbing will fix replacing.