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

Delegating to Existing Matchers Using Helper Methods

We’re going to start with a technique you’ve already used to keep your code organized: helper methods. RSpec provides its own matchers via built-in methods, such as contain_exactly(...). You can easily write your own methods that return the same matcher objects but using names specific to your domain. You can also add your own customizations, such as default arguments.

When you developed the expense tracker application in Part 2, Building an App With RSpec 3, you used the matcher expression a_hash_including(id: some_id) to represent a particular expected expense. Here’s an example use:

 expect​(ledger.expenses_on(​ ...

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