Your Turn
We’ve covered a lot of ground this chapter! From basic Ruby building blocks like strings and numbers, through deeply nested collections, to methods with side effects, you can find a matcher to suit your needs.
All these matchers built into RSpec are designed to help you do two things:
-
Express exactly how you want the code to behave, without being too strict or too lax
-
Get precise feedback when something breaks so that you can find exactly where the failure happened
It’s much more important to keep these two principles in mind than it is to memorize all the different matchers. As you try your hand at the following exercises, refer to Appendix 3, Matcher Cheat Sheet to get inspiration for different matchers to try.
Exercises
Since matchers ...
Get Effective Testing with RSpec 3 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.