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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With