我的黄瓜测试正在修改开发数据库。我如何让它修改测试数据库?
在我的 features/support/env.rb 文件的顶部:
ENV["RAILS_ENV"] = 'test'
但是测试仍然修改开发数据库...... 即使我这样做
rake cucumber:authentication RAILS_ENV=test
仍然会更改开发数据库
我还需要更改什么?
数据库.yml:
development:
adapter: mysql
encoding: utf8
database: app_dev
username: root
password:
test:
adapter: mysql
encoding: utf8
database: app_test
username: root
password:
production:
adapter: mysql
encoding: utf8
database: app_production
username: root
password:
cucumber: &CUCUMBER
adapter: mysql
encoding: utf8
database: app_cuke
username: root
password:
culerity:
<<: *CUCUMBER
使用:
ruby 1.8.7
rails 2.3.8
and cucumber 1.0.2
At the top of my features/support/env.rb file:
ENV["RAILS_ENV"] = 'test'
BUt the tests still modify the development db....
Even when I do
rake cucumber:authentication RAILS_ENV=test
it still changes the dev db
What else do I need to change?
database.yml:
development:
adapter: mysql
encoding: utf8
database: app_dev
username: root
password:
test:
adapter: mysql
encoding: utf8
database: app_test
username: root
password:
production:
adapter: mysql
encoding: utf8
database: app_production
username: root
password:
cucumber: &CUCUMBER
adapter: mysql
encoding: utf8
database: app_cuke
username: root
password:
culerity:
<<: *CUCUMBER
using:
ruby 1.8.7
rails 2.3.8
and cucumber 1.0.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另外 dotenv 也可能会导致此问题,因为如果 .env 文件中设置了 DATABASE_URL,则将使用此数据库无论。这导致我的测试连接到我的开发数据库。
Also dotenv might cause this because if there is a DATABASE_URL set in your .env file, this database will be used no matter what. This caused my tests to connect to my development database for me.
检查数据库.yml
也许您已经为测试环境指定了开发数据库?
好吧,基本安装步骤是
检查database.yml,指定正确的连接详细信息,
检查cucumber,
此步骤的结果是什么?
特别是您是否创建并迁移了用于测试的数据库?
check database.yml
Probably you have specified development database for test env?
Well, basic install steps are
check database.yml, to specify right connection details
check cucumber
what were the results of this steps?
especially have you created and migrated db for tests?
我遇到了类似的问题,我这样解决了它:
在
cucumber.rake
中,我添加了 rake 任务,然后我让所有 cucumber 任务都依赖于它,就像
I had a similar problem and I solved it like this:
In
cucumber.rake
I added the rake taskand then I made all cucumber tasks depend on it like