Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 352
cjm2671 Avatar asked Apr 15 '26 21:04

cjm2671


1 Answers

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

like image 109
Dan Garland Avatar answered Apr 17 '26 12:04

Dan Garland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!