Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find a list of slow rspec tests [duplicate]

How can I find a list of the slowest rspec tests? I want to refactor those to run faster. I tried looking for gems but can't find any. I was thinking of putting something in

Rspec.before(:each)

and

Rspec.after(:each)

blocks to generate this list. But I don't know how to access the name of the spec.

like image 800
Ibrahim Muhammad Avatar asked Jun 07 '12 18:06

Ibrahim Muhammad


2 Answers

That's actually built right in to the rspec command. Just use the -p or --profile flag while you're running all your rspec tests.

like image 148
MrDanA Avatar answered Nov 18 '22 19:11

MrDanA


As MrDan says, the --profile flag. You can also make a .rspec file in the root of your project, so that you get the timing information all the time, like this:

$ cat .rspec 
--colour
--profile
--format nested
--backtrace

You can also speed up all your tests generally by turning off garbage collection, like this:

# turn off garbage collection when running tests, place this in spec_helper.rb
RSpec.configure do |config|
  config.before(:all) do
     DeferredGarbageCollection.start
  end

  config.after(:all) do
     DeferredGarbageCollection.reconsider
  end
end
like image 21
Rob Avatar answered Nov 18 '22 18:11

Rob