What is it?

Top tests displays your 10 slowest tests after execution. The goal is to help you keeping your tests fast.

Moreover top tests can break your build if any test is taking longer than a specified duration.

How to use it?

Add to your Gemfile.

group :test do
  gem 'top_tests'
end

Then run your test as usual and you will have a similar output:

Top 10 slowest tests:
    0.429 ApplicationControllerTest#test_notify_error
    0.322 HoneyBadgersControllerTest#test_show
    0.200 BearsControllerTest#test_destroy_collection
    0.134 SuricatsControllerTest#test_can_not_update
    0.124 SuricatsControllerTest#test_create
    0.105 SuricatsControllerTest#test_update
    0.096 HoneyBadgersControllerTest#test_create
    0.093 HoneyBadgersControllerTest#test_update
    0.091 SuricatsControllerTest#test_destroy
    0.090 HoneyBadgersControllerTest#test_show

Run your your with the option ‘–max-time=SECONDS` to break the tests that are slower than the specified time:

3 tests are taking longer than 0.2 seconds:
    0.410 HoneyBadgerTest#test_fighting_a_cobra
    0.228 SuricatTest#test_caught_by_an_eagle
    0.203 HoneyBadgerTest#test_eating_larvae