Skip to content

Instantly share code, notes, and snippets.

@jparker
Last active October 12, 2015 17:37
Show Gist options
  • Save jparker/4062626 to your computer and use it in GitHub Desktop.
Save jparker/4062626 to your computer and use it in GitHub Desktop.
Snippet to be placed in test_helper.rb or spec_helper.rb to trick has_secure_password into using lower cost bcrypt encryption than the default.
# Place in test_helper.rb or spec_helper.rb
AuthLogic::CryptoProviders::BCrypt.cost = 1
# Place in test_helper.rb, spec_helper.rb or spec/support/...
require 'bcrypt'
class BCrypt::Password
class << self
method = instance_method(:create)
define_method :create do |arg, options = {cost: 1}|
method.bind(self).call(arg, options)
end
end
end
# Place in test_helper.rb or spec_helper.rb
Devise.setup do |config|
config.stretches = 1
end
# Before...
$ bundle exec rspec ./spec/features
..................................................................................................................
Finished in 42.67 seconds
114 examples, 0 failures
Randomized with seed 48858
# ...and after
$ SPEC_OPTS="--seed 48858" bundle exec rspec ./spec/features
..................................................................................................................
Finished in 27.36 seconds
114 examples, 0 failures
Randomized with seed 48858
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment