Skip to content

TIL Rails: Errors In Test Cases Creates Floating Test Data #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions rails/errors-in-test-cases-creates-floating-test-data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Errors In Test Cases Creates Floating Test Data

If an exception is thrown when running your test cases, the test data created will NOT be rolled back.
This creates "floating" test data in your test database will may impact other test cases.

The most common solution is to use the gem database_cleaner which basically clears out the entire test database
whenever you start the test cases.
However, this makes your test cases run slower!
Furthermore, database_cleaner gem also don't address any test data leakage in your test cases.

The easiest solution is to run `rake db:test:prepare` in your terminal.
This resets the entire test database so that there are no more floating test data in your test database.

Every time you have a floating test data issue, you should run `rake db:test:prepare`
instead of using a slow solution like database_cleaner.