Fork me on GitHub
#practicalli
<
2021-09-17
>
paulspencerwilliams04:09:21

So I’m progressing through the video internalising non Evil keyboard shortcuts and differences with Spacemacs which is helping me learn so much about vanilla Emacs. Thanks again for this excellent resource. One further question… Further on, you seem to be able to use *n* within testing blocks, but your first passing test fails for me. If I change *n* to the test namespace symbol it works okay? Is this a cider configuration you’ve applied - is it cider-test-infer-test-ns?

2
practicalli-johnny09:09:55

*ns* is a dynamic variable that should evaluate to the current namespace. I dont recall adding anything special in Spacemacs to make this work. If using cider-test, then remember that the test code and any code it tests must be evaluated (loaded) into the REPL, as cider-test runs only within the REPL. The test directory also needs to be included in classpath settings, so for Clojure CLI tools projects I include the :test alias that adds test directory using :extra-paths

practicalli-johnny09:09:20

Is there a specific place in the video that is not working for you?

practicalli-johnny09:09:15

One Spacemacs specific thing. When calling the cider-test runner, Spacemacs will evaluate the namespace of the current buffer (and picks up changes). I usually evaluate the source and test buffers before running tests to ensure that all changes have been picked up (that may not be the case in the video)

paulspencerwilliams15:09:10

Right, so even explicitly evaluating the test namespace, *ns* still doesn’t bind to that namespace - instead it binds to 'user

paulspencerwilliams15:09:50

But if I change the namespace in the repl to the random function test namespace it works…

paulspencerwilliams15:09:08

The video I’m talking about is at https://practical.li/spacemacs/ and I suppose my results differ from yours around 16:22

practicalli-johnny18:09:49

To be more specific, *ns* dynamically binds to the namespace it is called from. So if you call the tests from the default user namespace, then *ns* will be user. Calling any of the cider-test- commands from the test buffer will automatically be evaluated in the test namespace, so *ns* will evaluate to that test namespace name. In fact, any Cider function called with a Clojure buffer as active will evaluate in the context of that buffers namespace You have to manually switch namespace if the REPL buffer is the active window when running commands (or of course evaluating code in the REPL buffer) This is one of many reasons I don't use the REPL buffer directly.