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

Get Effective Testing with RSpec 3 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.