Lower your cost for speedy tests when using BCrypt
If you are using BCrypt Ruby you can have some significant time savings when running your unit tests by lowering the cost. By default BCrypt::Password.create(unencrypted_password)
will use a cost of 10. I dropped a RSpec test suite from 25 seconds to just 4 by just setting the cost to be the minimum (4) in test mode.
def password=(unencrypted_password)
@password = unencrypted_password
unless unencrypted_password.blank?
if Rails.env.test?
cost = BCrypt::Engine::MIN_COST
else
cost = BCrypt::Engine::DEFAULT_COST
end
self.password_digest = BCrypt::Password.create(unencrypted_password, cost: cost)
end
end
Written by Nick DeSteffen
Related protips
1 Response
Nice tip!
You can also set it on your test_helper.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#