ruby on rails - database cleanup with capybara -
i'm using capybara, minitest, database_cleaner gem, i'm curious database cleaner not cleanup database after running test, test running well, user created , can login successfully, re-run test same data, , said email taken, meaning: database_cleaner not running
below test
require "test_helper" require "database_cleaner" feature 'register new user' scenario 'register', js: true databasecleaner.strategy = :transaction databasecleaner.start visit '/sign_up' within '#new_user' fill_in 'user name', with: 'user4' fill_in 'email', with: 'user4@gmail.com' fill_in 'password', with: 'password4' fill_in 'password konfirmasi', with: 'password4' click_button 'sign up' end databasecleaner.clean page.must_have_content 'user setting & info' end end
and below gemfile testing
group :development, :test gem 'selenium-webdriver', '2.53.4' gem 'minitest-rails-capybara' gem 'minitest-reporters' gem 'database_cleaner' end
you need put page.must_have_content 'user setting & info'
before databasecleaner.clean
line. because when click button can return while request triggered button click happens asynchronously. in case means click button, clean database, meanwhile request create new user sent , arrives after database has been cleared thereby creating user doesn't cleared.
usually databasecleaner methods called setup/teardown minitest (before/append_after blocks rspec) ensure database cleaning doesn't occur until test complete, , run if in test fails.
Comments
Post a Comment