Skip to content

Commit 4de56cf

Browse files
committed
Merge pull request #12 from futureworkz/test-errors
TIL Rails: Errors In Test Cases Creates Floating Test Data
2 parents 42ed12f + 30aeee0 commit 4de56cf

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Errors In Test Cases Creates Floating Test Data
2+
3+
If an exception is thrown when running your test cases, the test data created will NOT be rolled back.
4+
This creates "floating" test data in your test database will may impact other test cases.
5+
6+
The most common solution is to use the gem database_cleaner which basically clears out the entire test database
7+
whenever you start the test cases.
8+
However, this makes your test cases run slower!
9+
Furthermore, database_cleaner gem also don't address any test data leakage in your test cases.
10+
11+
The easiest solution is to run `rake db:test:prepare` in your terminal.
12+
This resets the entire test database so that there are no more floating test data in your test database.
13+
14+
Every time you have a floating test data issue, you should run `rake db:test:prepare`
15+
instead of using a slow solution like database_cleaner.

0 commit comments

Comments
 (0)