在 运行 测试时,如何让 emacs cider(clojure 模式)使用我的测试环境变量?

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

我已经为开发和测试环境设置了单独的 database-url,这在 运行 在 REPL 中和从 lein test 在命令行中设置我的 webapp 时效果很好.这是我的 profiles.clj:

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

以及命中正确数据库实例的证据(我使用的是 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

但是,当我 运行 在 Emacs 中通过 Cider 进行测试时,它使用了开发环境,因此使用了错误的数据库实例。

我该如何解决这个问题?

我建议您尝试使用 with-redefs

像这样:

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

其中 db 是您在测试中绑定数据库句柄的符号。

这篇文章应该会有帮助: Isolating External Dependencies in Clojure