Rails clean database between tests not work Rails clean database between tests not work selenium selenium

Rails clean database between tests not work


Cleaning the tables means it deletes all records, it doesn't necessarily mean it resets the index counters - just like if you delete record 3 and then add a new record - the new one would be 4. So in your case it's possible 27 records have been deleted and the next one you create would be 28 even though there's only 1 actual record. Query the database to see how many actual records are there to verify that.

Next, your database cleaner config should be more like the recommended config - https://github.com/DatabaseCleaner/database_cleaner#rspec-with-capybara-example . append_after vs after is important for stability and checking the driver name vs just the :js metadata is too.

When checking for the href '/uploads/attachment/file/1/test_file.dat' in your tests you shouldn't be checking for a hardcoded '1' there you should check based on the record id number of the record you created. So "/uploads/attachment/file/#{question.id}/test_file.dat" (obviously question.id will depend on what objects you've created and your variable names, but that matches at least one of your tests I think.

Additionally after a quick look at your specs - anywhere you're doing expect(current_path).to eq ... is wrong. You should be doing expect(page).to have_current_path(...). The first way disables the retrying behavior of Capybara and will lead to flaky tests.

And finally - where you have expect(page).not_to have_content t('common.button.ready'), I'm guessing that should be expect(page).not_to have_button t('common.button.ready')