Skip to content

Commit

Permalink
Merge pull request #6 from bdmac/update-tests
Browse files Browse the repository at this point in the history
Update tests and ensure specs run
  • Loading branch information
bdmac committed Sep 12, 2015
2 parents ce680d6 + b2ba590 commit 3d7a715
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Expand Up @@ -2,7 +2,7 @@ source 'https://rubygems.org'

gemspec

version = ENV["RAILS_VERSION"] || "3.2"
version = ENV["RAILS_VERSION"] || "4.2"

rails = case version
when "master"
Expand All @@ -11,4 +11,4 @@ else
"~> #{version}.0"
end

gem "rails", rails
gem "rails", rails
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
@@ -1,8 +1,8 @@
require 'bundler/setup'
require 'strong_password'
require 'active_model'
require 'strong_password'

RSpec.configure do |config|
config.expect_with(:rspec) {|c| c.syntax = :expect}
config.order = :random
end
end
12 changes: 6 additions & 6 deletions spec/strong_password/dictionary_adjuster_spec.rb
Expand Up @@ -7,12 +7,12 @@ module StrongPassword

it 'returns true if the calculated entropy is >= the minimum' do
subject.stub(adjusted_entropy: 18)
expect(subject.is_strong?).to be_true
expect(subject.is_strong?).to be_truthy
end

it 'returns false if the calculated entropy is < the minimum' do
subject.stub(adjusted_entropy: 17)
expect(subject.is_strong?).to be_false
expect(subject.is_strong?).to be_falsey
end
end

Expand All @@ -21,7 +21,7 @@ module StrongPassword

it 'returns the opposite of is_strong?' do
subject.stub(is_strong?: true)
expect(subject.is_weak?).to be_false
expect(subject.is_weak?).to be_falsey
end
end

Expand Down Expand Up @@ -52,9 +52,9 @@ module StrongPassword
end

it 'allows extra words to be provided as an array' do
password = 'mcmanus'
password = 'administratorWEQ@123'
base_entropy = EntropyCalculator.calculate(password)
expect(DictionaryAdjuster.new(password).adjusted_entropy(extra_dictionary_words: ['mcmanus'])).not_to eq(base_entropy)
expect(DictionaryAdjuster.new(password).adjusted_entropy(extra_dictionary_words: ['administrator'])).not_to eq(base_entropy)
end

it 'allows minimum word length to be adjusted' do
Expand All @@ -65,4 +65,4 @@ module StrongPassword
end
end
end
end
end
14 changes: 7 additions & 7 deletions spec/strong_password/qwerty_adjuster_spec.rb
Expand Up @@ -7,24 +7,24 @@ module StrongPassword

it 'returns true if the calculated entropy is >= the minimum' do
subject.stub(adjusted_entropy: 18)
expect(subject.is_strong?).to be_true
expect(subject.is_strong?).to be_truthy
end

it 'returns false if the calculated entropy is < the minimum' do
subject.stub(adjusted_entropy: 17)
expect(subject.is_strong?).to be_false
expect(subject.is_strong?).to be_falsey
end
end

describe '#is_weak?' do
let(:subject) { QwertyAdjuster.new('password') }

it 'returns the opposite of is_strong?' do
subject.stub(is_strong?: true)
expect(subject.is_weak?).to be_false
expect(subject.is_weak?).to be_falsey
end
end

describe '#adjusted_entropy' do
before(:each) { NistBonusBits.stub(bonus_bits: 0)}
{
Expand All @@ -42,4 +42,4 @@ module StrongPassword
end
end
end
end
end
14 changes: 9 additions & 5 deletions spec/validation/strength_validator_spec.rb
Expand Up @@ -18,7 +18,7 @@ class TestStrengthStrongEntropy < User
end

class TestStrengthExtraWords < User
validates :password, password_strength: {extra_dictionary_words: ['mcmanus'], use_dictionary: true}
validates :password, password_strength: {extra_dictionary_words: ['administrator'], use_dictionary: true}
end

class TestBaseStrengthAlternative < User
Expand Down Expand Up @@ -138,14 +138,18 @@ module Validations

describe 'extra words' do
it 'allows extra words to be specified as an option to the validation' do
password = 'mcmanus'
password = 'administratorWEQ@123'
# Validate that without 'administrator' added to extra_dictionary_words
# this password is considered strong
weak_entropy.password = password
expect(weak_entropy.valid?).to be_true
expect(weak_entropy.valid?).to be_truthy
# Now check that with 'administrator' added to extra_dictionary_words
# in our model, the same password is considered weak.
extra_words.password = password
expect(extra_words.valid?).to be_false
expect(extra_words.valid?).to be_falsey
end
end
end
end
end
end
end

0 comments on commit 3d7a715

Please sign in to comment.