Sha256: e6461403baf528ae93e4f741d02366b8f0fb97af9bb827e64245d8a253a53608
Contents?: true
Size: 1.8 KB
Versions: 2
Compression:
Stored size: 1.8 KB
Contents
require 'spec_helper' describe Mascherari::Formatter do subject do described_class.new :format => "(##) ####-####" end describe '#mask' do context 'when value is unmasked' do it 'returns value with mask' do expect(subject.mask "1234567890").to eq "(12) 3456-7890" end end context 'when value is already masked' do it 'returns value' do expect(subject.mask "(12) 3456-7890").to eq "(12) 3456-7890" end end context 'when value size is invalid' do it 'raises an error' do expect { subject.mask "23456789" }.to raise_error "Value size don't match format" expect { subject.mask "91234567890" }.to raise_error "Value size don't match format" end end end describe '#unmask' do context 'when value is masked' do it 'returns value with mask' do expect(subject.unmask "(12) 3456-7890").to eq "1234567890" end end context 'when value is already unmasked' do it 'returns value' do expect(subject.unmask "1234567890").to eq "1234567890" end end context 'when value size is invalid' do it 'raises an error' do expect { subject.unmask "(23) 456-789" }.to raise_error "Value size don't match format" expect { subject.unmask "(123) 4456-7789" }.to raise_error "Value size don't match format" end end end context 'when using different wildcard' do subject do described_class.new :format => "(**) ****-****", :wildcard => "*" end describe '#mask' do it 'returns value with mask' do expect(subject.mask "1234567890").to eq "(12) 3456-7890" end end describe '#unmask' do it 'returns value without mask' do expect(subject.unmask "(12) 3456-7890").to eq "1234567890" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mascherari-0.0.2 | spec/formatter_spec.rb |
mascherari-0.0.1 | spec/formatter_spec.rb |