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