Using a Custom Formatter

In Customizing Your Specs’ Output, you used RSpec’s built-in formatters to view different levels of detail in your specs’ output. Now, you’re going to use a custom formatter to make one small tweak to the way RSpec reports failures.

A custom formatter is a regular Ruby class that registers itself with RSpec to receive notifications. As your suite runs, RSpec notifies the formatter of the events it’s subscribed to, such as starting an example group, running an example, or encountering a failure. This flexible system gives you room for all sorts of creative changes to the output. Here, we’re going to change how RSpec reports failures.

RSpec’s built-in formatters display failure details—messages and backtraces—at the ...

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.