Sha256: 84fadb16d80024416822c1875bc3a5ac02dd55a32da322c41f7dcd8cd84ed8a2

Contents?: true

Size: 1.23 KB

Versions: 7

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require 'helper'

class TestPhoneNumber < Test::Unit::TestCase
  include DeterministicHelper

  assert_methods_are_deterministic(
    FFaker::PhoneNumber,
    :phone_number, :area_code, :exchange_code, :short_phone_number,
    :phone_calling_code, :imei
  )

  def test_phone_number
    assert_match(/\d{3}[. -]\d{3}/, FFaker::PhoneNumber.phone_number)
  end

  def test_area_code
    assert_not_match(/\A\d11\z/, FFaker::PhoneNumber.area_code.to_s)
    assert_match(/\A\d{3}\z/, FFaker::PhoneNumber.area_code.to_s)
  end

  def test_exchange_code
    assert_not_match(/\A\d11\z/, FFaker::PhoneNumber.exchange_code.to_s)
    assert_match(/\A\d{3}\z/, FFaker::PhoneNumber.exchange_code.to_s)
  end

  def test_short_phone_number
    assert_match(/\A\d{3}-\d{3}-\d{4}\z/, FFaker::PhoneNumber.short_phone_number)
  end

  def test_phone_calling_code
    assert_match(/\A\+\d+\z/, FFaker::PhoneNumber.phone_calling_code)
  end

  def test_imei
    assert_match(/\A\d{15}\z/, FFaker::PhoneNumber.imei)
  end

  def test_imei_with_sn
    sn = rand(0...1_000_000)
    assert_match(/\A\d{8}#{format('%06d', sn)}\d{1}\z/,
                 FFaker::PhoneNumber.imei(sn))
    assert_deterministic { FFaker::PhoneNumber.imei(sn) }
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ffaker-2.18.0 test/test_phone_number.rb
ffaker-2.17.0 test/test_phone_number.rb
ffaker-2.16.0 test/test_phone_number.rb
ffaker-2.15.0 test/test_phone_number.rb
ffaker-2.14.0 test/test_phone_number.rb
ffaker-2.13.0 test/test_phone_number.rb
ffaker-2.12.0 test/test_phone_number.rb