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

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

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