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

Higher-Order Matchers

All the matchers seen so far are primitives. Now, we’re going to look at higher-order matchers—that is, matchers that you can pass other matchers into. With this technique, you can build up composed matchers that specify exactly the behavior you want.

Collections and Strings

One of the primary tasks of programming, in any language, is dealing with collections, and Ruby is no exception. RSpec ships with six different matchers for dealing with data structures:

  • include requires certain items to be present (in any order).
  • start_with and end_with require items to be at the beginning or end.
  • all checks a common property across all items.
  • match checks a data structure against a pattern.
  • contain_exactly requires certain items, and ...

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