How to save time when run RSpec tests

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 li…


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » How to save time when run RSpec tests." Alan Ferreira | Sciencx - Saturday July 6, 2024, https://www.scien.cx/2024/07/06/how-to-save-time-when-run-rspec-tests/
HARVARD
Alan Ferreira | Sciencx Saturday July 6, 2024 » How to save time when run RSpec tests., viewed ,<https://www.scien.cx/2024/07/06/how-to-save-time-when-run-rspec-tests/>
VANCOUVER
Alan Ferreira | Sciencx - » How to save time when run RSpec tests. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/06/how-to-save-time-when-run-rspec-tests/
CHICAGO
" » How to save time when run RSpec tests." Alan Ferreira | Sciencx - Accessed . https://www.scien.cx/2024/07/06/how-to-save-time-when-run-rspec-tests/
IEEE
" » How to save time when run RSpec tests." Alan Ferreira | Sciencx [Online]. Available: https://www.scien.cx/2024/07/06/how-to-save-time-when-run-rspec-tests/. [Accessed: ]
rf:citation
» How to save time when run RSpec tests | Alan Ferreira | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.