我的黄瓜测试正在修改开发数据库。我如何让它修改测试数据库?

发布于 2024-12-02 01:23:50 字数 811 浏览 1 评论 0原文

在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情徒 2024-12-09 01:23:50

另外 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.

七七 2024-12-09 01:23:50

检查数据库.yml
也许您已经为测试环境指定了开发数据库?

好吧,基本安装步骤是

bundle install
rails generate cucumber:install

检查database.yml,指定正确的连接详细信息,

rake db:create
rake db:migrate

检查cucumber,

rake cucumber

此步骤的结果是什么?
特别是您是否创建并迁移了用于测试的数据库?

check database.yml
Probably you have specified development database for test env?

Well, basic install steps are

bundle install
rails generate cucumber:install

check database.yml, to specify right connection details

rake db:create
rake db:migrate

check cucumber

rake cucumber

what were the results of this steps?
especially have you created and migrated db for tests?

幸福还没到 2024-12-09 01:23:50

我遇到了类似的问题,我这样解决了它:

cucumber.rake 中,我添加了 rake 任务

task :ensure_test_env do
  ENV['RAILS_ENV'] = 'test'
end

,然后我让所有 cucumber 任务都依赖于它,就像

Cucumber::Rake::Task.new({:ok => ['db:test:prepare', :ensure_test_env]}, ...

I had a similar problem and I solved it like this:

In cucumber.rake I added the rake task

task :ensure_test_env do
  ENV['RAILS_ENV'] = 'test'
end

and then I made all cucumber tasks depend on it like

Cucumber::Rake::Task.new({:ok => ['db:test:prepare', :ensure_test_env]}, ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文