Created
July 13, 2014 22:21
-
-
Save tjchambers/717dde44ba5a2a295774 to your computer and use it in GitHub Desktop.
scrubber test for mutant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EmailAddressScrubber | |
DUMMY = '@yahoo.com' unless defined?(DUMMY) | |
CANDIDATES = %w(TestingInferences.com CoordinationSystem.com DifficultConversation.com Undiscussible.com RelationshipEffectiveness.com Coordinated-Action.com OptimizeAlignment.com AlignmentOptimization.com) unless defined?(CANDIDATES) | |
def scrub(address) | |
x = address[1].ord % CANDIDATES.size | |
collapse(address.sub(DUMMY, "@#{CANDIDATES[x]}")) | |
end | |
def collapse(out) | |
out = out.sub('99@', '@').sub('001@', '@') | |
out = out[2..-1] if out =~ /sp.@.*/ | |
out | |
end | |
end | |
require 'spec_helper.rb' | |
describe 'EmailAddressScrubber' do | |
let(:eas) { EmailAddressScrubber.new } | |
describe '#scrub' do | |
it 'should scrub an email address' do | |
expect(eas.scrub('tim@yahoo.com')).to eq('tim@CoordinationSystem.com') | |
expect(eas.scrub('spc@yahoo.com')).to eq('c@TestingInferences.com') | |
end | |
it 'should return same address if not yahoo.com' do | |
old_address = 'tim@gmail.com' | |
expect(eas.scrub(old_address)).to eq(old_address) | |
end | |
end | |
describe '#collapse' do | |
it 'should collapse properly' do | |
$_ = '' | |
expect(eas.collapse('----')).to eq('----') | |
expect(eas.collapse('a99@xyz.com')).to eq('a@xyz.com') | |
expect(eas.collapse('a001@xyz.com')).to eq('a@xyz.com') | |
expect(eas.collapse('spx@xyz.com')).to eq('x@xyz.com') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment