Your Turn

In this chapter, you’ve learned the major parts of an expectation: the expect method, the subject, to/not_to, and the matcher. You wrote some simple expectations using expect and a few of RSpec’s built-in matchers. You saw how to combine matchers by passing them into one another, and by combining them with and/or.

In the next chapter, we’ll take you on a tour of the matchers that RSpec ships with. But first, test your newfound knowledge of expectations with a quick exercise.

Exercise

We’ve prepared an unfinished spec file that will give you the chance to try out the concepts explained in this chapter. We encourage you to download it, run it, and edit it until you’ve gotten all the specs to pass consistently:

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.