Search code examples
ruby-on-railsruby-on-rails-4minitest

How to make Minitest run faster?


In a new Rails project, Minitest is running very slow:

First I set Spring binstubs:

david$ bundle exec spring binstub --all
* bin/rake: spring inserted
* bin/rails: spring inserted

Next I run the default test (navigation_test.rb) through Spring:

david$ time bundle exec spring rake test
Run options: --seed 32313

# Running:

.

Finished in 0.003368s, 296.9121 runs/s, 296.9121 assertions/s.

1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

real    0m5.171s
user    0m0.581s
sys     0m0.098s

The next runs are slightly faster, but still very slow (around 3 secs):

david$ time bundle exec spring rake test
Run options: --seed 48522

# Running:

.

Finished in 0.003506s, 285.2253 runs/s, 285.2253 assertions/s.

1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

real    0m3.159s
user    0m0.579s
sys     0m0.088s

If I run it again without bundler, it's a little faster:

david$ time spring rake test
Run options: --seed 55025

# Running:

.

Finished in 0.003413s, 292.9974 runs/s, 292.9974 assertions/s.

1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

real    0m2.677s
user    0m0.087s
sys     0m0.032s

Anyone using Minitest+Spring? How to make it run faster?

Using Rails 4.1.1


Solution

  • Once you have set up spring and binstubs, there is no reason to continue to call bundler. Try this:

    $ time bin/rake test