Customizing Your Specs’ Output

When you use RSpec on a real-world project, you’ll build up a suite of dozens, hundreds, or even thousands of examples. Most test frameworks, including RSpec, are optimized for this kind of use. The default output format hides a lot of detail so that it can show your specs’ progress.

The Progress Formatter

In this section, we’re going to look at a different ways to view your specs’ output. Create a new file called spec/coffee_spec.rb with the following contents:

 RSpec.describe ​'A cup of coffee'​ ​do
 let​(​:coffee​) { Coffee.new }
 
 it​ ​'costs $1'​ ​do
 expect​(coffee.price).to eq(1.00)
 end
 
»context​ ​'with milk'​ ​do
 before​ { coffee.add ​:milk​ }

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.