Getting the Words Right

Specs can’t exist on their own. From the first spec you wrote while reading this book, every spec has been part of an example group. The example group fulfills the role of a test case class in other test frameworks. It has multiple purposes:

  • Gives a logical structure for understanding how individual examples relate to one another

  • Describes the context—such as a particular class, method, or situation—of what you’re testing

  • Provides a Ruby class to act as a scope for your shared logic, such as hooks, let definitions, and helper methods

  • Runs common setup and teardown code shared by several examples

Let’s look at a few different ways to create these groups.

The Basics

We saw the basic ways to organize specs in Groups, Examples, ...

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.