简体   繁体   中英

When using cucumber, how do I select the 'test' database?

I'm just running cucumber; I'm not sure which database it's running with but when I run it with selenium (via capybara) it definitely uses the development database. How can I be certain the test database is selected, and how can I interact with the test database to make sure it's in the right state?

By default, Cucumber uses the test environment and test database. You ought to see this in your database.yml:

cucumber:
  <<: *test

Which means 'take the settings from the test database and use for cucumber'.

To get your test database in the right state, use the rake commands to copy your development database ready for execution:

rake db:test:clone_structure

I also recommend looking at the DatabaseCleaner gem, which is widely adopted for use in tests. You can set it up with cucumber so that either truncates or uses database transactions to ensure that each scenario starts from a clean database state.

https://github.com/bmabey/database_cleaner

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM