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

Your Turn

This chapter paved a gradual path into custom matchers. We started off by building custom matchers from RSpec’s existing ones, using helper methods, aliases, and negation. Next, we defined a brand-new matcher using RSpec’s DSL. Finally, we peeled back the curtain and showed that there’s no magic behind matchers. They’re just plain Ruby classes.

With a good set of custom matchers, your specs will become more readable. When there’s a failure, the improved error message will save you time finding the cause.

Now, it’s time to try your hand at writing your own custom matcher.

Exercises

At the top of the chapter, we looked at some hypothetical matchers for a concert ticketing API. In these exercises, you’re going to implement these matchers. ...

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