Search code examples
ruby-on-railsrubyrspecrspec-rails

Is there a simple way to find slow specs


When running all specs in a project I have not touched in a while, I noticed that there seem to be 2 specs that take ages. I suspect some mocking of an API call or similar is not working anymore and the specs are running into a timeout.

Is there an easy way to identify those 2 specs without going manually through all spec files?


Solution

  • You can enable profiling by using the -p flag when running rspec

    Or you can permanently enable profiling by adding

    config.profile_examples = true
    

    or, for example,

    config.profile_examples = 5
    

    to your Rspec configuration in spec/spec_helper.rb.

    By default, it prints the 10 slowest examples, but you can set it to a different value to have it print more or fewer slow examples.