Identifying Slow Examples

Throughout this book, we’re going to give you advice on how to keep your specs running quickly. To understand where the biggest bottlenecks are in your suite, you need to be able to identify the slowest examples.

RSpec’s spec runner can help you do so. Consider the following group of examples that take too long to run:

 RSpec.describe ​'The sleep() method'​ ​do
 it​(​'can sleep for 0.1 second'​) { sleep 0.1 }
 it​(​'can sleep for 0.2 second'​) { sleep 0.2 }
 it​(​'can sleep for 0.3 second'​) { sleep 0.3 }
 it​(​'can sleep for 0.4 second'​) { sleep 0.4 }
 it​(​'can sleep for 0.5 second'​) { sleep 0.5 }
 end

We can ask RSpec to list the top time-wasters by passing 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.