How to save time when run RSpec tests

RMAG news

two tips that help a lot to save time when running test suites on Rails with RSpec.

1. Reduce Devise.stretches

Note: This tip is useful if you are using Devise as an
authentication tool.

In your spec/test.rb file, add the following line:

Devise.stretches = 1

When using Devise, the cost value is set by a class variable called stretches, with a default value of 11. It specifies the number of times the password is hashed. By setting this value lower, you make the hash algorithm less costly and time-consuming, saving time in the test suite as it’s unnecessary to have such a secure password in our testing environment.

2. Increase log level in the test environment

In your spec/test.rb file, add the following line:

Rails.logger.level = 4

Rails logs everything that happens in your test environment by default to “log/test.log”. By increasing the logger level, you reduce IO during your tests. The downside is that if a test fails, nothing will be logged. In such cases, simply comment out the above configuration option and rerun your tests.

These two tips already help you save a lot of time when running the test suite with RSpec. Hope this helps!

Please follow and like us:
Pin Share