spec/password_strategies/bcrypt_spec.rb in clearance-2.0.0.beta2 vs spec/password_strategies/bcrypt_spec.rb in clearance-2.0.0

- old
+ new

@@ -20,14 +20,27 @@ model_instance.password = password expect(BCrypt::Password).to have_received(:create).with( password, - cost: ::BCrypt::Engine::DEFAULT_COST + cost: ::BCrypt::Engine::DEFAULT_COST, ) end + it "uses an explicity configured BCrypt cost" do + stub_bcrypt_cost(8) + bcrypt_password = BCrypt::Password.create(password, cost: nil) + + expect(bcrypt_password.cost).to eq(8) + end + + it "uses the default BCrypt cost value implicitly" do + bcrypt_password = BCrypt::Password.create(password, cost: nil) + + expect(bcrypt_password.cost).to eq(BCrypt::Engine::DEFAULT_COST) + end + it "encrypts with BCrypt using minimum cost in test environment" do stub_bcrypt_password model_instance = fake_model_with_bcrypt_strategy model_instance.password = password @@ -38,9 +51,13 @@ ) end def stub_bcrypt_password allow(BCrypt::Password).to receive(:create).and_return(encrypted_password) + end + + def stub_bcrypt_cost(cost) + allow(BCrypt::Engine).to receive(:cost).and_return(cost) end def encrypted_password @encrypted_password ||= double("encrypted password") end