问题描述
我已经为开发和测试环境设置了单独的database-url
,当在REPL中以及在命令行中的lein test
中运行我的webapp时,这很好用.这是我的profiles.clj
:
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"}}}
以及正确的数据库实例被击中的证据(我正在使用CouchDB):
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
但是,当我在Emacs中通过Cider运行测试时,它使用了开发环境,因此使用了错误的数据库实例.
However, when I run tests via Cider in Emacs it uses the dev environment and therefore the wrong database instance.
我该如何解决?
推荐答案
我建议您尝试使用with-redefs
.
类似这样的东西:
(with-redefs [db (get-my-test-db)]
(run-my-tests)
db
是在测试中将数据库句柄绑定到的符号.
Where db
is the symbol to which you bind your db handle in your tests.
本文应该会有所帮助:在Clojure中隔离外部依赖项
This article should be helpful:Isolating External Dependencies in Clojure
这篇关于运行测试时,如何让emacs苹果酒(clojure模式)使用我的测试环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!