Using the Matcher DSL

In Part 2, Building an App With RSpec 3, you built an expense-tracking API. If this grows to include expense accounts, you’d end up writing specs that check account balances. In this section, we’re going to build a custom have_a_balance_of matcher that helps with those expectations. Here’s what the matcher will eventually look like:

 expect​(account).to have_a_balance_of(30)

Unlike most of the other examples in the book, the code snippets in this section aren’t intended for you to type in as you read. We want to focus on just the matcher, without cluttering the examples with all the supporting code. If you do want to run these snippets on your ...

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.