We cover:

  • How to specify expected outcomes of your code with rspec-expectations
  • What a matcher is
  • How to match complex data structures, focusing only on the important details
  • How to combine matchers with and/or operators

Chapter 10Exploring RSpec Expectations

In Part 3, RSpec Core, we saw how rspec-core helps you structure your test code into example groups and examples. But having a sound structure is not enough for writing good tests. If our specs run code without looking at the output, we’re not really testing anything—except that the code doesn’t crash outright. That’s where rspec-expectations comes in. It provides an API for specifying expected outcomes.

Each RSpec example should contain one or more expectations. These express what you ...

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.