O'Reilly logo

Effective Testing with RSpec 3 by Myron Marston, Ian Dees

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

Testing Ledger Behavior

We’ve seen how to run Sequel migrations manually from the command line. You’ll need to configure RSpec to run them automatically, so that the database structure is in place before your first integration spec runs.

The following code will make sure the database structure is set up and empty, ready for your specs to add data to it:

 Sequel.extension ​:migration
 Sequel::Migrator.run(DB, ​'db/migrations'​)
 DB[​:expenses​].truncate

First, we run all the migration files in to make sure that all the database tables exist with their current schema. Then, we remove any leftover test data from the table using the truncate method. That way, each run of the spec suite starts with a clean database—no matter what happened before. ...

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