Cleaning the Database with Truncation

Truncating the database before each scenario is a brute-force technique, and the main drawback is that it’s generally slower than rolling back a transaction. This is why the transactional approach is generally preferable if you can get away with it. The advantage of truncation is that it’s a cleaning strategy that works reliably when we have more than one database connection, since no transactions are used. Let’s modify our cleaning strategy and see how it compares. This is a simple change in our database.rb file, shown below.

Joe asks:
Joe asks:
Why Not Truncate the Database in an After Hook?

Truncating the database ...

Get The Cucumber Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.