O'Reilly logo

The Cucumber Book, 2nd Edition by Steve Tooke, Aslak Hellesoy, Matt Wynne

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required