Capybara+Selemium: How to initialize database in an integration test code and make it visible in Rails application?
For me worked solution from here and here:
- add to Gemfile
gem database_cleaner
- create file
spec/support/javascript.rb
with content
`
RSpec.configure do |config| config.before(:suite) do DatabaseCleaner.strategy = :transaction DatabaseCleaner.clean_with :truncation end config.before(:each) do if example.metadata[:js] Capybara.current_driver = :selenium DatabaseCleaner.strategy = :truncation else DatabaseCleaner.strategy = :transaction DatabaseCleaner.start end end config.after(:each) do Capybara.use_default_driver if example.metadata[:js] DatabaseCleaner.clean endend
`
though it caused small penalti to my contoller & model specs execution time (from 40 to 43 seconds).