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

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​ }

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