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

How Matchers Work

Earlier, we saw that matchers are objects that carry pass/fail logic. Let’s take a closer look at how they work.

A matcher is a bit like a regular expression. Just as the regular expression /^\[warn\] / defines a category of strings (those beginning with [warn] followed by a space), a matcher defines a category of objects.

The resemblance doesn’t end there. As you’ll see in a moment, matchers implement one of the same protocols that regular expressions do, allowing them to be used in similar ways.

Any Ruby object can be used as a matcher as long as it implements a minimal set of methods. This protocol is so simple that you can even build up a matcher object in IRB. Over the next few code examples, we’re going to do just that. ...

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