O'Reilly logo

Effective Testing with RSpec 3 by Myron Marston, Ian Dees

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required