My load and "Elapsed time" change when RSpec starts. Can I speed them up?

Most of my tests currently run against models. I currently have about 100 tests. When I run them I see:

Finished in 3.99 seconds (files downloaded 17.97 seconds)
Finished in 3.93 seconds (files took 17.51 ​​seconds to download)
Finished in 2.03 seconds (files took 2.36 seconds to download) <<Now it looks like better Finished in 4.27 seconds (files took 17.45 seconds to upload)
Finishes in 1.98 seconds (files upload in 2.4 seconds) <<Now it looks better

The total 20 second delay is very similar to me and I see it randomly. Is this what I should accept, or maybe a better way? As the number of tests grows, I am concerned that my development cycle will become unwieldy. I know I can run individual or groups of spec files. I would like to optimize the performance of the whole set if possible.

I don't know what elements to add, but here are a few:

  • RSpec v3.0.4
  • Spring version 1.1.3
  • Rails 4.1.5
  • Mac OS X 10.9.4

Spring status reports:
.. $ spring
Spring status :

17524 spring server | app_name | started 137 hours ago

22503 spring application | app_name | started work 77 hours ago | development mode


source to share

1 answer

First of all - make sure you are using your set of specs with spring:

spring rspec


This will ensure that the environment is preloaded with spring and that RSpec is using the pre-installed environment.

If you haven't installed spring with rspec yet, just add spring-commands-rspec

to your Gemfile:

gem "spring-commands-rspec", group: :development


Then stop spring so that it collects the new configuration:

spring stop


The way you do it, don't trust the RSpec message load time. The amount of load times you see is probably wildly inaccurate. When starting RSpec with spring, the boot time seems to be from the beginning of spring:

> time spring rspec

Finished in 9.12 seconds (files took 1 minute 11.36 seconds to load)
345 examples, 0 failures

spring rspec  0.45s user 0.06s system 4% cpu 10.304 total


As you can see, RSpec reported that it took 1 minute 11.36 seconds to download, but in fact the entire package downloaded and ran in 10.3 seconds!

If you run the test again after 2 minutes:

> time spring rspec 

Finished in 9.01 seconds (files took 3 minutes 18.5 seconds to load)
345 examples, 0 failures

spring rspec  0.44s user 0.06s system 4% cpu 10.209 total



There is an open issue for inaccurately recorded download periods:

There is a workaround for this problem, which is to add Rspec.configuration.start_time =

to binstub in bin/rspec

. With this I get a constant load time of 1 second:

time spring rspec

Finished in 8.46 seconds (files took 0.53673 seconds to load)
345 examples, 0 failures

spring rspec  0.46s user 0.06s system 5% cpu 9.214 total




All Articles