20

Recently I had a problem with one of my cucumber scenarios. Certain entries in my test database were disappearing whilst the feature was running. I solved the problem by changing the line

DatabaseCleaner.strategy = :transaction

to

DatabaseCleaner.strategy = :truncation

I'm not sure why that helped. There is a table on the database cleaners gem webpage, but it dosen't really say what the two terms mean. Any help on understanding the difference between the two concepts would be great.

2 Answers 2

41

Putting it in a very simple way: truncation removes all data from the database and transaction rollbacks all changes that has been made by the running scenario.

1
  • 1
    thats pretty much what I needed. Thanks
    – elliance
    Sep 18, 2011 at 0:46
2

Truncation removes the data leaving the database structure, transaction majorly rollback the database operation and it is the fastest strategy. And there is the last one which is deletion. Deletion deletes the data and removes the structure of the database, it is the slowest but safest. You can also check Difference between truncation, transaction and deletion database strategies

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.