This content originally appeared on DEV Community and was authored by Alan Ferreira
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!
This content originally appeared on DEV Community and was authored by Alan Ferreira
Alan Ferreira | Sciencx (2024-07-06T19:39:19+00:00) How to save time when run RSpec tests. Retrieved from https://www.scien.cx/2024/07/06/how-to-save-time-when-run-rspec-tests/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.