How do I get emacs cider (clojure mode) to use my test environment variables when running tests?

為{幸葍}努か 提交于 2019-12-10 12:43:52

问题


I've set up separate database-url for development and test environments, and this works nicely when running my webapp in the REPL and from the lein test on the command line. Here's my profiles.clj:

{:profiles/dev  {:env {:database-url "wiki"}}
 :profiles/test {:env {:database-url "wiki-test"}}}

And evidence of the right database instance being hit (I'm using CouchDB):

;; Running the site from the REPL:
[info] [<0.12149.0>] 127.0.0.1 - - GET /wiki/home-page 200
[info] [<0.10353.0>] 127.0.0.1 - - GET /wiki/about 200

;; Running lein test:
[info] [<0.12026.0>] 127.0.0.1 - - GET /wiki-test/welcome 404
[error] [<0.12933.0>] Could not open file /usr/local/var/lib/couchdb/wiki-test.c

However, when I run tests via Cider in Emacs it uses the dev environment and therefore the wrong database instance.

How do I fix this?


回答1:


I suggest you try using with-redefs for that.

Something like this:

(with-redefs [db (get-my-test-db)]
  (run-my-tests)

Where db is the symbol to which you bind your db handle in your tests.

This article should be helpful: Isolating External Dependencies in Clojure



来源:https://stackoverflow.com/questions/42069550/how-do-i-get-emacs-cider-clojure-mode-to-use-my-test-environment-variables-whe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!