Chapter 2. Specifying Behavior with Examples and Matchers

In this chapter, we'll see how RSpec's examples and matchers implement the general testing concepts of units and assertions. An example is the base unit for a set of RSpec specs and, within it, you must have a matcher to assert something, otherwise it would serve no purpose.

In this chapter, we will cover the following topics:

  • Structure of a spec file
  • RSpec output
  • Matchers
  • The let helper
  • Testing for errors

Structure of a spec file

Let's look again at the AddressValidator module we introduced in Chapter 1, Exploring Testability from Unit Tests to Behavior-Driven Development, so we can understand its structure better. We'll also use some basic RSpec features to improve the tests. Let's look at the ...

Get RSpec Essentials 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.