-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Closed
Labels
Description
Describe the bug
Starting with version 3.3.0, Faker is generating invalid US phone numbers.
To Reproduce
Use the reproduction script below to reproduce the issue. If you swap the library version back to 3.2.3, the tests will always pass successfully.
# frozen_string_literal: true
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'faker', '3.3.0' # fails
# gem 'faker', '3.2.3' # passes
gem 'phonelib'
gem 'minitest'
end
require 'minitest/autorun'
Faker::Config.locale = 'en-US'
class BugTest < Minitest::Test
def test_fail_on_first_bad_number
@tester = Faker::PhoneNumber
100.times do
number = @tester.cell_phone_in_e164
assert Phonelib.valid?(number), "Expected #{number} to be a valid phone number"
end
end
def test_100_numbers
@tester = Faker::PhoneNumber
results = Array.new(100) { Phonelib.valid?(@tester.cell_phone_in_e164) }
tally = results.tally
assert results.all? == true, "Expected 100 valid phone numbers, but only #{tally[true]} of #{tally[false]} valid"
end
end