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

Generated Example Descriptions

Matchers have another useful ability over simpler assert methods: they’re self-describing. The matcher protocol includes the optional (but recommended) description method. All built-in matchers define this method:

 >>​ start_with(1).description
 => "start with 1"
 >>​ (start_with(1) & end_with(9)).description
 => "start with 1 and end with 9"
 >>​ contain_exactly( a_string_starting_with(1) & ending_with(9) ).description
 => "contain exactly (a string starting with 1 and ending with 9)"

As you can see, the descriptions of composed and compound matchers include the description of each part. These descriptions are used in failure messages when you pass one matcher to another. They can also help you reduce duplication ...

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