Sha256: d8847556bdee5411a3bb163b4aaf317608c79d9496d0da6ef90d19e47c663948

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

require 'simplecov'
SimpleCov.start do
  add_filter '/vendor/'
end
require 'pwm'

describe Pwm do
  describe 'The default set of characters' do
    (('A'..'Z').to_a - %w(I O)).each do |character|
      it "includes #{character}" do
        expect(Pwm.characters).to include(character)
      end
    end
    (('a'..'z').to_a - ['l']).each do |character|
      it "includes #{character}" do
        expect(Pwm.characters).to include(character)
      end
    end
    ('2'..'9').each do |character|
      it "includes #{character}" do
        expect(Pwm.characters).to include(character)
      end
    end
    %w(I O l 0 1).each do |character|
      it "does not include #{character}" do
        expect(Pwm.characters).not_to include(character)
      end
    end
  end

  describe 'The password method' do
    context 'when given a length' do
      context 'equal to 8' do
        it 'generates a password of that length' do
          expect(Pwm.password(8).length).to eq(8)
        end
      end
      context 'greater than 8' do
        it 'generates a password of that length' do
          expect(Pwm.password(9).length).to eq(9)
        end
      end
      context 'less than 8' do
        it 'raises Pwm::TooShortException' do
          expect { Pwm.password(7) }.to raise_error(Pwm::TooShortException)
        end
      end
    end
    context 'when not given a length' do
      it 'generates a 16-character password' do
        expect(Pwm.password.length).to eq(16)
      end
    end
    it 'generates passwords containing at least one upper-case letter' do
      expect(Pwm.password).to match(/[A-Z]/)
    end
    it 'generates passwords containing at least one lower-case letter' do
      expect(Pwm.password).to match(/[a-z]/)
    end
    it 'generates passwords containing at least one number' do
      expect(Pwm.password).to match(/[2-9]/)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pwm-1.2.2 spec/pwm_spec.rb