Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show runtime for each rspec example

currently I'm running more than 1k examples and it's taking a long time to complete (more than 20 minutes!!!).

I'd like to identify which examples are the ones taking more time to complete, is there any way to run rspec and return the time each example takes to complete(individually)? I'm using rspec 1.3.0 and rspec-rails 1.2.3

like image 510
jpemberthy Avatar asked Jan 31 '11 21:01

jpemberthy


People also ask

What RSpec method is used to create an example?

The describe Keyword The word describe is an RSpec keyword. It is used to define an “Example Group”. You can think of an “Example Group” as a collection of tests. The describe keyword can take a class name and/or string argument.


1 Answers

You can use profiling to list your 10 slowest examples:

spec -p spec/*/*_spec.rb --colour --format profile 

If you run this on a specific test suite you can get the 10 slowest examples from a smaller subset of examples:

spec -p spec/models/user_spec.rb --format profile 

Newer Versions of Rspec

For newer versions of rspec you should use the --profile option:

rspec spec/ --profile         | (shows the 10 slowest examples) rspec spec/ --profile 2       | (shows the 2  slowest examples) 
like image 170
Pan Thomakos Avatar answered Oct 04 '22 11:10

Pan Thomakos