repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1 value | license stringclasses 7 values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2 classes |
|---|---|---|---|---|---|---|---|---|
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_number.rb | test/faker/default/test_faker_number.rb | # frozen_string_literal: true
require_relative '../../test_helper'
require 'minitest/mock'
class TestFakerNumber < Test::Unit::TestCase
def setup
@tester = Faker::Number
end
def test_leading_zero_number
assert_match(/^0[0-9]{9}/, @tester.leading_zero_number)
assert_match(/^0[0-9]{8}/, @tester.leading_zero_number(digits: 9))
end
def test_number
assert_match(/[0-9]{10}/, @tester.number(digits: 10).to_s)
10.times do |digits|
digits += 1
assert_match(/^[0-9]{#{digits}}$/, @tester.number(digits: digits).to_s)
end
assert_equal(10, @tester.number(digits: 10).to_s.length)
assert_equal(1, @tester.number(digits: 1).to_s.length)
end
def test_number_with_one_digit
random_number = 4
in_range = lambda { |range|
assert_equal(0..9, range)
random_number
}
Faker::Base.stub(:rand, in_range) do
assert_equal(random_number, @tester.number(digits: 1))
end
end
def test_decimal
assert_match(/[0-9]{1}\.[1-9]{1}/, @tester.decimal(l_digits: 1, r_digits: 1).to_s)
assert_match(/[0-9]{2}\.[0-9]{1}[1-9]{1}/, @tester.decimal(l_digits: 2).to_s)
assert_match(/[0-9]{4}\.[0-9]{4}[1-9]{1}/, @tester.decimal(l_digits: 4, r_digits: 5).to_s)
end
def test_digit
assert_match(/[0-9]{1}/, @tester.digit.to_s)
assert_includes((1..1000).collect { |_i| @tester.digit == 9 }, true)
end
def test_even_distribution
assert stats = {}
assert times = 10_000
times.times do
assert num = @tester.digit
stats[num] ||= 0
assert stats[num] += 1
end
stats.each_value do |value|
assert_in_delta 10.0, 100.0 * value / times, 2.0
end
end
def test_normal
n = 10_000
values = Array.new(n) { @tester.normal(mean: 150.0, standard_deviation: 100.0) }
mean = values.reduce(:+) / n.to_f
variance = values.inject(0) { |var, value| var + (value - mean)**2 } / (n - 1).to_f
std_dev = Math.sqrt variance
assert_in_delta 150.0, mean, 5.0
assert_in_delta 100.0, std_dev, 3.0
end
def test_between
deterministically_verify -> { @tester.between(from: -50, to: 50) }, depth: 5 do |random_number|
assert_operator random_number, :>=, -50, "Expected >= -50, but got #{random_number}"
assert_operator random_number, :<=, 50, "Expected <= 50, but got #{random_number}"
end
end
def test_within
deterministically_verify -> { @tester.within(range: -50..50) }, depth: 5 do |random_number|
assert_operator random_number, :>=, -50, "Expected >= -50, but got #{random_number}"
assert_operator random_number, :<=, 50, "Expected <= 50, but got #{random_number}"
end
end
def test_positive
deterministically_verify -> { @tester.positive(from: 1, to: 100) }, depth: 5 do |random_number|
assert_operator random_number, :>=, 1, "Expected >= 1, but got #{random_number}"
assert_operator random_number, :<=, 100, "Expected <= 100, but got #{random_number}"
end
end
def test_negative
deterministically_verify -> { @tester.negative(from: -1, to: -100) }, depth: 5 do |random_number|
assert_operator random_number, :<=, -1, "Expected <= -1, but got #{random_number}"
assert_operator random_number, :>=, -100, "Expected >= -100, but got #{random_number}"
end
end
def test_force_positive
random_number = @tester.positive(from: -1, to: -100)
assert_operator random_number, :>=, 1, "Expected >= 1, but got #{random_number}"
assert_operator random_number, :<=, 100, "Expected <= 100, but got #{random_number}"
end
def test_force_negative
random_number = @tester.negative(from: 1, to: 100)
assert_operator random_number, :<=, -1, "Expected <= -1, but got #{random_number}"
assert_operator random_number, :>=, -100, "Expected >= -100, but got #{random_number}"
end
def test_parameters_order
random_number = @tester.between(from: 100, to: 1)
assert_operator random_number, :>=, 1, "Expected >= 1, but got #{random_number}"
assert_operator random_number, :<=, 100, "Expected <= 100, but got #{random_number}"
end
def test_hexadecimal
assert_match(/[0-9a-f]{4}/, @tester.hexadecimal(digits: 4))
assert_match(/[0-9a-f]{7}/, @tester.hexadecimal(digits: 7))
end
def test_hexadecimal_range
random_hex = @tester.hexadecimal(digits: 1000)
expected_range = Array('0'..'9') + Array('a'..'f')
expected_range.each { |char| assert_include(random_hex, char) }
end
def test_binary
assert_match(/^[0-1]{4}$/, @tester.binary(digits: 4))
assert_match(/^[0-1]{8}$/, @tester.binary(digits: 8))
assert_match(/^[0-1]{4}$/, @tester.binary)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_currency.rb | test/faker/default/test_faker_currency.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerCurrency < Test::Unit::TestCase
def setup
@tester = Faker::Currency
end
def test_name
assert_match(/[\w' ]+/, @tester.name)
end
def test_code
assert_match(/[A-Z]{3}/, @tester.code)
end
def test_symbol
assert_instance_of String, @tester.symbol
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_science.rb | test/faker/default/test_faker_science.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerScience < Test::Unit::TestCase
def setup
@tester = Faker::Science
end
def test_science
assert_match(/\w+/, @tester.science)
assert_match(/\w+/, @tester.science(:empirical))
assert_match(/\w+/, @tester.science(:formal))
assert_match(/\w+/, @tester.science(:natural))
assert_match(/\w+/, @tester.science(:social))
assert_match(/\w+/, @tester.science(:basic))
assert_match(/\w+/, @tester.science(:applied))
assert_match(/\w+/, @tester.science(:empirical, :natural))
assert_match(/\w+/, @tester.science(:empirical, :social))
assert_match(/\w+/, @tester.science(:empirical, :natural, :basic))
assert_match(/\w+/, @tester.science(:empirical, :natural, :applied))
assert_match(/\w+/, @tester.science(:empirical, :social, :basic))
assert_match(/\w+/, @tester.science(:empirical, :social, :applied))
assert_match(/\w+/, @tester.science(:empirical, :basic))
assert_match(/\w+/, @tester.science(:empirical, :applied))
assert_match(/\w+/, @tester.science(:formal, :basic))
assert_match(/\w+/, @tester.science(:formal, :applied))
end
def test_element
assert_match(/\w+/, @tester.element)
end
def test_element_symbol
assert_match(/\w{1,2}/, @tester.element)
end
def test_element_state
assert_match(/\w+/, @tester.element_state)
end
def test_element_subcategory
assert_match(/\w+/, @tester.element_subcategory)
end
def test_scientist
assert_match(/\w+/, @tester.scientist)
end
def test_modifier
assert_match(/\w+/, @tester.modifier)
end
def test_tool
assert_match(/\w+/, @tester.tool)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_bank.rb | test/faker/default/test_faker_bank.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerBank < Test::Unit::TestCase
IBAN_HEADER = '[A-Z]{2}[0-9]{2}'
def setup
@tester = Faker::Bank
end
def test_routing_number
routing_number = Faker::Bank.routing_number
checksum = (
7 * (routing_number[0].to_i + routing_number[3].to_i + routing_number[6].to_i) +
3 * (routing_number[1].to_i + routing_number[4].to_i + routing_number[7].to_i) +
9 * (routing_number[2].to_i + routing_number[5].to_i + routing_number[8].to_i)
) % 10
assert_match(/\d{9}/, routing_number)
assert_equal(0, checksum)
end
def test_routing_number_with_format
fraction = Faker::Bank.routing_number_with_format
assert_match(/\d{1,2}-\d{1,4}\/\d{1,4}/, fraction)
end
def test_bsb_number
assert_match(/\d{6}/, Faker::Bank.bsb_number)
end
def test_account_number
assert_match(/\d{10}/, Faker::Bank.account_number)
assert_match(/\d{12}/, Faker::Bank.account_number(digits: 12))
assert_match(/\d{100}/, Faker::Bank.account_number(digits: 100))
end
def test_name
assert_match(/(\w+\.? ?){2,3}/, @tester.name)
end
def test_swift_bic
assert_match(/(\w+\.? ?){2,3}/, @tester.swift_bic)
end
# This test makes sure there are no collisions in BIC number pool
# https://github.com/faker-ruby/faker/pull/2130#issuecomment-703213837
# def test_swift_bic_collission
# 10.times do
# samplebic1 = @tester.swift_bic
# samplebic2 = @tester.swift_bic
# refute_equal samplebic1, samplebic2
# end
# end
def test_iban_country_code
assert_match(/^[A-Z]{2}$/, @tester.iban_country_code)
end
def test_iban_default
assert_match(/^GB\d{2}[A-Z]{4}\d{14}$/, @tester.iban)
end
def test_iban_rand_country
assert_match(/^[A-Z]{2}\d{2}[A-Z\d]{10,30}$/, @tester.iban(country_code: nil))
end
def test_iban_checksum
# Sourced IBANs from https://www.iban.com/structure
accounts = {
AL: { account: '202111090000000001234567', check_digit: '35' }, # AL35202111090000000001234567
BY: { account: 'AKBB10100000002966000000', check_digit: '86' }, # BY86AKBB10100000002966000000
CY: { account: '002001950000357001234567', check_digit: '21' }, # CY21002001950000357001234567
DO: { account: 'ACAU00000000000123456789', check_digit: '22' }, # DO22ACAU00000000000123456789
EG: { account: '0002000156789012345180002', check_digit: '80' }, # EG800002000156789012345180002
FR: { account: '30006000011234567890189', check_digit: '76' }, # FR7630006000011234567890189
GB: { account: 'BUKB20201555555555', check_digit: '33' }, # GB33BUKB20201555555555
HU: { account: '116000060000000012345676', check_digit: '93' }, # HU93116000060000000012345676
IT: { account: 'X0542811101000000123456', check_digit: '60' }, # IT60X0542811101000000123456
JO: { account: 'CBJO0000000000001234567890', check_digit: '71' }, # JO71CBJO0000000000001234567890
KW: { account: 'CBKU0000000000001234560101', check_digit: '81' }, # KW81CBKU0000000000001234560101
LB: { account: '000700000000123123456123', check_digit: '92' }, # LB92000700000000123123456123
MD: { account: 'EX000000000001234567', check_digit: '21' }, # MD21EX000000000001234567
NL: { account: 'ABNA0123456789', check_digit: '02' }, # NL02ABNA0123456789
PL: { account: '105000997603123456789123', check_digit: '10' }, # PL10105000997603123456789123
QA: { account: 'QNBA000000000000693123456', check_digit: '54' }, # QA54QNBA000000000000693123456
RU: { account: '04452560040702810412345678901', check_digit: '02' }, # RU0204452560040702810412345678901
SC: { account: 'MCBL01031234567890123456USD', check_digit: '74' }, # SC74MCBL01031234567890123456USD
TR: { account: '0010009999901234567890', check_digit: '32' }, # TR320010009999901234567890
UA: { account: '3052992990004149123456789', check_digit: '90' }, # UA903052992990004149123456789
VG: { account: 'ABVI0000000123456789', check_digit: '07' } # VG07ABVI0000000123456789
}
accounts.each do |country_code, data|
assert_equal data[:check_digit], @tester.send(:iban_checksum, country_code.to_s, data[:account])
end
end
# Andorra
def test_iban_ad
account = @tester.iban(country_code: 'ad')
assert_equal(24, account.length)
assert_match(/^#{IBAN_HEADER}\d{8}[A-Z0-9]{12}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# United Arab Emirates
def test_iban_ae
account = @tester.iban(country_code: 'ae')
assert_equal(23, account.length)
assert_match(/^#{IBAN_HEADER}\d{19}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Albania
def test_iban_al
account = @tester.iban(country_code: 'al')
assert_equal(28, account.length)
assert_match(/^#{IBAN_HEADER}\d{8}[A-Z0-9]{16}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Austria
def test_iban_at
account = @tester.iban(country_code: 'at')
assert_equal(20, account.length)
assert_match(/^#{IBAN_HEADER}\d{16}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Azerbaijan, Republic of
def test_iban_az
account = @tester.iban(country_code: 'az')
assert_equal(28, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}[A-Z0-9]{20}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Bosnia
def test_iban_ba
account = @tester.iban(country_code: 'ba')
assert_equal(20, account.length)
assert_match(/^#{IBAN_HEADER}\d{16}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Belgium
def test_iban_be
account = @tester.iban(country_code: 'be')
assert_equal(16, account.length)
assert_match(/^#{IBAN_HEADER}\d{12}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Bulgaria
def test_iban_bg
account = @tester.iban(country_code: 'bg')
assert_equal(22, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}\d{6}[A-Z0-9]{8}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Bahrain
def test_iban_bh
account = @tester.iban(country_code: 'bh')
assert_equal(22, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}[A-Z0-9]{14}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Brazil
def test_iban_br
account = @tester.iban(country_code: 'br')
assert_equal(29, account.length)
assert_match(/^#{IBAN_HEADER}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z]{1}[A-Z0-9]{1}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Switzerland
def test_iban_ch
account = @tester.iban(country_code: 'ch')
assert_equal(21, account.length)
assert_match(/^#{IBAN_HEADER}\d{5}[A-Z0-9]{12}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Costa Rica
def test_iban_cr
account = @tester.iban(country_code: 'cr')
assert_equal(22, account.length)
assert_match(/^#{IBAN_HEADER}0\d{3}\d{14}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Cyprus
def test_iban_cy
account = @tester.iban(country_code: 'cy')
assert_equal(28, account.length)
assert_match(/^#{IBAN_HEADER}\d{8}[A-Z0-9]{16}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Czech Republic
def test_iban_cz
account = @tester.iban(country_code: 'cz')
assert_equal(24, account.length)
assert_match(/^#{IBAN_HEADER}\d{20}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Germany
def test_iban_de
account = @tester.iban(country_code: 'de')
assert_equal(22, account.length)
assert_match(/^#{IBAN_HEADER}\d{18}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Denmark
def test_iban_dk
account = @tester.iban(country_code: 'dk')
assert_equal(18, account.length)
assert_match(/^#{IBAN_HEADER}\d{14}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Dominican Republic
def test_iban_do
account = @tester.iban(country_code: 'do')
assert_equal(28, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}\d{20}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Estonia
def test_iban_ee
account = @tester.iban(country_code: 'ee')
assert_equal(20, account.length)
assert_match(/^#{IBAN_HEADER}\d{16}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Spain
def test_iban_es
account = @tester.iban(country_code: 'es')
assert_equal(24, account.length)
assert_match(/^#{IBAN_HEADER}\d{20}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Finland
def test_iban_fi
account = @tester.iban(country_code: 'fi')
assert_equal(18, account.length)
assert_match(/^#{IBAN_HEADER}\d{14}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Faroe Islands
def test_iban_fo
account = @tester.iban(country_code: 'fo')
assert_equal(18, account.length)
assert_match(/^#{IBAN_HEADER}\d{14}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# France
def test_iban_fr
deterministically_verify -> { @tester.iban(country_code: 'fr') }, depth: 5 do |account|
assert_equal(27, account.length)
assert_match(/^#{IBAN_HEADER}\d{10}[A-Z0-9]{11}\d{2}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
end
# United Kingdom
def test_iban_gb
deterministically_verify -> { @tester.iban(country_code: 'gb') }, depth: 5 do |account|
assert_equal(22, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}\d{14}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
end
# Georgia
def test_iban_ge
deterministically_verify -> { @tester.iban(country_code: 'ge') }, depth: 5 do |account|
assert_equal(22, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{2}\d{16}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
end
# Gibraltar
def test_iban_gi
account = @tester.iban(country_code: 'gi')
assert_equal(23, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}[A-Z0-9]{15}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Greenland
def test_iban_gl
account = @tester.iban(country_code: 'gl')
assert_equal(18, account.length)
assert_match(/^#{IBAN_HEADER}\d{14}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Greece
def test_iban_gr
account = @tester.iban(country_code: 'gr')
assert_equal(27, account.length)
assert_match(/^#{IBAN_HEADER}\d{7}[A-Z0-9]{16}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Guatemala
def test_iban_gt
account = @tester.iban(country_code: 'gt')
assert_equal(28, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z0-9]{4}\d{2}\d{2}[A-Z0-9]{16}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Croatia
def test_iban_hr
account = @tester.iban(country_code: 'hr')
assert_equal(21, account.length)
assert_match(/^#{IBAN_HEADER}\d{17}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Hungary
def test_iban_hu
account = @tester.iban(country_code: 'hu')
assert_equal(28, account.length)
assert_match(/^#{IBAN_HEADER}\d{24}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Ireland
def test_iban_ie
account = @tester.iban(country_code: 'ie')
assert_equal(22, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}\d{14}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Israel
def test_iban_il
account = @tester.iban(country_code: 'il')
assert_equal(23, account.length)
assert_match(/^#{IBAN_HEADER}\d{19}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Iceland
def test_iban_is
account = @tester.iban(country_code: 'is')
assert_equal(26, account.length)
assert_match(/^#{IBAN_HEADER}\d{22}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Italy
def test_iban_it
account = @tester.iban(country_code: 'it')
assert_equal(27, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]\d{10}[A-Z0-9]{12}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Kuwait
def test_iban_kw
account = @tester.iban(country_code: 'kw')
assert_equal(30, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}\d{22}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Kazakhstan
def test_iban_kz
account = @tester.iban(country_code: 'kz')
assert_equal(20, account.length)
assert_match(/^#{IBAN_HEADER}[0-9]{3}[A-Z0-9]{13}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Lebanon
def test_iban_lb
account = @tester.iban(country_code: 'lb')
assert_equal(28, account.length)
assert_match(/^#{IBAN_HEADER}\d{4}[A-Z0-9]{20}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Liechtenstein
def test_iban_li
account = @tester.iban(country_code: 'li')
assert_equal(21, account.length)
assert_match(/^#{IBAN_HEADER}\d{5}[A-Z0-9]{12}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Lithuania
def test_iban_lt
account = @tester.iban(country_code: 'lt')
assert_equal(20, account.length)
assert_match(/^#{IBAN_HEADER}\d{16}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Luxembourg
def test_iban_lu
account = @tester.iban(country_code: 'lu')
assert_equal(20, account.length)
assert_match(/^#{IBAN_HEADER}\d{3}[A-Z0-9]{13}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Latvia
def test_iban_lv
account = @tester.iban(country_code: 'lv')
assert_equal(21, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}[A-Z0-9]{13}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Monaco
def test_iban_mc
account = @tester.iban(country_code: 'mc')
assert_equal(27, account.length)
assert_match(/^#{IBAN_HEADER}\d{10}[A-Z0-9]{11}\d{2}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Moldova
def test_iban_md
account = @tester.iban(country_code: 'md')
assert_equal(24, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{2}[A-Z0-9]{18}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Montenegro
def test_iban_me
account = @tester.iban(country_code: 'me')
assert_equal(22, account.length)
assert_match(/^#{IBAN_HEADER}\d{18}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Macedonia
def test_iban_mk
account = @tester.iban(country_code: 'mk')
assert_equal(19, account.length)
assert_match(/^#{IBAN_HEADER}\d{3}[A-Z0-9]{10}\d{2}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Mauritania
def test_iban_mr
account = @tester.iban(country_code: 'mr')
assert_equal(27, account.length)
assert_match(/^#{IBAN_HEADER}\d{23}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Malta
def test_iban_mt
account = @tester.iban(country_code: 'mt')
assert_equal(31, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}\d{5}[A-Z0-9]{18}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Mauritius
def test_iban_mu
account = @tester.iban(country_code: 'mu')
assert_equal(30, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}\d{19}[A-Z]{3}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Netherlands
def test_iban_nl
account = @tester.iban(country_code: 'nl')
assert_equal(18, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}\d{10}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Norway
def test_iban_no
account = @tester.iban(country_code: 'no')
assert_equal(15, account.length)
assert_match(/^#{IBAN_HEADER}\d{11}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Pakistan
def test_iban_pk
account = @tester.iban(country_code: 'pk')
assert_equal(24, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}[A-Z0-9]{16}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Poland
def test_iban_pl
account = @tester.iban(country_code: 'pl')
assert_equal(28, account.length)
assert_match(/^#{IBAN_HEADER}\d{8}[A-Z0-9]{16}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Palestinian Territory, Occupied
def test_iban_ps
account = @tester.iban(country_code: 'ps')
assert_equal(29, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}[A-Z0-9]{21}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Portugal
def test_iban_pt
account = @tester.iban(country_code: 'pt')
assert_equal(25, account.length)
assert_match(/^#{IBAN_HEADER}\d{21}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Qatar
def test_iban_qa
account = @tester.iban(country_code: 'qa')
assert_equal(29, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}[A-Z0-9]{21}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Romania
def test_iban_ro
account = @tester.iban(country_code: 'ro')
assert_equal(24, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}[A-Z0-9]{16}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Serbia
def test_iban_rs
account = @tester.iban(country_code: 'rs')
assert_equal(22, account.length)
assert_match(/^#{IBAN_HEADER}\d{18}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Saudi Arabia
def test_iban_sa
account = @tester.iban(country_code: 'sa')
assert_equal(24, account.length)
assert_match(/^#{IBAN_HEADER}\d{2}[A-Z0-9]{18}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Sweden
def test_iban_se
account = @tester.iban(country_code: 'se')
assert_equal(24, account.length)
assert_match(/^#{IBAN_HEADER}\d{20}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Slovenia
def test_iban_si
account = @tester.iban(country_code: 'si')
assert_equal(19, account.length)
assert_match(/^#{IBAN_HEADER}\d{15}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Slovakia
def test_iban_sk
account = @tester.iban(country_code: 'sk')
assert_equal(24, account.length)
assert_match(/^#{IBAN_HEADER}\d{20}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# San Marino
def test_iban_sm
account = @tester.iban(country_code: 'sm')
assert_equal(27, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]\d{10}[A-Z0-9]{12}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Timor-Leste
def test_iban_tl
account = @tester.iban(country_code: 'tl')
assert_equal(23, account.length)
assert_match(/^#{IBAN_HEADER}\d{19}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Tunisia
def test_iban_tn
account = @tester.iban(country_code: 'tn')
assert_equal(24, account.length)
assert_match(/^#{IBAN_HEADER}\d{20}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Turkey
def test_iban_tr
account = @tester.iban(country_code: 'tr')
assert_equal(26, account.length)
assert_match(/^#{IBAN_HEADER}\d{5}[A-Z0-9]{17}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Ukraine
def test_iban_ua
account = @tester.iban(country_code: 'ua')
assert_equal(29, account.length)
assert_match(/^#{IBAN_HEADER}\d{25}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Virgin Islands, British
def test_iban_vg
account = @tester.iban(country_code: 'vg')
assert_equal(24, account.length)
assert_match(/^#{IBAN_HEADER}[A-Z]{4}\d{16}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
# Kosovo, Republic of
def test_iban_xk
account = @tester.iban(country_code: 'xk')
assert_equal(20, account.length)
assert_match(/^#{IBAN_HEADER}\d{16}$/, account)
assert valid_iban_checksum?(account), 'IBAN checksum is invalid'
end
def test_iban_invalid
assert_raise ArgumentError.new('Could not find iban details for bad') do
@tester.iban(country_code: 'bad')
end
end
private
# https://en.wikipedia.org/wiki/International_Bank_Account_Number#Validating_the_IBAN
def valid_iban_checksum?(iban)
# Check digit should be between 2..98
return false unless (2..98).include? iban[2, 2].to_i
iban = (iban[4..] + iban[0..3]).upcase
iban = iban.chars.map { |char| char =~ /[A-Z]/ ? char.ord - 55 : char }.join
iban.to_i % 97 == 1
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_job_locale.rb | test/faker/default/test_faker_job_locale.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerJobLocale < Test::Unit::TestCase
def setup
Faker::Config.locale = 'en-AU'
@tester = Faker::Job
end
def teardown
Faker::Config.locale = nil
end
def test_locale_without_jobs_defaults_to_en
assert_match(/(\w+\.? ?)/, @tester.position)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_dessert.rb | test/faker/default/test_faker_dessert.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerDessert < Test::Unit::TestCase
def setup
@tester = Faker::Dessert
end
def test_variety
assert_match(/\w+/, @tester.variety)
end
def test_topping
assert_match(/\w+/, @tester.topping)
end
def test_flavor
assert_match(/\w+/, @tester.flavor)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_html.rb | test/faker/default/test_faker_html.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerHTML < Test::Unit::TestCase
def setup
@tester = Faker::HTML
end
def test_heading
header = @tester.heading
level = header.match(/<h(\d)>/i)[1].to_i
open_tag = "<h#{level}>"
close_tag = "</h#{level}>"
assert(header.start_with?(open_tag))
assert(header.end_with?(close_tag))
end
def test_paragraph
assert_match(/<p>.+<\/p>/, @tester.paragraph)
end
def test_emphasis
assert_match(/<em>.*<\/em>/, @tester.emphasis)
end
def test_ordered_list
assert_match(/<ol>.*<\/ol>/m, @tester.ordered_list)
end
def test_unordered_list
assert_match(/<ul>.*<\/ul>/m, @tester.unordered_list)
end
def test_code
assert_match(/<code>.+<\/code>/, @tester.code)
end
def test_table
table_html = @tester.table
assert(table_html.start_with?('<table>'))
assert(table_html.end_with?('</table>'))
assert_equal(1, count_occurrences(table_html, '<thead>'))
assert_equal(1, count_occurrences(table_html, '<tbody>'))
assert_equal(1, count_occurrences(table_html, '<tfoot>'))
assert_equal(3, count_occurrences(table_html, '<th>'))
assert_equal(5, count_occurrences(table_html, '<tr>'))
assert_equal(12, count_occurrences(table_html, '<td>'))
end
def test_script
assert_match(/<script src=".+"><\/script>/, @tester.script)
end
def test_link
assert_match(/<link rel=".+" href=".+">/, @tester.link)
assert_match(/<link rel="alternate" href=".+">/, @tester.link(rel: 'alternate'))
end
def test_element
assert_match(/<div .+>.+<\/div>/, @tester.element)
assert_match(/<span .+>.+<\/span>/, @tester.element(tag: 'span'))
end
def test_random
assert_match(/<[^>]+>.*<\/[^>]+>|<link[^>]+>/, @tester.random)
end
def test_sandwich
sandwich = @tester.sandwich(sentences: 2, repeat: 3)
assert_match(/<h\d>[\w\s]+<\/h\d>/i, sandwich)
assert_match(/<p>[\w\s.,!?]+<\/p>/i, sandwich)
assert_match(/<[^>]+>[\w\s.,!?]*<\/[^>]+>/i, sandwich)
end
private
def count_occurrences(text, substring)
text.scan(substring).length
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_device.rb | test/faker/default/test_faker_device.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerDevice < Test::Unit::TestCase
def setup
@tester = Faker::Device
end
def test_model_name
assert_match(/\w+/, @tester.model_name)
end
def test_platform
assert_match(/\w+/, @tester.platform)
end
def test_version
assert_predicate @tester.version, :positive?
assert_operator @tester.version, :<=, 1000
end
def test_build_number
assert_predicate @tester.build_number, :positive?
assert_operator @tester.build_number, :<=, 500
end
def test_manufacturer
assert_match(/\w+/, @tester.manufacturer)
end
def test_serial
assert_match(/\w+/, @tester.serial)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_phone_number.rb | test/faker/default/test_faker_phone_number.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerPhone < Test::Unit::TestCase
def setup
@tester = Faker::PhoneNumber
@phone_with_country_code_regex = /\A\+(\s|\d|-|\(|\)|x|\.)*\z/
end
def test_phone_number_min_1_max_3_length
assert_match(/^\+\d{1,3}$/, @tester.country_code)
end
def test_phone_number_with_country_code
assert_match(@phone_with_country_code_regex, @tester.phone_number_with_country_code)
end
def test_area_code
assert_match(/\d{1,3}$/, @tester.area_code)
end
def test_exchange_code
assert_match(/\d{1,3}$/, @tester.exchange_code)
end
def test_cell_phone_with_country_code
assert_match(@phone_with_country_code_regex, @tester.cell_phone_with_country_code)
end
def test_cell_phone_in_e164
assert_match(@phone_with_country_code_regex, @tester.cell_phone_in_e164)
end
def test_subscriber_number_with_no_arguments
assert_match(/\d{4}$/, @tester.subscriber_number)
end
def test_subscriber_number_with_length_argument
assert_match(/\d{2}$/, @tester.subscriber_number(length: 2))
end
def test_subscriber_number_with_invalid_length_argument
exception = assert_raise(ArgumentError) do
@tester.subscriber_number(length: '2')
end
assert_equal('length must be an Integer and be lesser than 10', exception.message)
end
def test_subscriber_number_with_length_greater_than_10
exception = assert_raise(ArgumentError) do
@tester.subscriber_number(length: 11)
end
assert_equal('length must be an Integer and be lesser than 10', exception.message)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_business.rb | test/faker/default/test_faker_business.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerBusiness < Test::Unit::TestCase
def setup
@tester = Faker::Business
@credit_card_number_list = I18n.translate('faker.business.credit_card_numbers')
@credit_card_types = I18n.translate('faker.business.credit_card_types')
@minimum_expiry_date = ::Date.today + 365
@maximum_expiry_date = ::Date.today + (365 * 4)
end
def test_credit_card_number
number1 = @tester.credit_card_number
number2 = @tester.credit_card_number
assert_includes @credit_card_number_list, number1
assert_includes @credit_card_number_list, number2
end
def test_credit_card_expiry_date
date1 = @tester.credit_card_expiry_date
date2 = @tester.credit_card_expiry_date
assert date1.between?(@minimum_expiry_date, @maximum_expiry_date)
assert date2.between?(@minimum_expiry_date, @maximum_expiry_date)
end
def test_credit_card_type
type1 = @tester.credit_card_type
type2 = @tester.credit_card_type
assert_includes @credit_card_types, type1
assert_includes @credit_card_types, type2
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_json.rb | test/faker/default/test_faker_json.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerJson < Test::Unit::TestCase
require 'json'
def test_simple_json_lenght
expected_result_length = JSON.parse(simple_json).flatten.length
assert_same(expected_result_length, 6)
end
def test_nested_json_length
result = Faker::Json.add_depth_to_json(json: simple_json, options: { key: 'Name.first_name', value: 'Name.first_name' })
first_json_length = JSON.parse(result).flatten[1].flatten.length
second_json_length = JSON.parse(result).flatten[3].flatten.length
third_json_length = JSON.parse(result).flatten[5].flatten.length
assert_same(first_json_length, 6)
assert_same(second_json_length, 6)
assert_same(third_json_length, 6)
end
def test_nested_json_width_length
json = Faker::Json.add_depth_to_json(json: nested_json, width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
first_json_length = JSON.parse(json).flatten[1].flatten[1].flatten.length
second_json_length = JSON.parse(json).flatten[3].flatten[3].flatten.length
assert_same(first_json_length, 6)
assert_same(second_json_length, 6)
end
def simple_json
Faker::Json.shallow_json(options: { key: 'Name.first_name', value: 'Name.first_name' })
end
def nested_json
Faker::Json.add_depth_to_json(json: simple_json, width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_hacker_talk.rb | test/faker/default/test_faker_hacker_talk.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerHacker < Test::Unit::TestCase
def setup
@hacker = Faker::Hacker
@phrases = @hacker.phrases
end
def test_phrases
assert_equal(8, @phrases.size)
@phrases.each do |phrase|
refute_empty phrase.to_s
end
end
def test_noun
assert_match(/\w+/, @hacker.noun)
end
def test_abbreviation
assert_match(/\w+/, @hacker.abbreviation)
end
def test_adjective
assert_match(/\w+/, @hacker.adjective)
end
def test_verb
assert_match(/\w+/, @hacker.verb)
end
def test_ingverb
assert_match(/\w+/, @hacker.ingverb)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_unique_generator.rb | test/faker/default/test_faker_unique_generator.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerUniqueGenerator < Test::Unit::TestCase
def test_generates_unique_values
generator = Faker::UniqueGenerator.new(Faker::Base, 10_000)
result = [generator.rand_in_range(1, 2), generator.rand_in_range(1, 2)]
assert_equal([1, 2], result.sort)
end
def test_respond_to_missing
stubbed_generator = Object.new
generator = Faker::UniqueGenerator.new(stubbed_generator, 3)
assert(generator.send(:respond_to_missing?, 'faker_address'))
refute(generator.send(:respond_to_missing?, 'address'))
end
def test_returns_error_when_retries_exceeded
stubbed_generator = Object.new
def stubbed_generator.test
1
end
generator = Faker::UniqueGenerator.new(stubbed_generator, 3)
generator.test
assert_raises Faker::UniqueGenerator::RetryLimitExceeded do
generator.test
end
end
def test_includes_field_name_in_error
stubbed_generator = Object.new
def stubbed_generator.my_field
1
end
generator = Faker::UniqueGenerator.new(stubbed_generator, 3)
generator.my_field
assert_raise_message 'Retry limit exceeded for my_field' do
generator.my_field
end
end
def test_clears_unique_values
stubbed_generator = Object.new
def stubbed_generator.test
1
end
generator = Faker::UniqueGenerator.new(stubbed_generator, 3)
assert_equal(1, generator.test)
assert_raises Faker::UniqueGenerator::RetryLimitExceeded do
generator.test
end
generator.clear
assert_equal(1, generator.test)
assert_raises Faker::UniqueGenerator::RetryLimitExceeded do
generator.test
end
generator.clear
assert_equal(1, generator.test)
end
def test_clears_unique_values_for_all_generators
stubbed_generator = Object.new
def stubbed_generator.test
1
end
stubbed_generator2 = Object.new
def stubbed_generator2.test
2
end
generator1 = Faker::UniqueGenerator.new(stubbed_generator, 3)
generator2 = Faker::UniqueGenerator.new(stubbed_generator2, 3)
assert_equal(1, generator1.test)
assert_equal(2, generator2.test)
assert_raises Faker::UniqueGenerator::RetryLimitExceeded do
generator1.test
end
assert_raises Faker::UniqueGenerator::RetryLimitExceeded do
generator2.test
end
Faker::UniqueGenerator.clear
assert_nothing_raised Faker::UniqueGenerator::RetryLimitExceeded do
assert_equal(1, generator1.test)
assert_equal(2, generator2.test)
end
assert_raises Faker::UniqueGenerator::RetryLimitExceeded do
generator1.test
end
assert_raises Faker::UniqueGenerator::RetryLimitExceeded do
generator2.test
end
Faker::UniqueGenerator.clear
assert_nothing_raised Faker::UniqueGenerator::RetryLimitExceeded do
assert_equal(1, generator1.test)
assert_equal(2, generator2.test)
end
end
def test_thread_safety
stubbed_generator = Object.new
def stubbed_generator.test
1
end
generator = Faker::UniqueGenerator.new(stubbed_generator, 3)
Thread.new do
assert_equal(1, generator.test)
assert_raises Faker::UniqueGenerator::RetryLimitExceeded do
generator.test
end
end.join
Thread.new do
assert_equal(1, generator.test)
end.join
assert_equal(1, generator.test)
assert_raises Faker::UniqueGenerator::RetryLimitExceeded do
generator.test
end
Thread.new do
generator.clear
end.join
assert_raises Faker::UniqueGenerator::RetryLimitExceeded do
generator.test
end
generator.clear
assert_equal(1, generator.test)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_cannabis.rb | test/faker/default/test_faker_cannabis.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerCannabis < Test::Unit::TestCase
def setup
Faker::Config.locale = nil
end
def test_strain
deterministically_verify(-> { Faker::Cannabis.strain }) { |result| assert_match(/\w+/, result) }
end
def test_cannabinoid_abbreviation
deterministically_verify(-> { Faker::Cannabis.cannabinoid_abbreviation }) { |result| assert_match(/\w+/, result) }
end
def test_cannabinoid
deterministically_verify(-> { Faker::Cannabis.cannabinoid }) { |result| assert_match(/\w+/, result) }
end
def test_terpene
deterministically_verify(-> { Faker::Cannabis.terpene }) { |result| assert_match(/\w+/, result) }
end
def test_medical_use
deterministically_verify(-> { Faker::Cannabis.medical_use }) { |result| assert_match(/\w+/, result) }
end
def test_health_benefit
deterministically_verify(-> { Faker::Cannabis.health_benefit }) { |result| assert_match(/\w+/, result) }
end
def test_category
deterministically_verify(-> { Faker::Cannabis.category }) { |result| assert_match(/\w+/, result) }
end
def test_type
deterministically_verify(-> { Faker::Cannabis.type }) { |result| assert_match(/\w+/, result) }
end
def test_buzzword
deterministically_verify(-> { Faker::Cannabis.buzzword }) { |result| assert_match(/\w+/, result) }
end
def test_brand
deterministically_verify(-> { Faker::Cannabis.brand }) { |result| assert_match(/\w+/, result) }
end
def test_locales
[nil, 'en', 'de'].each do |_locale_name|
Faker::Config.locale = 'de'
assert_kind_of String, Faker::Cannabis.strain
assert_kind_of String, Faker::Cannabis.cannabinoid_abbreviation
assert_kind_of String, Faker::Cannabis.cannabinoid
assert_kind_of String, Faker::Cannabis.terpene
assert_kind_of String, Faker::Cannabis.medical_use
assert_kind_of String, Faker::Cannabis.health_benefit
assert_kind_of String, Faker::Cannabis.category
assert_kind_of String, Faker::Cannabis.type
assert_kind_of String, Faker::Cannabis.buzzword
assert_kind_of String, Faker::Cannabis.brand
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_source.rb | test/faker/default/test_faker_source.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerSource < Test::Unit::TestCase
def setup
@tester = Faker::Source
end
def test_hello_world_instance
assert_instance_of String, @tester.hello_world
end
def test_hello_world
assert_match "'Hello World!'", @tester.hello_world
end
def test_print_instance
assert_instance_of String, @tester.print
end
def test_print
assert_match "'some string'", @tester.print
end
def test_print_another_string
assert_match "'another string'", @tester.print(str: 'another string')
end
def test_print_invalid_lang
assert_raise(I18n::MissingTranslationData) { @tester.print(lang: :js) }
end
def test_print_1_to_10_instance
assert_instance_of String, @tester.print_1_to_10
end
def test_print_1_to_10_javascript
assert_match 'console.log(i);', @tester.print_1_to_10(lang: :javascript)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_measurement.rb | test/faker/default/test_faker_measurement.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerMeasurement < Test::Unit::TestCase
def setup
@tester = Faker::Measurement
end
def test_height
assert_match(/\d\s[a-z]/, @tester.height)
end
def length
assert_match(/\d\s[a-z]/, @tester.length(0))
end
def volume
singular_unit = @tester.volume('none')
plural_unit = @tester.volume('all')
custom_amount_float = @tester.volume(1.5)
custom_amount_integer = @tester.volume(276)
assert_match(/\A\D+[^s]\z/, singular_unit)
assert_match(/\A\D+s\z/, plural_unit)
assert_match(/\d\s[a-z]/, @tester.volume)
assert_match(/\d\s[a-z]+s\z/, custom_amount_float)
assert_match(/\d\s[a-z]+s\z/, custom_amount_integer)
end
def weight
assert_match(/\d\s[a-z]/, @tester.weight)
end
def metric_height
assert_match(/\d\s[a-z]/, @tester.metric_height)
end
def metric_length
assert_match(/\d\s[a-z]/, @tester.metric_length)
end
def metric_volume
assert_match(/\d\s[a-z]/, @tester.metric_volume)
end
def metric_weight
assert_match(/\d\s[a-z]/, @tester.metric_weight)
assert_match(/\d\s[a-z]/, @tester.metric_weight(1))
end
def test_invalid_amount_error
amount = 'hello world!'
assert_raise ArgumentError do
@tester.volume(amount: amount)
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_vehicle.rb | test/faker/default/test_faker_vehicle.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerVehicle < Test::Unit::TestCase
WORD_MATCH = /\w+\.?/
VIN_REGEX = /\A[A-HJ-NPR-Z0-9]{17}\z/
def setup
@tester = Faker::Vehicle
end
def test_vin
assert valid_vin?('11111111111111111') # known valid test string
assert valid_vin?('FAKERGEM5FAKERGEM') # valid checksum
refute valid_vin?('ABCDEFGH123456789') # invalid checksum
deterministically_verify -> { @tester.vin }, depth: 4 do |vin|
assert valid_vin?(vin)
end
end
def test_manufacturer
assert_match WORD_MATCH, @tester.manufacturer
end
def test_color
assert_match WORD_MATCH, @tester.color
end
def test_flexible_key
assert_equal(:vehicle, @tester.flexible_key)
end
def test_transmission
assert_match WORD_MATCH, @tester.transmission
end
def test_drive_type
assert_match WORD_MATCH, @tester.drive_type
end
def test_fuel_type
assert_match WORD_MATCH, @tester.fuel_type
end
def test_style
assert_match WORD_MATCH, @tester.style
end
def test_car_type
assert_match WORD_MATCH, @tester.car_type
end
def test_doors
doors_condition(@tester.doors)
end
def test_engine
assert_match(/\d Cylinder Engine/, @tester.engine)
end
def test_mileage
mileage = @tester.mileage(min: 5, max: 10)
assert mileage.between?(5, 10)
end
def test_license_plate
assert_match WORD_MATCH, @tester.license_plate
end
def test_license_plate_with_params
assert_match WORD_MATCH, @tester.license_plate(state_abbreviation: 'CA')
end
def test_make
assert_match WORD_MATCH, @tester.make
end
def test_model
assert_match WORD_MATCH, @tester.model
end
def test_model_with_make
assert_match WORD_MATCH, @tester.model(make_of_model: 'Toyota')
end
def test_make_and_model
assert_match WORD_MATCH, @tester.make_and_model
end
def test_door_count
doors_condition(@tester.door_count)
end
def test_car_options
car_options = @tester.car_options
assert car_options.length >= 5 && car_options.length < 10
end
def test_standard_specs
standard_specs = @tester.standard_specs
assert standard_specs.length >= 5 && standard_specs.length < 10
end
def test_version
assert_match WORD_MATCH, @tester.version
end
private
def doors_condition(doors)
assert_predicate doors, :positive?
assert_kind_of Integer, doors
end
def valid_vin?(vin)
if vin && vin =~ VIN_REGEX
total = 0
vin.chars.each_with_index do |char, index|
value = (char =~ /\A\d\z/ ? char.to_i : Faker::Vehicle::VIN_TRANSLITERATION[char.to_sym])
total += value * Faker::Vehicle::VIN_WEIGHT[index]
end
checksum = total % 11
checksum = 'X' if checksum == 10
return vin[8] == checksum.to_s
end
false
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_alphanum.rb | test/faker/default/test_alphanum.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerAlphanum < Test::Unit::TestCase
def setup
@tester = Faker::Alphanumeric
end
def alpha
assert_match(/[a-z]{5}/, @tester.alpha(number: 5))
end
def alphanum
assert_match(/[a-z0-9]{5}/, @tester.alphanumeric(number: 5))
end
def test_alphanumeric_invalid_min_alpha
assert_raise ArgumentError do
@tester.alphanumeric(number: 5, min_alpha: -1)
end
end
def test_alphanumeric_invalid_min_numeric
assert_raise ArgumentError do
@tester.alphanumeric(number: 5, min_numeric: -1)
end
end
def test_alphanumeric_with_invalid_mins
assert_raise ArgumentError do
@tester.alphanumeric(number: 5, min_numeric: 4, min_alpha: 3)
end
end
def test_alphanumeric_with_min_alpha
letters = @tester.alphanumeric(number: 5, min_alpha: 2).chars.map do |char|
char =~ /[[:alpha:]]/
end
assert_operator letters.compact.size, :>=, 2
end
def test_alphanumeric_with_min_numeric
numbers = @tester.alphanumeric(number: 5, min_numeric: 4).chars.map do |char|
char =~ /[[:digit:]]/
end
assert_operator numbers.compact.size, :>=, 4
end
def test_alphanumeric_with_min_alpha_and_min_numeric
deterministically_verify -> { @tester.alphanumeric(number: 10, min_alpha: 5, min_numeric: 5) } do |alphanum|
assert_equal 10, alphanum.size
assert_equal 5, alphanum.scan(/[[:alpha:]]/).size
assert_equal 5, alphanum.scan(/[[:digit:]]/).size
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_kpop.rb | test/faker/default/test_faker_kpop.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerKpop < Test::Unit::TestCase
def setup
@tester = Faker::Kpop
end
def test_i_groups
assert_match(/\w+/, @tester.i_groups)
end
def test_ii_groups
assert_match(/\w+/, @tester.ii_groups)
end
def test_iii_groups
assert_match(/\w+/, @tester.iii_groups)
end
def test_girl_groups
assert_match(/\w+/, @tester.girl_groups)
end
def test_boy_bands
assert_match(/\w+/, @tester.boy_bands)
end
def test_solo
assert_match(/\w+/, @tester.solo)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_time.rb | test/faker/default/test_faker_time.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerTime < Test::Unit::TestCase
TEN_HOURS = 36_000
def setup
@tester = Faker::Time
@time_ranges = Faker::Time::TIME_RANGES
end
def test_between_with_time_parameters
from = Time.at(0)
to = Time.at(2_145_945_600)
deterministically_verify -> { @tester.between(from: from, to: to) }, depth: 5 do |random_time|
assert_operator random_time, :>=, from, "Expected >= \"#{from}\", but got #{random_time}"
assert_operator random_time, :<=, to, "Expected <= \"#{to}\", but got #{random_time}"
end
end
def test_between_with_date_parameters
from = Time.at(0).to_date
to = Time.at(2_145_945_600).to_date
deterministically_verify -> { @tester.between(from: from, to: to) }, depth: 5 do |random_time|
assert_operator random_time.to_date, :>=, from, "Expected >= \"#{from}\", but got #{random_time}"
assert_operator random_time.to_date, :<=, to, "Expected <= \"#{to}\", but got #{random_time}"
end
end
def test_forward
today = Date.today
deterministically_verify -> { @tester.forward(days: 10) }, depth: 5 do |random_time|
assert_operator random_time, :>, today.to_time, "Expected > \"#{today}\", but got #{random_time}"
end
end
def test_backward
tomorrow = Date.today + 1
deterministically_verify -> { @tester.backward(days: 10) }, depth: 5 do |random_time|
assert_operator random_time, :<, tomorrow.to_time, "Expected < \"#{tomorrow}\", but got #{random_time}"
end
end
def test_invalid_period_error
from = Date.today
to = Date.today + 15
assert_raise ArgumentError do
@tester.between_dates(from, to, :invalid_period)
end
end
def test_return_types_are_time_objects
random_backward = @tester.backward(days: 5)
random_between_dates = @tester.between_dates(from: Date.today, to: Date.today + 5)
random_between_with_date_args = @tester.between(from: Date.today, to: Date.today + 5)
random_between_with_time_args = @tester.between(from: Time.now, to: Time.now + TEN_HOURS)
random_forward = @tester.forward(days: 5)
[
random_backward,
random_between_dates,
random_between_with_date_args,
random_between_with_time_args,
random_forward
].each do |result|
assert_kind_of Time, result, "Expected a Time object, but got #{result.class}"
end
end
def test_format
from = Date.today
to = Date.today + 15
format = :us
100.times do
period = @time_ranges.keys.to_a.sample
random_between_dates = @tester.between_dates(from: from, to: to, period: period, format: format)
random_backward = @tester.backward(days: 30, period: period, format: format)
random_between = @tester.between(from: from, to: to, format: format)
random_forward = @tester.forward(days: 30, period: period, format: format)
[random_backward, random_between, random_between_dates, random_forward].each do |result|
assert_kind_of String, result, "Expected a String, but got #{result.class}"
assert_nothing_raised 'Not a valid date string' do
date_format = '%m/%d/%Y %I:%M %p'
DateTime.strptime(result, date_format)
end
end
end
end
def test_time_period
# These dates are chosen to avoid any conflict with DST. When period is not strictly respected.
from = Date.parse('2018-09-01')
to = Date.parse('2018-09-15')
100.times do
period = @time_ranges.keys.to_a.sample
period_range = @time_ranges[period]
random_backward = @tester.backward(days: 30, period: period)
random_between = @tester.between_dates(from: from, to: to, period: period)
random_forward = @tester.forward(days: 30, period: period)
[random_backward, random_between, random_forward].each_with_index do |result, index|
assert_includes period_range, result.hour.to_i, "#{%i[random_backward random_between random_forward][index]}: \"#{result}\" expected to be included in Faker::Time::TIME_RANGES[:#{period}] range"
end
end
end
def test_between_in_short_window
# This test intentionally specifies a small window, because previous versions of between's
# default behavior would only constrain the date range, while allowing the time range to
# wander.
from = Time.utc(2018, 'jun', 12, 16, 14, 44)
to = Time.utc(2018, 'jun', 12, 16, 19, 52)
100.times do
random_between = @tester.between(from: from, to: to)
assert_operator random_between, :>=, from, "Expected >= \"#{from}\", but got #{random_between}"
assert_operator random_between, :<=, to, "Expected <= \"#{to}\", but got #{random_between}"
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_gender.rb | test/faker/default/test_faker_gender.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerGender < Test::Unit::TestCase
def setup
@tester = Faker::Gender
end
def test_type
assert_match(/\w+/, @tester.type)
end
def test_binary_type
assert_match(/\w+/, @tester.binary_type)
end
def test_short_binary_type
assert_match(/f|m/, @tester.short_binary_type)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_beer.rb | test/faker/default/test_faker_beer.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerBeer < Test::Unit::TestCase
def setup
@tester = Faker::Beer
end
def test_brand
assert_match(/(\w+\.? ?){2,3}/, @tester.brand)
end
def test_name
assert_match(/(\w+\.? ?){2,3}/, @tester.name)
end
def test_style
assert_match(/(\w+\.? ?){2,3}/, @tester.style) # TODO
end
def test_hop
assert_match(/(\w+\.? ?){2,3}/, @tester.hop)
end
def test_yeast
assert_match(/(\w+\.? ?){2,3}/, @tester.yeast)
end
def test_malts
assert_match(/(\w+\.? ?){2,3}/, @tester.malts)
end
def test_ibu
assert_match(/(\w+\.? ?){2,3}/, @tester.ibu)
end
def test_alcohol
assert_match(/(\w+\.? ?){2,3}/, @tester.alcohol)
end
def test_blg
assert_match(/(\w+\.? ?){2,3}/, @tester.blg)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_lorem.rb | test/faker/default/test_faker_lorem.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerLorem < Test::Unit::TestCase
def setup
@tester = Faker::Lorem
@standard_wordlist = I18n.translate('faker.lorem.words')
@complete_wordlist =
@standard_wordlist + I18n.translate('faker.lorem.supplemental')
end
def test_character
assert_equal(1, @tester.character.length)
end
def test_character_type
assert_instance_of String, @tester.character
end
def test_characters
assert_equal(255, @tester.characters.length)
end
def test_characters_negatives
assert_equal '', @tester.characters(number: -1)
assert_equal '', @tester.characters(number: (-2..-1))
assert_equal '', @tester.characters(number: [-1, -2])
end
def test_characters_with_args
deterministically_verify -> { @tester.characters(number: 500).length }, depth: 5 do |character_length|
assert_equal(500, character_length)
end
end
# Words delivered by a standard request should be on the standard wordlist.
def test_standard_words
@words = @tester.words(number: 1000)
assert_equal 1000, @words.length
@words.each { |w| assert_includes @standard_wordlist, w }
end
# Words requested from the supplemental list should all be in that list.
def test_supplemental_words
@words = @tester.words(number: 10_000, supplemental: true)
@words.each { |w| assert_includes @complete_wordlist, w }
end
# Faker::Lorem.word generates random word from standard wordlist
def test_word
@standard_wordlist = I18n.translate('faker.lorem.words')
deterministically_verify -> { @tester.word }, depth: 5 do |word|
assert_includes @standard_wordlist, word
end
end
def test_excluded_words_on_word
excluded_words_array = @tester.words(number: 2)
w = @tester.word(exclude_words: excluded_words_array)
assert_not_equal w, excluded_words_array[0]
assert_not_equal w, excluded_words_array[1]
end
def test_excluded_words_as_string_on_word
excluded_words_array = @tester.words(number: 2)
excluded_word_string = excluded_words_array.join(', ')
w = @tester.word(exclude_words: excluded_word_string)
assert_not_equal w, excluded_words_array[0]
assert_not_equal w, excluded_words_array[1]
end
def test_exact_sentence_word_count
assert_equal 2, @tester.sentence(word_count: 2, supplemental: false, random_words_to_add: 0).split.length
end
def test_exact_count_param
assert_equal(2, @tester.characters(number: 2).length)
assert_equal(2, @tester.words(number: 2).length)
assert_equal(2, @tester.sentences(number: 2).length)
assert_equal(2, @tester.paragraphs(number: 2).length)
end
def test_range_count_param
cs = @tester.characters(number: 2..5)
ws = @tester.words(number: 2..5)
ss = @tester.sentences(number: 2..5)
ps = @tester.paragraphs(number: 2..5)
assert(cs.length.between?(2, 5))
assert(ws.length.between?(2, 5))
assert(ss.length.between?(2, 5))
assert(ps.length.between?(2, 5))
end
def test_exclusive_range_count_param
cs = @tester.characters(number: 2...3)
ws = @tester.words(number: 2...3)
ss = @tester.sentences(number: 2...3)
ps = @tester.paragraphs(number: 2...3)
assert_equal(2, cs.length)
assert_equal(2, ws.length)
assert_equal(2, ss.length)
assert_equal(2, ps.length)
end
def test_array_count_param
cs = @tester.characters(number: [1, 4])
ws = @tester.words(number: [1, 4])
ss = @tester.sentences(number: [1, 4])
ps = @tester.paragraphs(number: [1, 4])
assert(cs.length == 1 || cs.length == 4)
assert(ws.length == 1 || ws.length == 4)
assert(ss.length == 1 || ss.length == 4)
assert(ps.length == 1 || ps.length == 4)
end
def test_words_with_large_count_params
exact = @tester.words(number: 500)
range = @tester.words(number: 250..500)
array = @tester.words(number: [250, 500])
assert_equal(500, exact.length)
assert(range.length.between?(250, 500))
assert(array.length == 250 || array.length == 500)
end
def test_multibyte
assert_kind_of String, @tester.multibyte
assert_includes %w[😀 ❤ 😡], @tester.multibyte
end
def test_paragraph_char_count
paragraph = @tester.paragraph_by_chars(number: 256)
assert_equal(256, paragraph.length)
end
def test_unique_with_already_set_values
values = ('a'..'z').to_a + ('0'..'9').to_a
@tester.unique.exclude(:character, [], values)
assert_raise(Faker::UniqueGenerator::RetryLimitExceeded) { @tester.unique.character }
end
def test_unique_with_already_set_values_and_parameter
values = ('a'..'z').to_a + ('0'..'9').to_a
@tester.unique.exclude(:characters, [number: 1], values)
assert_raise(Faker::UniqueGenerator::RetryLimitExceeded) { @tester.unique.characters(number: 1) }
end
def test_excluded_words_as_string
excluded_word_string = @tester.word
@words = @tester.words(number: 10_000, exclude_words: excluded_word_string)
@words.each { |w| assert_not_equal w, excluded_word_string }
end
def test_excluded_words_as_comma_delimited_string
excluded_words_array = @tester.words(number: 2)
excluded_words_string = excluded_words_array.join(', ')
@words = @tester.words(number: 10_000, exclude_words: excluded_words_string)
@words.each do |w|
assert_not_equal w, excluded_words_array[0]
assert_not_equal w, excluded_words_array[1]
end
end
def test_excluded_words_as_array
excluded_words_array = @tester.words(number: 2)
@words = @tester.words(number: 10_000, exclude_words: excluded_words_array)
@words.each do |w|
assert_not_equal w, excluded_words_array[0]
assert_not_equal w, excluded_words_array[1]
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_university.rb | test/faker/default/test_faker_university.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerUniversity < Test::Unit::TestCase
def setup
@tester = Faker::University
@alphabet = Faker::University.greek_alphabet
end
def test_prefix
assert_match(/\w+\.?/, @tester.prefix)
end
def test_suffix
assert_match(/\w+\.?/, @tester.suffix)
end
def test_name
assert_match(/\w+\.?/, @tester.name)
end
def test_greek_alphabet_has_24_characters
assert_equal(24, @alphabet.count)
end
def test_greek_organization
assert_match(/\p{Greek}|\w+/, @tester.greek_organization)
assert_equal(3, @tester.greek_organization.length)
end
def test_greek_organization_is_assembled_from_greek_alphabet
test_organization = @tester.greek_organization
test_organization.each_char do |letter|
assert_includes @alphabet, letter
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_house.rb | test/faker/default/test_faker_house.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerHouse < Test::Unit::TestCase
def setup
@tester = Faker::House
end
def test_furniture
assert_match(/\w+/, @tester.furniture)
end
def test_room
assert_match(/\w+/, @tester.room)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_chile_rut.rb | test/faker/default/test_faker_chile_rut.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestChileRut < Test::Unit::TestCase
def setup
@tester = Faker::ChileRut
end
def test_full_rut
assert_equal('6-k', @tester.full_rut(min_rut: 6, fixed: true))
assert_equal('8-6', @tester.full_rut(min_rut: 8, max_rut: 8))
assert_equal('11.111.111-1', @tester.full_rut(min_rut: 11_111_111, max_rut: 11_111_111, formatted: true))
assert_equal('30686957-4', @tester.full_rut(min_rut: 30_686_957, fixed: true))
end
def test_rut_length
refute_empty @tester.rut.to_s
assert_operator @tester.rut.to_s.length, :<=, 8
end
def test_rut_min_max
assert_equal(7, @tester.rut(min_rut: 7, max_rut: 7))
end
# We need to set specific rut before testing the check digit
# since the whole idea of the method revolves around calculating
# the check digit for that specific rut.
def test_check_digit
assert_equal(30_686_957, @tester.rut(min_rut: 30_686_957, fixed: true))
assert_equal('4', @tester.dv)
end
def test_full_formatted_rut
assert_equal('30.686.957', @tester.full_rut(min_rut: 30_686_957, fixed: true, formatted: true).split('-')[0])
assert_equal('4', @tester.dv)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_id_number.rb | test/faker/default/test_faker_id_number.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerIdNumber < Test::Unit::TestCase
def setup
@tester = Faker::IdNumber
end
def test_valid_ssn
sample = @tester.valid
assert_equal(11, sample.length)
assert_equal '-', sample[3]
assert_equal '-', sample[6]
assert sample[0..2].split.map { :to_i }.all? { :is_digit? }
assert sample[4..5].split.map { :to_i }.all? { :is_digit? }
assert sample[7..9].split.map { :to_i }.all? { :is_digit? }
end
def test_invalid_ssn
sample = @tester.invalid
assert_equal(11, sample.length)
assert_equal '-', sample[3]
assert_equal '-', sample[6]
assert sample[0..2].split.map { :to_i }.all? { :is_digit? }
assert sample[4..5].split.map { :to_i }.all? { :is_digit? }
assert sample[7..9].split.map { :to_i }.all? { :is_digit? }
end
def test_spanish_dni
sample = @tester.spanish_citizen_number
assert_equal 10, sample.length
assert sample[0..7].split.map { :to_i }.all? { :is_digit? }
assert_equal('-', sample[8])
mod = sample[0..7].to_i % 23
assert_equal Faker::IdNumber::CHECKS[mod], sample[9]
end
def test_spanish_nie
sample = @tester.spanish_foreign_citizen_number
assert_equal 11, sample.length
assert_includes 'XYZ', sample[0]
assert_equal '-', sample[1]
assert sample[2..8].split.map { :to_i }.all? { :is_digit? }
assert_equal '-', sample[9]
prefix = 'XYZ'.index(sample[0]).to_s
mod = "#{prefix}#{sample[2..8]}".to_i % 23
assert_equal Faker::IdNumber::CHECKS[mod], sample[10]
end
def test_south_african_id_number
assert_valid_south_african_id_number(@tester.south_african_id_number)
end
def test_valid_south_african_id_number
assert_valid_south_african_id_number(@tester.valid_south_african_id_number)
end
def test_invalid_south_african_id_number
sample = @tester.invalid_south_african_id_number
assert_raises Date::Error do
Date.parse(sample[0..5])
end
end
def test_brazilian_citizen_number
sample = @tester.brazilian_citizen_number
assert_match(/^\d{11}$/, sample)
assert_match(/(\d)((?!\1)\d)+/, sample)
end
def test_brazilian_citizen_number_formatted
sample = @tester.brazilian_citizen_number(formatted: true)
assert_match(/^\d{3}\.\d{3}\.\d{3}-\d{2}$/, sample)
end
def test_brazilian_id
sample = @tester.brazilian_id
assert_match(/^\d{8}(X|\d)?$/, sample)
assert_match(/(\d)((?!\1)\d)+/, sample)
end
def test_brazilian_id_formatted
sample = @tester.brazilian_id(formatted: true)
assert_match(/^\d{1,2}.\d{3}.\d{3}-[\dX]$/, sample)
end
def test_brazilian_citizen_number_checksum_digit
digits = '128991760'
checksum_digit = Faker::IdNumber.send(:brazilian_citizen_number_checksum_digit, digits)
assert_equal('4', checksum_digit)
digits = '1289917604'
checksum_digit = Faker::IdNumber.send(:brazilian_citizen_number_checksum_digit, digits)
assert_equal('8', checksum_digit)
end
def test_brazilian_id_checksum_digit
digits = '41987080'
checksum_digit = Faker::IdNumber.send(:brazilian_id_checksum_digit, digits)
assert_equal('5', checksum_digit)
end
def test_brazilian_document_checksum
digits = '123456789'
checksum = Faker::IdNumber.send(:brazilian_document_checksum, digits)
assert_equal(2100, checksum)
end
def test_brazilian_document_digit
citizen_number_digit10 = Faker::IdNumber.send(:brazilian_document_digit, 10)
citizen_number_digit_other = Faker::IdNumber.send(:brazilian_document_digit, 9)
id_digit10 = Faker::IdNumber.send(:brazilian_document_digit, 1, id: true)
id_digit11 = Faker::IdNumber.send(:brazilian_document_digit, 0, id: true)
id_digit_other = Faker::IdNumber.send(:brazilian_document_digit, 2, id: true)
assert_equal('0', citizen_number_digit10)
assert_equal('9', citizen_number_digit_other)
assert_equal('X', id_digit10)
assert_equal('0', id_digit11)
assert_equal('9', id_digit_other)
end
def test_brazilian_citizen_number_digit
digit10 = Faker::IdNumber.send(:brazilian_citizen_number_digit, 10)
digit_other = Faker::IdNumber.send(:brazilian_citizen_number_digit, 9)
assert_equal('0', digit10)
assert_equal('9', digit_other)
end
def test_brazilian_id_digit
digit10 = Faker::IdNumber.send(:brazilian_id_digit, 1)
digit11 = Faker::IdNumber.send(:brazilian_id_digit, 0)
digit_other = Faker::IdNumber.send(:brazilian_id_digit, 2)
assert_equal('X', digit10)
assert_equal('0', digit11)
assert_equal('9', digit_other)
end
def test_chilean_id
sample = @tester.chilean_id
assert_match(/^\d{8}-[K\d]$/, sample)
end
def test_chilean_verification_code_k
verification_code = Faker::IdNumber.send(:chilean_verification_code, 20_680_873)
assert_equal('K', verification_code)
end
def test_chilean_verification_code_0
verification_code = Faker::IdNumber.send(:chilean_verification_code, 13_196_022)
assert_equal(0, verification_code)
end
def test_croatian_id
sample = @tester.croatian_id
assert_match(/^\d{11}$/, sample)
end
def test_croatian_id_international
sample = @tester.croatian_id(international: true)
assert_match(/^HR\d{11}$/, sample)
end
def test_croatian_id_checksum_digit
digits = '8764670153'
checksum_digit = Faker::IdNumber.send(:croatian_id_checksum_digit, digits)
assert_equal(5, checksum_digit)
end
def test_danish_id_number
sample = @tester.danish_id_number
assert_match(/^\d{10}$/, sample)
end
def test_french_insee_number
sample = @tester.french_insee_number
assert_match(/^(?<gnd>\d{1})(?<year>\d{2})(?<month>\d{2})(?<department1>\d{1})(?<department2>[0-9AB]{1})(?<place>\d{3})(?<indv>\d{3})(?<ctrl>\d{2})$/, sample)
end
def test_danish_id_number_formatted
sample = @tester.danish_id_number(formatted: true)
assert_match(/^\d{6}-\d{4}$/, sample)
end
def test_danish_id_number_birthday
sample = @tester.danish_id_number(birthday: Date.new(1995, 1, 2))
assert_match(/^020195\d{4}$/, sample)
end
def test_danish_id_number_birthday_early_1800
assert_raises ArgumentError do
@tester.danish_id_number(birthday: Date.new(1815, 1, 2))
end
end
def test_danish_id_number_birthday_late_1800
sample = @tester.danish_id_number(birthday: Date.new(1895, 1, 2))
assert_match(/^020195[5678]\d{3}$/, sample)
end
def test_danish_id_number_birthday_early_1900
sample = @tester.danish_id_number(birthday: Date.new(1915, 1, 2))
assert_match(/^020115[0123]\d{3}$/, sample)
end
def test_danish_id_number_birthday_late_1900
sample = @tester.danish_id_number(birthday: Date.new(1995, 1, 2))
assert_match(/^020195[012349]\d{3}$/, sample)
end
def test_danish_id_number_birthday_early_2000
sample = @tester.danish_id_number(birthday: Date.new(2015, 1, 2))
assert_match(/^020115[456789]\d{3}$/, sample)
end
def test_danish_id_number_birthday_mid_2000
sample = @tester.danish_id_number(birthday: Date.new(2055, 1, 2))
assert_match(/^020155[5678]\d{3}$/, sample)
end
def test_danish_id_number_birthday_late_2000
assert_raises ArgumentError do
@tester.danish_id_number(birthday: Date.new(2095, 1, 2))
end
end
def test_danish_id_number_gender_female
sample = @tester.danish_id_number(gender: :female)
assert_predicate sample.chars.last.to_i, :even?
end
def test_danish_id_number_gender_male
sample = @tester.danish_id_number(gender: :male)
assert_predicate sample.chars.last.to_i, :odd?
end
def test_danish_id_number_invalid_gender
assert_raises ArgumentError do
@tester.danish_id_number(gender: :invalid)
end
end
private
def assert_valid_south_african_id_number(sample)
assert_equal 13, sample.length
assert_match(/^\d{13}$/, sample)
assert_include Faker::IdNumber::ZA_CITIZENSHIP_DIGITS, sample[10]
assert_equal Faker::IdNumber::ZA_RACE_DIGIT, sample[11]
assert Date.parse(sample[0..5])
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_vulnerability_identifier.rb | test/faker/default/test_faker_vulnerability_identifier.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerVulnerabilityIdentifier < Test::Unit::TestCase
def setup
@tester = Faker::VulnerabilityIdentifier
end
def test_cve_no_args
assert_match(/^CVE-\d{4}-\d{4,}$/, @tester.cve)
end
def test_cve_with_year
assert_match(/^CVE-2012-\d{4,}$/, @tester.cve(year: 2012))
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_hipster.rb | test/faker/default/test_faker_hipster.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerHipster < Test::Unit::TestCase
def setup
@tester = Faker::Hipster
@standard_wordlist = I18n.translate('faker.hipster.words')
@complete_wordlist =
@standard_wordlist + I18n.translate('faker.lorem.words')
end
# Words delivered by a standard request should be on the standard wordlist.
def test_words
@words = @tester.words(number: 1000)
assert_equal 1000, @words.length
@words.each { |w| assert_includes @standard_wordlist, w }
end
# Words should not return any word with spaces
def test_words_without_spaces
@words = @tester.words(number: 1000)
@words.each { |w| refute_match(/\s/, w) }
end
# Words requested from the supplemental list should all be in that list.
def test_supplemental_words
@words = @tester.words(number: 10_000, supplemental: true)
@words.each { |w| assert_includes @complete_wordlist, w }
end
# Faker::Hipster.word generates random word from standard wordlist
def test_word
@tester = Faker::Hipster
@standard_wordlist = I18n.translate('faker.hipster.words')
deterministically_verify -> { @tester.word }, depth: 5 do |word|
assert_includes @standard_wordlist, word
end
end
# Word should not return any word with spaces
def test_word_without_spaces
@tester = Faker::Hipster
deterministically_verify -> { @tester.word }, depth: 5 do |word|
refute_match(/\s/, word)
end
end
def test_exact_count_param
assert_equal(2, @tester.words(number: 2).length)
assert_equal(2, @tester.sentences(number: 2).length)
assert_equal(2, @tester.paragraphs(number: 2).length)
end
def test_range_count_param
ws = @tester.words(number: 2..5)
ss = @tester.sentences(number: 2..5)
ps = @tester.paragraphs(number: 2..5)
assert(ws.length.between?(2, 5))
assert(ss.length.between?(2, 5))
assert(ps.length.between?(2, 5))
end
def test_array_count_param
ws = @tester.words(number: [1, 4])
ss = @tester.sentences(number: [1, 4])
ps = @tester.paragraphs(number: [1, 4])
assert(ws.length == 1 || ws.length == 4)
assert(ss.length == 1 || ss.length == 4)
assert(ps.length == 1 || ps.length == 4)
end
def test_words_with_large_count_params
exact = @tester.words(number: 500)
range = @tester.words(number: 250..500)
array = @tester.words(number: [250, 500])
assert_equal(500, exact.length)
assert(range.length.between?(250, 500))
assert(array.length == 250 || array.length == 500)
end
def test_sentence_with_open_compounds_allowed
deterministically_verify -> { @tester.sentence(word_count: 5, random_words_to_add: 0, open_compounds_allowed: true) }, depth: 5 do |sentence|
assert_operator(sentence.split.length, :>=, 5)
end
end
# Sentence should not contain any open compounds
def test_sentence_without_open_compounds_allowed
deterministically_verify -> { @tester.sentence(word_count: 5, random_words_to_add: 0, open_compounds_allowed: false) }, depth: 5 do |sentence|
assert_equal(5, sentence.split.length)
end
end
def test_paragraph_char_count
paragraph = @tester.paragraph_by_chars(characters: 256)
assert_equal(256, paragraph.length)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_south_africa.rb | test/faker/default/test_faker_south_africa.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerSouthAfrica < Test::Unit::TestCase
def setup
@tester = Faker::SouthAfrica
end
def test_id_number
stubbed_id_number = '7201010001081'
Faker::IdNumber.stub :south_african_id_number, stubbed_id_number do
assert_equal stubbed_id_number, @tester.id_number
end
end
def test_valid_id_number
stubbed_id_number = '7201010001081'
Faker::IdNumber.stub :valid_south_african_id_number, stubbed_id_number do
assert_equal stubbed_id_number, @tester.valid_id_number
end
end
def test_invalid_id_number
stubbed_id_number = '9999990001081'
Faker::IdNumber.stub :invalid_south_african_id_number, stubbed_id_number do
assert_equal stubbed_id_number, @tester.invalid_id_number
end
end
def test_pty_ltd_registration_number
stubbed_number = '2016/0123456/07'
Faker::Company.stub :south_african_pty_ltd_registration_number, stubbed_number do
assert_equal stubbed_number, @tester.pty_ltd_registration_number
end
end
def test_close_corporation_registration_number
stubbed_number = 'CK85/123456/23'
Faker::Company.stub :south_african_close_corporation_registration_number, stubbed_number do
assert_equal stubbed_number, @tester.close_corporation_registration_number
end
end
def test_listed_company_registration_number
stubbed_number = '1977/1234/06'
Faker::Company.stub :south_african_listed_company_registration_number, stubbed_number do
assert_equal stubbed_number, @tester.listed_company_registration_number
end
end
def test_trust_registration_number
stubbed_number = 'IT2018/78'
Faker::Company.stub :south_african_trust_registration_number, stubbed_number do
assert_equal stubbed_number, @tester.trust_registration_number
end
end
def test_vat_number
stubbed_number = 'ZA1234567890'
Faker::Finance.stub :vat_number, stubbed_number, with: 'ZA' do
assert_equal stubbed_number, @tester.vat_number
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_name.rb | test/faker/default/test_faker_name.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerName < Test::Unit::TestCase
def setup
@tester = Faker::Name
end
def test_name
assert_match(/(\w+\.? ?){2,3}/, @tester.name)
end
def test_name_with_middle
assert_match(/(\w+\.? ?){3,4}/, @tester.name_with_middle)
end
def test_first_name
assert_match(/(\w+\.? ?){2,4}/, @tester.first_name)
end
def test_male_first_name
assert_kind_of String, @tester.male_first_name
end
def test_female_first_name
assert_kind_of String, @tester.female_first_name
end
def test_neutral_first_name
assert_kind_of String, @tester.neutral_first_name
end
def test_middle_name
assert_match(/(\w+\.? ?){3,4}/, @tester.middle_name)
end
def test_last_name
assert_match(/(\w+\.? ?){3,4}/, @tester.last_name)
end
def test_prefix
assert_match(/[A-Z][a-z]+\.?/, @tester.prefix)
end
def test_suffix
assert_match(/[A-Z][a-z]*\.?/, @tester.suffix)
end
def test_initials
assert_match(/[A-Z]{3}/, @tester.initials)
assert_match(/[A-Z]{2}/, @tester.initials(number: 2))
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_birthday_in_leap_year.rb | test/faker/default/test_faker_birthday_in_leap_year.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerBirthdayInLeapYear < Test::Unit::TestCase
def setup
@tester = Faker::Date
@today = Date.parse('2016-02-29')
@min = 18
@max = 65
end
def teardown
Timecop.return
end
def test_birthday_in_leap_year
Timecop.freeze(@today)
assert_nothing_raised ArgumentError do
@tester.birthday
end
assert_raise Date::Error do
::Date.new(@today.year - @min, @today.month, @today.day)
end
assert_raise Date::Error do
::Date.new(@today.year - @max, @today.month, @today.day)
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_construction.rb | test/faker/default/test_faker_construction.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerConstruction < Test::Unit::TestCase
def setup
Faker::Config.locale = nil
end
def test_material
assert_match(/\w+/, Faker::Construction.material)
end
def test_heavy_equipment
assert_match(/\w+/, Faker::Construction.heavy_equipment)
end
def test_trade
assert_match(/\w+/, Faker::Construction.trade)
end
def test_subcontract_category
assert_match(/\w+/, Faker::Construction.subcontract_category)
end
def test_standard_cost_code
assert_match(/\w+/, Faker::Construction.standard_cost_code)
end
def test_role
assert_match(/\w+/, Faker::Construction.role)
end
def test_locales
[nil, 'en'].each do |locale_name|
Faker::Config.locale = locale_name
assert_kind_of String, Faker::Construction.material
assert_kind_of String, Faker::Construction.subcontract_category
assert_kind_of String, Faker::Construction.standard_cost_code
assert_kind_of String, Faker::Construction.trade
assert_kind_of String, Faker::Construction.role
assert_kind_of String, Faker::Construction.heavy_equipment
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_driving_licence.rb | test/faker/default/test_faker_driving_licence.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerDrivingLicence < Test::Unit::TestCase
def setup
@tester = Faker::DrivingLicence
end
def test_valid_gb_licence
sample = @tester.british_driving_licence
# GB Licence number is 16 characters long
assert_equal 16, sample.length
# First 5 characters are the last_name, right-padded with '9'
assert_match %r{[A-Z][A-Z9]{4}}, sample[0..4]
# Next 6 are digits
assert_match %r{[0-9]{6}}, sample[5..10]
# comprising:
# Single digit decade of birth
assert_includes 0..9, sample[5].to_i
# 2 digit month of birth (add 5 to first digit if female)
assert_includes [1..12, 51..62].map(&:to_a).flatten, sample[6..7].to_i
# 2 digit day of birth
assert_includes 1..31, sample[8..9].to_i
# and least significant digit of birth year
assert_includes 0..9, sample[10].to_i
# Next 2 are first 2 initials of forenames, padded with '9'
assert_match %r{[A-Z][A-Z9]}, sample[11..12]
# Last stanza is a tie-breaker digit + 2 letter checksum
assert_match %r{[0-9][A-Z0-9]{2}}, sample[13..15]
end
def test_valid_northern_irish_licence
sample = @tester.northern_irish_driving_licence
# NI licence is an opaque 8-digit number
assert_equal 8, sample.length
assert_match %r{[0-9]{8}}, sample
end
def test_uk_licence
sample = @tester.uk_driving_licence
assert_includes [8, 16], sample.length
end
def test_british_licence_correctly_mangles_last_name
padded = @tester.british_driving_licence(last_name: 'Judd')
assert_equal 'JUDD9', padded[0..4]
truncated = @tester.british_driving_licence(last_name: 'Hamilton')
assert_match %r{HAMIL[0-9]}, truncated[0..5]
cleaned = @tester.british_driving_licence(last_name: "O'Carroll")
assert_equal 'OCARR', cleaned[0..4]
end
def test_british_licence_correctly_mangles_date_of_birth
date_of_birth = Date.parse('1978-02-13')
male = @tester.british_driving_licence(date_of_birth: date_of_birth, gender: :male)
assert_equal '702138', male[5..10]
female = @tester.british_driving_licence(date_of_birth: date_of_birth, gender: :female)
assert_equal '752138', female[5..10]
end
def test_british_licence_correctly_builds_initials
padded = @tester.british_driving_licence(initials: 'A')
assert_equal 'A9', padded[11..12]
truncated = @tester.british_driving_licence(initials: 'NLTC')
assert_equal 'NL', truncated[11..12]
end
def test_usa_driving_licence
# When state is not passed to method it returns CA licence format by default
licence_number = @tester.usa_driving_licence
assert_match %r{[A-Z][0-9]{7}}, licence_number
end
def test_usa_driving_licence_for_different_states
# When state Washington is passed
licence_number = @tester.usa_driving_licence('Washington')
assert_match %r{[A-Z]{7,12}[0-9]{0,5}\**}, licence_number
# When state Alaska is passed
licence_number = @tester.usa_driving_licence('alaska')
assert_match %r{[0-9]{6,7}}, licence_number
# When state North Dakota is passed
licence_number = @tester.usa_driving_licence('North Dakota')
assert_match %r{([A-Z]{3}[0-9]{6})|([0-9]{9})}, licence_number
end
def test_usa_driving_licence_with_faker_code
assert_raises(Faker::InvalidStatePassed) do
@tester.usa_driving_licence('abc')
end
assert_raises(Faker::InvalidStatePassed) do
@tester.usa_driving_licence(123)
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_zip_code.rb | test/faker/default/test_faker_zip_code.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerZipCode < Test::Unit::TestCase
def setup
@zip_codes_without_state = %w[50817 48666 55551 14242 99852]
@zip_codes_with_state = %w[55555 44444 33333 22222 11111]
@old_locales = I18n.config.available_locales
locale_without_state = {
faker: {
address: {
state_abbreviation: [''],
postcode: @zip_codes_without_state
}
}
}
locale_with_state = {
faker: {
address: {
postcode_by_state: {
NY: @zip_codes_with_state
}
}
}
}
I18n.config.available_locales += %i[xy xz]
I18n.backend.store_translations(:xy, locale_without_state)
I18n.backend.store_translations(:xz, locale_with_state)
@tester = Faker::Address
end
def teardown
I18n.config.available_locales = @old_locales
end
def test_zip_code_can_have_leading_zero
zip_codes = []
1000.times { zip_codes << @tester.zip_code }
assert zip_codes.any? { |zip_code| zip_code[0].to_i.zero? }
end
def test_default_zip_codes_without_states
I18n.with_locale(:xy) do
zip_codes = @zip_codes_without_state
deterministically_verify -> { @tester.zip_code }, depth: 5 do |zip_code|
assert_includes zip_codes, zip_code, "Expected <#{zip_codes.join(' / ')}>, but got #{zip_code}"
end
end
end
def test_zip_codes_with_states
I18n.with_locale(:xz) do
zip_codes = @zip_codes_with_state
deterministically_verify -> { @tester.zip_code(state_abbreviation: 'NY') }, depth: 5 do |zip_code|
assert_includes zip_codes, zip_code, "Expected <#{zip_codes.join(' / ')}>, but got #{zip_code}"
end
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_crypto.rb | test/faker/default/test_faker_crypto.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerCrypto < Test::Unit::TestCase
def setup
@tester = Faker::Crypto
end
def test_md5
assert_match(/\A[a-z0-9]{32}\z/, @tester.md5)
end
def test_sha1
assert_match(/\A[a-z0-9]{40}\z/, @tester.sha1)
end
def test_sha256
assert_match(/\A[a-z0-9]{64}\z/, @tester.sha256)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_crypto_coin.rb | test/faker/default/test_faker_crypto_coin.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerCryptoCoin < Test::Unit::TestCase
COIN_NAME = 0
ACRONYM = 1
URL_LOGO = 2
REGEX_COIN_NAME = /[a-zA-Z .]{3,}/
REGEX_ACRONYM = /\w+{3,}/
REGEX_URL_LOGO = /^https:\/\/i.imgur.com\/.......\./
def setup
@tester = Faker::CryptoCoin
end
def test_coin_name
assert_match REGEX_COIN_NAME, @tester.coin_name
end
def test_acronym
assert_match REGEX_ACRONYM, @tester.acronym
end
def test_url_logo
assert_match REGEX_URL_LOGO, @tester.url_logo
end
def test_coin_array
assert_kind_of Array, @tester.coin_array
assert_match REGEX_COIN_NAME, @tester.coin_array[COIN_NAME]
assert_match REGEX_ACRONYM, @tester.coin_array[ACRONYM]
assert_match REGEX_URL_LOGO, @tester.coin_array[URL_LOGO]
end
def test_coin_hash
assert_kind_of Hash, @tester.coin_hash
assert @tester.coin_hash.key?(:name)
assert @tester.coin_hash.key?(:acronym)
assert @tester.coin_hash.key?(:url_logo)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_boolean.rb | test/faker/default/test_faker_boolean.rb | # frozen_string_literal: true
require_relative '../../test_helper'
require 'minitest/mock'
class TestFakerBoolean < Test::Unit::TestCase
def setup
@tester = Faker::Boolean
end
def test_boolean
assert_includes [true, false], @tester.boolean
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_coin.rb | test/faker/default/test_faker_coin.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerCoin < Test::Unit::TestCase
def setup
@tester = Faker::Coin
end
def test_name
assert_match(/\w+/, @tester.name)
end
def test_flip
assert_match(/\w+/, @tester.flip)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_relationship.rb | test/faker/default/test_faker_relationship.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerRelationship < Test::Unit::TestCase
def setup
@tester = Faker::Relationship
end
def test_random_familial
assert_match(/\w+/, @tester.familial)
end
def test_familial_direct
assert_match(/\w+/, @tester.familial(connection: 'direct'))
end
def test_familial_extended
assert_match(/\w+/, @tester.familial(connection: 'extended'))
end
# test error on no match
def test_invalid_familial_connection
assert_raise ArgumentError do
@tester.familial(connection: 'Not Correct')
end
end
def test_in_law
assert_match(/\w+/, @tester.in_law)
end
def test_spouse
assert_match(/\w+/, @tester.spouse)
end
def test_parent
assert_match(/\w+/, @tester.parent)
end
def test_sibling
assert_match(/\w+/, @tester.sibling)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_adjective.rb | test/faker/default/test_faker_adjective.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerAdjective < Test::Unit::TestCase
def setup
@tester = Faker::Adjective
end
def test_positive
assert_match(/\w+/, @tester.positive)
end
def test_negative
assert_match(/\w+/, @tester.negative)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_marketing.rb | test/faker/default/test_faker_marketing.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerMarketing < Test::Unit::TestCase
def setup
@tester = Faker::Marketing
end
def test_buzzwords
assert_match(/\w+/, @tester.buzzwords)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_internet.rb | test/faker/default/test_faker_internet.rb | # frozen_string_literal: true
require_relative '../../test_helper'
require 'uri'
class TestFakerInternet < Test::Unit::TestCase
def setup
@tester = Faker::Internet
@default_locale = Faker::Config.locale
end
def teardown
Faker::Config.locale = @default_locale
end
def test_email_with_no_arguments
deterministically_verify -> { @tester.email } do |result|
name, domain = result.split('@')
domain_name, domain_suffix = domain.split('.')
assert_kind_of String, name
assert_kind_of String, domain_name
assert_includes(%w[example test], domain_suffix)
end
end
def test_email_name_with_non_permitted_characters
deterministically_verify -> { @tester.email(name: 'martín') } do |result|
name, domain = result.split('@')
domain_name, domain_suffix = domain.split('.')
assert_equal('mart#n', name)
assert_kind_of String, domain_name
assert_includes(%w[example test], domain_suffix)
end
end
def test_email_with_apostrophes
name = "Alexis O'Connell"
deterministically_verify -> { @tester.email(name: name) } do |result|
assert_email_regex 'Alexis', 'OConnell', result
end
end
def test_email_with_abbreviations
name = 'Mr. Faker'
deterministically_verify -> { @tester.email(name: name) } do |email|
assert_email_regex 'Mr', 'Faker', email
end
end
def test_email_against_name_generator
deterministically_verify -> { @tester.email(name: Faker::Name.unique.name) } do |email|
# reject emails with duplicated punctuation
# e.g.: "mr._faker.jr.@example.com"
refute_match(/\p{Punct}{2,}/, email)
end
end
def test_email_with_separators
deterministically_verify -> { @tester.email(name: 'jane doe', separators: '+') } do |result|
name, domain = result.split('@')
domain_name, domain_suffix = domain.split('.')
assert_match(/(jane\+doe|doe\+jane)/, name)
assert_kind_of String, domain_name
assert_includes(%w[example test], domain_suffix)
end
end
def test_email_with_domain_name_option_given
result = @tester.email(domain: 'customdomain')
name, domain = result.split('@')
domain_name, domain_suffix = domain.split('.')
assert_kind_of String, name
assert_equal('customdomain', domain_name)
assert_includes(%w[example test], domain_suffix)
end
def test_email_with_full_domain_option_given
deterministically_verify -> { @tester.email(domain: 'customdomain.org') } do |result|
name, domain = result.split('@')
assert_kind_of String, name
assert_equal('customdomain.org', domain)
end
end
def test_email_with_name_seperators_domain
deterministically_verify -> { @tester.email(name: 'faker ruby', separators: '-', domain: 'test') } do |result|
name, domain = result.split('@')
domain_name, domain_suffix = domain.split('.')
assert_match(/(ruby-faker|faker-ruby)/, name)
assert_equal('test', domain_name)
assert_includes(%w[example test], domain_suffix)
end
end
def test_username
assert_match(/[a-z]+((_|\.)[a-z]+)?/, @tester.username(specifier: 0..3))
assert_match(/[a-z]+((_|\.)[a-z]+)?/, @tester.username)
end
def test_username_with_apostrophes
assert_match(/\A[a-z]+([_.][a-z]+)*\z/, @tester.username(specifier: "Alexis O'Connell"))
end
def test_user_name_alias
assert_equal @tester.method(:username), @tester.method(:user_name)
end
def test_username_with_string_arg
assert_match(/(bo(_|\.)peep|peep(_|\.)bo)/, @tester.username(specifier: 'bo peep'))
end
def test_username_with_string_arg_determinism
deterministically_verify -> { @tester.username(specifier: 'bo peep') }, depth: 4 do |username|
assert_match(/(bo(_|\.)peep|peep(_|\.)bo)/, username)
end
end
def test_username_with_integer_arg
(1..32).each do |min_length|
assert_operator @tester.username(specifier: min_length).length, :>=, min_length
end
end
def test_username_with_utf_8_arg
assert_match @tester.username(specifier: 'Łucja'), 'łucja'
end
def test_username_with_very_large_integer_arg
exception = assert_raises(ArgumentError) { @tester.username(specifier: 10_000_000) }
assert_equal('Given argument is too large', exception.message)
end
def test_username_with_closed_range_arg
(1..32).each do |min_length|
(min_length..32).each do |max_length|
l = @tester.username(specifier: (min_length..max_length)).length
assert_operator l, :>=, min_length
assert_operator l, :<=, max_length
end
end
end
def test_username_with_open_range_arg
(1..32).each do |min_length|
((min_length + 1)..33).each do |max_length|
l = @tester.username(specifier: (min_length...max_length)).length
assert_operator l, :>=, min_length
assert_operator l, :<=, max_length - 1
end
end
end
def test_username_with_range_and_separators
(1..32).each do |min_length|
((min_length + 1)..33).each do |max_length|
u = @tester.username(specifier: (min_length...max_length), separators: %w[=])
assert u.length.between? min_length, max_length - 1
assert_match(/\A[a-z]+((=)?[a-z]*)*\z/, u)
end
end
end
def test_password_with_no_arguments
password = @tester.password
default_min_length = 8
default_max_length = 16
assert_match(/\w{3}/, password)
assert_match(/[a-z]/, password)
assert_match(/[A-Z]/, password)
assert_match(/[0-9]/, password)
assert_includes(default_min_length..default_max_length, password.length, 'Generated password length is incorrect')
end
def test_password_with_integer_arg
(1..32).each do |min_length|
max_length = min_length + 1
assert_includes (min_length..max_length), @tester.password(min_length: min_length, max_length: max_length, mix_case: false).length
end
end
def test_password_max_with_integer_arg
(1..32).each do |min_length|
max_length = min_length + 4
assert_operator @tester.password(min_length: min_length, max_length: max_length, mix_case: false).length, :<=, max_length
end
end
def test_password_could_achieve_max_length
passwords = []
64.times do
passwords << @tester.password(min_length: 14, max_length: 16)
end
assert_operator passwords.select { |item| item.length == 16 }.size, :>=, 1
end
def test_password_with_mixed_case
password = @tester.password
upcase_count = 0
downcase_count = 0
password.chars.each do |char|
if char =~ /[[:alpha:]]/
char.capitalize == char ? upcase_count += 1 : downcase_count += 1
end
end
assert_operator upcase_count, :>=, 1
assert_operator downcase_count, :>=, 1
end
def test_password_with_min_length_eq_1_without_mix_case
password = @tester.password(min_length: 1, mix_case: false)
assert_match(/\w+/, password)
end
def test_password_with_min_length_and_max_length
min_length = 2
max_length = 5
password = @tester.password(min_length: min_length, max_length: max_length)
assert_match(/\w+/, password)
assert_includes (min_length..max_length), password.size, 'Password size is incorrect'
end
def test_password_with_same_min_max_length
password = @tester.password(min_length: 5, max_length: 5)
assert_match(/\w+/, password)
assert_equal(5, password.length)
end
def test_password_with_max_length_less_than_min_length
assert_raise 'min_length must be smaller than or equal to max_length' do
@tester.password(min_length: 8, max_length: 4)
end
end
def test_password_without_mixed_case
assert_match(/[^A-Z]+/, @tester.password(min_length: 8, max_length: 12, mix_case: false))
end
def test_password_with_special_chars
assert_match(/[!@#$%\^&*]+/, @tester.password(min_length: 8, max_length: 12, mix_case: true, special_characters: true))
end
def test_password_without_special_chars
assert_match(/[^!@#$%\^&*]+/, @tester.password(min_length: 8, max_length: 12, mix_case: true))
end
def test_password_with_special_chars_and_mixed_case
32.times do
password = @tester.password(min_length: 4, max_length: 6, mix_case: true, special_characters: true)
assert_match(/[!@#$%\^&*]+/, password)
assert_match(/[A-Za-z]+/, password)
end
end
def test_deterministic_password_with_special_chars_and_mixed_case
deterministically_verify -> { @tester.password(min_length: 4, max_length: 6, mix_case: true, special_characters: true) }, depth: 4 do |password|
assert_match(/[!@#$%\^&*]+/, password)
assert_match(/[A-Za-z]+/, password)
end
end
def test_password_with_special_chars_and_mixed_case_on_3chars_password
16.times do
password = @tester.password(min_length: 3, max_length: 6, mix_case: true, special_characters: true)
assert_match(/[!@#$%\^&*]+/, password)
assert_match(/[A-Za-z]+/, password)
end
end
def test_password_with_invalid_min_length_for_mix_case_and_special_characters
assert_raise_message 'min_length should be at least 3 to enable mix_case, special_characters configuration' do
@tester.password(min_length: 1, mix_case: true, special_characters: true)
end
end
def test_password_with_invalid_min_max_length
error = assert_raises(ArgumentError) do
@tester.password(min_length: 0, max_length: 0, mix_case: false, special_characters: false)
end
assert_equal 'min_length and max_length must be greater than or equal to one', error.message
end
def test_password_with_invalid_min_length_for_special_characters_only
error = assert_raises(ArgumentError) do
@tester.password(min_length: 0, mix_case: false, special_characters: true)
end
assert_equal 'min_length and max_length must be greater than or equal to one', error.message
end
def test_password_with_invalid_min_length_for_mix_case_only
error = assert_raises(ArgumentError) do
@tester.password(min_length: 1, mix_case: true)
end
assert_equal 'min_length should be at least 2 to enable mix_case configuration', error.message
end
def test_password_with_compatible_min_length_and_requirements
assert_nothing_raised do
[false, true].each do |value|
min_length = value ? 2 : 1
@tester.password(min_length: min_length, mix_case: value, special_characters: !value)
end
end
end
def test_deterministic_password_with_compatible_min_length_and_requirements
[false, true].each do |value|
min_length = value ? 2 : 1
deterministically_verify -> { @tester.password(min_length: min_length, mix_case: value, special_characters: !value) }, depth: 4 do |password|
assert_nothing_raised { password }
end
end
end
def test_domain_name_without_subdomain
domain_name, domain_suffix = @tester.domain_name.split('.')
assert_kind_of String, domain_name
assert_includes(%w[example test], domain_suffix)
end
def test_domain_name_with_subdomain
subdomain, domain_name, domain_suffix = @tester.domain_name(
subdomain: true
).split('.')
assert_kind_of String, domain_name
assert_kind_of String, subdomain
assert_includes(%w[example test], domain_suffix)
end
def test_domain_name_with_subdomain_and_with_domain_name_option_given
subdomain, domain_name, domain_suffix = @tester.domain_name(
subdomain: true,
domain: 'customdomain'
).split('.')
assert_kind_of String, subdomain
assert_equal 'customdomain', domain_name
assert_includes(%w[example test], domain_suffix)
end
def test_domain_name_with_subdomain_and_with_full_domain_option_given
subdomain, domain_name, domain_suffix = @tester.domain_name(
subdomain: true,
domain: 'faker-ruby.org'
).split('.')
assert_kind_of String, subdomain
assert_equal 'faker-ruby', domain_name
assert_equal 'org', domain_suffix
end
def test_domain_name_with_subdomain_and_with_domain_option_given_with_domain_suffix
subdomain, domain_name, domain_suffix = @tester.domain_name(
subdomain: true,
domain: 'faker.faker-ruby.org'
).split('.')
assert_equal 'faker', subdomain
assert_equal 'faker-ruby', domain_name
assert_equal 'org', domain_suffix
end
def test_domain_word
assert_match(/^[\w-]+$/, @tester.domain_word)
end
def test_domain_suffix_with_no_arguments
result = @tester.domain_suffix
domain_suffixes_options = %w[com biz info name net org org io co]
assert_includes(domain_suffixes_options, result)
end
def test_domain_suffix_with_arguments
result = @tester.domain_suffix(safe: true)
safe_domain_suffixes_options = %w[example test]
assert_includes(safe_domain_suffixes_options, result)
end
def test_ip_v4_address
assert_equal 3, @tester.ip_v4_address.count('.')
deterministically_verify -> { @tester.ip_v4_address }, depth: 5 do |address|
assert_operator address.split('.').map(&:to_i).min, :>=, 0
assert_operator address.split('.').map(&:to_i).max, :<=, 255
end
end
def test_private_ip_v4_address
regexps = [
/^10\./, # 10.0.0.0 - 10.255.255.255
/^100\.(6[4-9]|[7-9]\d|1[0-1]\d|12[0-7])\./, # 100.64.0.0 - 100.127.255.255
/^127\./, # 127.0.0.0 - 127.255.255.255
/^169\.254\./, # 169.254.0.0 - 169.254.255.255
/^172\.(1[6-9]|2\d|3[0-1])\./, # 172.16.0.0 - 172.31.255.255
/^192\.0\.0\./, # 192.0.0.0 - 192.0.0.255
/^192\.168\./, # 192.168.0.0 - 192.168.255.255
/^198\.(1[8-9])\./ # 198.18.0.0 - 198.19.255.255
]
expected = Regexp.new regexps.collect { |reg| "(#{reg})" }.join('|')
deterministically_verify -> { @tester.private_ip_v4_address }, depth: 5 do |address|
assert_match expected, address
end
end
def test_public_ip_v4_address
private = [
/^10\./, # 10.0.0.0 - 10.255.255.255
/^100\.(6[4-9]|[7-9]\d|1[0-1]\d|12[0-7])\./, # 100.64.0.0 - 100.127.255.255
/^127\./, # 127.0.0.0 - 127.255.255.255
/^169\.254\./, # 169.254.0.0 - 169.254.255.255
/^172\.(1[6-9]|2\d|3[0-1])\./, # 172.16.0.0 - 172.31.255.255
/^192\.0\.0\./, # 192.0.0.0 - 192.0.0.255
/^192\.168\./, # 192.168.0.0 - 192.168.255.255
/^198\.(1[8-9])\./ # 198.18.0.0 - 198.19.255.255
]
reserved = [
/^0\./, # 0.0.0.0 - 0.255.255.255
/^192\.0\.2\./, # 192.0.2.0 - 192.0.2.255
/^192\.88\.99\./, # 192.88.99.0 - 192.88.99.255
/^198\.51\.100\./, # 198.51.100.0 - 198.51.100.255
/^203\.0\.113\./, # 203.0.113.0 - 203.0.113.255
/^(22[4-9]|23\d)\./, # 224.0.0.0 - 239.255.255.255
/^(24\d|25[0-5])\./ # 240.0.0.0 - 255.255.255.254 and 255.255.255.255
]
deterministically_verify -> { @tester.public_ip_v4_address }, depth: 5 do |address|
private.each { |reg| assert_not_match reg, address }
reserved.each { |reg| assert_not_match reg, address }
end
end
def test_ip_v4_cidr
assert_match %r(/\d{1,2}$), @tester.ip_v4_cidr
deterministically_verify -> { @tester.ip_v4_cidr }, depth: 5 do |address|
assert((1..32).cover?(address.split('/').last.to_i))
end
end
def test_mac_address
assert_equal 5, @tester.mac_address.count(':')
assert_equal 5, @tester.mac_address(prefix: '').count(':')
deterministically_verify -> { @tester.mac_address }, depth: 5 do |address|
assert_operator address.split(':').map { |d| d.to_i(16) }.max, :<=, 255
end
assert @tester.mac_address(prefix: 'fa:fa:fa').start_with?('fa:fa:fa')
assert @tester.mac_address(prefix: '01:02').start_with?('01:02')
end
def test_ip_v6_address
assert_equal 7, @tester.ip_v6_address.count(':')
deterministically_verify -> { @tester.ip_v6_address }, depth: 5 do |address|
assert_operator address.split('.').map { |h| "0x#{h}".hex }.max, :<=, 65_535
end
end
def test_ip_v6_cidr
assert_match %r{/\d{1,3}$}, @tester.ip_v6_cidr
deterministically_verify -> { @tester.ip_v6_cidr }, depth: 5 do |address|
assert((1..128).cover?(address.split('/').last.to_i))
end
end
I18n.config.available_locales.each do |locale|
define_method("test_#{locale}_slug") do
Faker::Config.locale = locale
assert_match(/^[a-z]+(_|-)[a-z]+$/, @tester.slug)
end
define_method("test_#{locale}_slug_with_glue_arg") do
Faker::Config.locale = locale
assert_match(/^[a-z]+\+[a-z]+$/, @tester.slug(words: nil, glue: '+'))
end
end
def test_slug_with_content_arg
assert_match(/^foo(_|\.|-)bar(_|\.|-)baz$/, @tester.slug(words: 'Foo bAr baZ'))
end
def test_slug_with_unwanted_content_arg
assert_match(/^foo(_|\.|-)bar(_|\.|-)baz$/, @tester.slug(words: 'Foo.. bAr., baZ,,'))
end
def test_url_with_arguments
deterministically_verify -> { @tester.url(host: 'domain.com', path: '/username', scheme: 'https') } do |result|
uri = URI.parse(result)
assert_equal 'https', uri.scheme
assert_includes('domain.com', uri.host)
assert_equal '/username', uri.path
end
end
def test_url_with_no_arguments
deterministically_verify -> { @tester.url } do |result|
uri = URI.parse(result)
# example: http://zieme-bosco.example/porsche
# we just care about the last part here
suffix = uri.host.split('.').last
assert_equal 'http', uri.scheme
assert_includes(%w[example test], suffix)
end
end
def test_device_token
assert_equal 64, @tester.device_token.size
end
def test_user_agent_with_no_argument
assert_match(/Mozilla|Opera/, @tester.user_agent)
end
def test_user_agent_with_valid_argument
assert_match(/Opera/, @tester.user_agent(vendor: :opera))
assert_match(/Opera/, @tester.user_agent(vendor: 'opera'))
assert_match(/Mozilla|Opera/, @tester.user_agent(vendor: nil))
end
def test_user_agent_with_invalid_argument
refute_empty @tester.user_agent(vendor: :ie)
refute_empty @tester.user_agent(vendor: 1)
end
def test_bot_user_agent_with_no_argument
refute_empty @tester.bot_user_agent
end
def test_bot_user_agent_with_valid_argument
assert_match(/DuckDuckBot/, @tester.bot_user_agent(vendor: :duckduckbot))
assert_match(/DuckDuckBot/, @tester.bot_user_agent(vendor: 'duckduckbot'))
refute_empty @tester.bot_user_agent(vendor: nil)
end
def test_bot_user_agent_with_invalid_argument
refute_empty @tester.bot_user_agent(vendor: :ie)
refute_empty @tester.bot_user_agent(vendor: 1)
end
def test_uuid
uuid = @tester.uuid
assert_equal(36, uuid.size)
assert_match(/\A\h{8}-\h{4}-4\h{3}-\h{4}-\h{12}\z/, uuid)
end
def test_base64
assert_match(/[[[:alnum:]]\-_]{16}/, @tester.base64)
assert_match(/[[[:alnum:]]\-_]{4}/, @tester.base64(length: 4))
assert_match(/[[[:alnum:]]\-_]{16}=/, @tester.base64(padding: true))
assert_match(/[[[:alnum:]]+\/]{16}/, @tester.base64(urlsafe: false))
end
def test_user_with_args
user = @tester.user('username', 'email', 'password')
assert_match(/[a-z]+((_|\.)[a-z]+)?/, user[:username])
assert_match(/.+@.+\.\w+/, user[:email])
assert_match(/\w{3}/, user[:password])
end
def test_user_without_args
user = @tester.user
assert_match(/[a-z]+((_|\.)[a-z]+)?/, user[:username])
assert_match(/.+@.+\.\w+/, user[:email])
end
def test_user_with_invalid_args
assert_raises NoMethodError do
@tester.user('xyx')
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_world_cup.rb | test/faker/default/test_faker_world_cup.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerWorldCup < Test::Unit::TestCase
def setup
@tester = Faker::WorldCup
end
def test_team
assert_match(/\w+/, @tester.team)
end
def test_stadium
assert_match(/\w+/, @tester.stadium)
end
def test_city
assert_match(/\w+/, @tester.city)
end
def test_group
assert_match(/\w+/, @tester.group)
end
def test_roster
assert_match(/\w+/, @tester.roster)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_barcodes.rb | test/faker/default/test_barcodes.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerBarcodes < Test::Unit::TestCase
def setup
@tester = Faker::Barcode
end
def test_ean
assert_match(/[0-9]{8}/, @tester.ean)
assert_equal(8, @tester.ean.length)
assert_match(/[0-9]{8}/, @tester.ean(8))
assert_equal(8, @tester.ean(8).length)
assert_match(/[0-9]{13}/, @tester.ean(13))
assert_equal(13, @tester.ean(13).length)
end
def test_ean_with_composite_symbology
assert_match(/[0-9]{8}|[A-Za-z0-9]{8}/, @tester.ean_with_composite_symbology)
assert_equal(17, @tester.ean_with_composite_symbology.length)
assert_match(/[0-9]{8}|[A-Za-z0-9]{8}/, @tester.ean_with_composite_symbology(8))
assert_equal(17, @tester.ean_with_composite_symbology(8).length)
assert_match(/[0-9]{13}|[A-Za-z0-9]{8}/, @tester.ean_with_composite_symbology(13))
assert_equal(22, @tester.ean_with_composite_symbology(13).length)
end
def test_upc_a
assert_match(/[0-9]{12}/, @tester.upc_a)
assert_equal(12, @tester.upc_a.length)
end
def test_upc_a_with_composite_symbol
assert_match(/[0-9]{12}|[A-Za-z0-9]{8}/, @tester.upc_a_with_composite_symbology)
assert_equal(21, @tester.upc_a_with_composite_symbology.length)
end
def test_upc_e
assert_match(/[0-9]{8}/, @tester.upc_e)
assert_equal(8, @tester.upc_e.length)
end
def test_upc_e_with_composite_symbol
assert_match(/[0-9]{8}|[A-Za-z0-9]{8}/, @tester.upc_e_with_composite_symbology)
assert_equal(17, @tester.upc_e_with_composite_symbology.length)
end
def test_isbn
assert_match(/^(978|9798|97910|97911|97912)[0-9]{8,10}/, @tester.isbn)
assert_equal(13, @tester.isbn.length)
end
def test_ismn
assert_match(/9790[0-9]{9}/, @tester.ismn)
assert_equal(13, @tester.ismn.length)
end
def test_issn
assert_match(/977[0-9]{10}/, @tester.issn)
assert_equal(13, @tester.issn.length)
end
def test_sum_even_odd
assert_equal([12, 9], @tester.send(:sum_even_odd, 123_456))
assert_equal([11, 21], @tester.send(:sum_even_odd, 857_363))
end
def test_generate_check_digit
assert_equal(2, @tester.send(:generate_check_digit, 18, 24))
assert_equal(4, @tester.send(:generate_check_digit, 21, 13))
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_ancient.rb | test/faker/default/test_faker_ancient.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerAncient < Test::Unit::TestCase
def setup
@tester = Faker::Ancient
end
def test_god
assert_match(/\w+/, @tester.god)
end
def test_primordial
assert_match(/\w+/, @tester.primordial)
end
def test_titan
assert_match(/\w+/, @tester.titan)
end
def test_hero
assert_match(/\w+/, @tester.hero)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_hobby.rb | test/faker/default/test_faker_hobby.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerHobby < Test::Unit::TestCase
def setup
@tester = Faker::Hobby
end
def test_flexible_key
assert_equal(:hobby, @tester.flexible_key)
end
def test_activity
assert_match(/\w+/, @tester.activity)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_demographic.rb | test/faker/default/test_faker_demographic.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerDemographic < Test::Unit::TestCase
def setup
@tester = Faker::Demographic
end
def test_race
assert_match(/\w+/, @tester.race)
end
def test_educational_attainment
assert_match(/\w+/, @tester.educational_attainment)
end
def test_marital_status
assert_match(/\w+/, @tester.marital_status)
end
def test_demonym
assert_match(/\w+/, @tester.demonym)
end
def test_sex
assert_includes %w[Male Female], @tester.sex
end
def test_height_imperial
assert_match(/\w+/, @tester.height(unit: :imperial))
end
def test_height_metric
assert_match(/\w+/, @tester.height)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_programming_language.rb | test/faker/default/test_faker_programming_language.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerProgrammingLanguage < Test::Unit::TestCase
def setup
@tester = Faker::ProgrammingLanguage
end
def test_name
assert_match(/\w/, @tester.name)
end
def test_creator
assert_match(/\w/, @tester.creator)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_omniauth.rb | test/faker/default/test_faker_omniauth.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerInternetOmniauth < Test::Unit::TestCase
def setup
@tester = Faker::Omniauth
end
def test_omniauth_google
auth = @tester.google
provider = auth[:provider]
info = auth[:info]
credentials = auth[:credentials]
extra_raw_info = auth[:extra][:raw_info]
id_info = auth[:extra][:id_info]
plus_url = "https://plus.google.com/#{auth[:uid]}"
openid_id = "https://www.google.com/accounts/o8/id?id=#{auth[:uid]}"
assert_equal 'google_oauth2', provider
assert_equal 9, auth[:uid].length
assert_equal 2, word_count(info[:name])
assert_email_regex info[:first_name], info[:last_name], info[:email]
assert_equal info[:name].split.first, info[:first_name]
assert_equal info[:name].split.last, info[:last_name]
assert_instance_of String, info[:image]
assert_instance_of String, credentials[:token]
assert_instance_of String, credentials[:refresh_token]
assert credentials[:expires]
assert_equal 9, extra_raw_info[:sub].length
assert_equal info[:email], extra_raw_info[:email]
assert_includes %w[true false], extra_raw_info[:email_verified]
assert_equal info[:name], extra_raw_info[:name]
assert_equal info[:first_name], extra_raw_info[:given_name]
assert_equal info[:last_name], extra_raw_info[:family_name]
assert_equal plus_url, extra_raw_info[:profile]
assert_instance_of String, extra_raw_info[:picture]
assert gender?(extra_raw_info[:gender])
assert_instance_of String, extra_raw_info[:birthday]
assert_equal 'en', extra_raw_info[:locale]
assert_instance_of String, extra_raw_info[:hd]
assert_equal 'accounts.google.com', id_info[:iss]
assert_instance_of String, id_info[:at_hash]
assert_includes [true, false], id_info[:email_verified]
assert_equal 28, id_info[:sub].length
assert_equal 'APP_ID', id_info[:azp]
assert_equal info[:email], id_info[:email]
assert_equal 'APP_ID', id_info[:aud]
assert_equal openid_id, id_info[:openid_id]
assert_instance_of Integer, credentials[:expires_at]
assert_instance_of Integer, id_info[:iat]
assert_instance_of Integer, id_info[:exp]
end
def test_omniauth_google_with_name
custom_name = 'Happy Gilmore'
first_name, last_name = custom_name.split
auth = @tester.google(name: custom_name)
info = auth[:info]
extra_raw_info = auth[:extra][:raw_info]
assert_instance_of String, info[:name]
assert_equal 2, word_count(info[:name])
assert_equal custom_name, info[:name]
assert_email_regex first_name, last_name, info[:email]
assert_equal first_name, info[:first_name]
assert_equal last_name, info[:last_name]
assert_equal custom_name, extra_raw_info[:name]
assert_equal first_name, extra_raw_info[:given_name]
assert_equal last_name, extra_raw_info[:family_name]
end
def test_omniauth_google_with_email
custom_email = 'gilmore@happy.com'
auth = @tester.google(email: custom_email)
info = auth[:info]
extra_raw_info = auth[:extra][:raw_info]
id_info = auth[:extra][:id_info]
assert_instance_of String, info[:email]
assert_equal custom_email, info[:email]
assert_equal custom_email, extra_raw_info[:email]
assert_equal custom_email, id_info[:email]
end
def test_omniauth_google_with_uid
custom_uid = '12345'
auth = @tester.google(uid: custom_uid)
extra_raw_info = auth[:extra][:raw_info]
plus_url = "https://plus.google.com/#{custom_uid}"
assert_instance_of String, auth[:uid]
assert_equal custom_uid, auth[:uid]
assert_equal custom_uid, extra_raw_info[:sub]
assert_equal plus_url, extra_raw_info[:profile]
end
def test_omniauth_facebook
auth = @tester.facebook
provider = auth[:provider]
uid = auth[:uid]
info = auth[:info]
credentials = auth[:credentials]
extra_raw_info = auth[:extra][:raw_info]
username = (info[:first_name][0] + info[:last_name]).downcase
location = extra_raw_info[:location]
url = "http://www.facebook.com/#{username}"
assert_equal 'facebook', provider
assert_equal 7, uid.length
assert_email_regex info[:first_name], info[:last_name], info[:email]
assert_equal 2, word_count(info[:name])
assert_instance_of String, info[:first_name]
assert_instance_of String, info[:last_name]
assert_instance_of String, info[:image]
assert boolean?(info[:verified])
assert_instance_of String, credentials[:token]
assert_instance_of Integer, credentials[:expires_at]
assert credentials[:expires]
assert_equal uid, extra_raw_info[:id]
assert_equal info[:name], extra_raw_info[:name]
assert_equal info[:first_name], extra_raw_info[:first_name]
assert_equal info[:last_name], extra_raw_info[:last_name]
assert_equal url, extra_raw_info[:link]
assert_equal username, extra_raw_info[:username]
assert_equal 9, location[:id].length
assert_instance_of String, location[:name]
assert gender?(extra_raw_info[:gender])
assert_equal info[:email], extra_raw_info[:email]
assert_instance_of Integer, extra_raw_info[:timezone]
assert_instance_of String, extra_raw_info[:locale]
assert boolean?(extra_raw_info[:verified])
assert_instance_of String, extra_raw_info[:updated_time]
end
def test_omniauth_facebook_with_name
custom_name = 'Happy Gilmore'
first_name, last_name = custom_name.split
username = (first_name[0] + last_name).downcase
url = "http://www.facebook.com/#{username}"
auth = @tester.facebook(name: custom_name)
info = auth[:info]
extra_raw_info = auth[:extra][:raw_info]
assert_instance_of String, info[:name]
assert_equal 2, word_count(info[:name])
assert_equal custom_name, info[:name]
assert_equal custom_name, extra_raw_info[:name]
assert_instance_of String, info[:first_name]
assert_equal first_name, info[:first_name]
assert_equal first_name, extra_raw_info[:first_name]
assert_instance_of String, info[:last_name]
assert_equal last_name, info[:last_name]
assert_equal last_name, extra_raw_info[:last_name]
assert_email_regex first_name, last_name, info[:email]
assert_equal url, extra_raw_info[:link]
assert_equal username, extra_raw_info[:username]
end
def test_omniauth_facebook_with_username
custom_username = 'hgilmore'
auth = @tester.facebook(username: custom_username)
extra_raw_info = auth[:extra][:raw_info]
url = "http://www.facebook.com/#{custom_username}"
assert_equal custom_username, extra_raw_info[:username]
assert_equal url, extra_raw_info[:link]
end
def test_omniauth_facebook_with_email
custom_email = 'gilmore@happy.com'
auth = @tester.facebook(email: custom_email)
info = auth[:info]
extra_raw_info = auth[:extra][:raw_info]
assert_instance_of String, info[:email]
assert_equal custom_email, info[:email]
assert_equal custom_email, extra_raw_info[:email]
end
def test_omniauth_facebook_with_uid
custom_uid = '12345'
auth = @tester.facebook(uid: custom_uid)
extra_raw_info = auth[:extra][:raw_info]
assert_instance_of String, auth[:uid]
assert_equal custom_uid, auth[:uid]
assert_equal custom_uid, extra_raw_info[:id]
end
def test_omniauth_twitter
auth = @tester.twitter
provider = auth[:provider]
uid = auth[:uid]
info = auth[:info]
urls = info[:urls]
credentials = auth[:credentials]
access_token = auth[:extra][:access_token]
raw_info = auth[:extra][:raw_info]
url = "https://twitter.com/#{info[:nickname]}"
assert_equal 'twitter', provider
assert_equal 6, uid.length
assert_equal info[:name].downcase.delete(' '), info[:nickname]
assert_equal 2, word_count(info[:name])
assert_equal 2, info[:location].split(', ').length
assert_instance_of String, info[:image]
assert_instance_of String, info[:description]
assert_nil urls[:Website]
assert_equal url, urls[:Twitter]
assert_instance_of String, credentials[:token]
assert_instance_of String, credentials[:secret]
assert_instance_of String, access_token
assert_equal info[:name], raw_info[:name]
assert_instance_of Integer, raw_info[:listed_count]
assert_instance_of String, raw_info[:profile_sidebar_border_color]
refute raw_info[:url]
assert_equal 'en', raw_info[:lang]
assert_instance_of Integer, raw_info[:statuses_count]
assert_instance_of String, raw_info[:profile_image_url]
assert_instance_of String, raw_info[:profile_background_image_url_https]
assert_equal info[:location], raw_info[:location]
assert_instance_of String, raw_info[:time_zone]
assert boolean?(raw_info[:follow_request_sent])
assert_equal uid, raw_info[:id]
assert boolean?(raw_info[:profile_background_tile])
assert_instance_of String, raw_info[:profile_sidebar_fill_color]
assert_instance_of Integer, raw_info[:followers_count]
assert boolean?(raw_info[:default_profile_image])
assert_equal '', raw_info[:screen_name]
assert boolean?(raw_info[:following])
assert_instance_of Integer, raw_info[:utc_offset]
assert boolean?(raw_info[:verified])
assert_instance_of Integer, raw_info[:favourites_count]
assert_instance_of String, raw_info[:profile_background_color]
assert boolean?(raw_info[:is_translator])
assert_instance_of Integer, raw_info[:friends_count]
assert boolean?(raw_info[:notifications])
assert boolean?(raw_info[:geo_enabled])
assert_instance_of String, raw_info[:profile_background_image_url]
assert boolean?(raw_info[:protected])
assert_equal info[:description], raw_info[:description]
assert_instance_of String, raw_info[:profile_link_color]
assert_instance_of String, raw_info[:created_at]
assert_equal uid, raw_info[:id_str]
assert_instance_of String, raw_info[:profile_image_url_https]
assert boolean?(raw_info[:default_profile])
assert boolean?(raw_info[:profile_use_background_image])
assert_instance_of Array, raw_info[:entities][:description][:urls]
assert_instance_of String, raw_info[:profile_text_color]
assert boolean?(raw_info[:contributors_enabled])
end
def test_omniauth_twitter_with_name
custom_name = 'Happy Gilmore'
nickname = custom_name.downcase.delete(' ')
url = "https://twitter.com/#{nickname}"
auth = @tester.twitter(name: custom_name)
info = auth[:info]
urls = info[:urls]
raw_info = auth[:extra][:raw_info]
assert_instance_of String, info[:name]
assert_equal custom_name, info[:name]
assert_equal nickname, info[:nickname]
assert_equal 2, word_count(info[:name])
assert_equal url, urls[:Twitter]
assert_equal custom_name, raw_info[:name]
end
def test_omniauth_twitter_with_nickname
custom_nickname = 'hgilmore'
url = "https://twitter.com/#{custom_nickname}"
auth = @tester.twitter(nickname: custom_nickname)
info = auth[:info]
assert_instance_of String, info[:nickname]
assert_equal custom_nickname, info[:nickname]
assert_equal url, info[:urls][:Twitter]
end
def test_omniauth_twitter_with_uid
custom_uid = '12345'
auth = @tester.twitter(uid: custom_uid)
raw_info = auth[:extra][:raw_info]
assert_instance_of String, auth[:uid]
assert_equal custom_uid, auth[:uid]
assert_equal custom_uid, raw_info[:id]
assert_equal custom_uid, raw_info[:id_str]
end
def test_omniauth_linkedin
auth = @tester.linkedin
info = auth[:info]
credentials = auth[:credentials]
extra = auth[:extra]
access_token = extra[:access_token]
params = access_token[:params]
raw_info = extra[:raw_info]
first_name = info[:first_name].downcase
last_name = info[:last_name].downcase
url = "http://www.linkedin.com/in/#{first_name}#{last_name}"
assert_equal 'linkedin', auth[:provider]
assert_equal 6, auth[:uid].length
assert_equal 2, word_count(info[:name])
assert_email_regex first_name, last_name, info[:email]
assert_equal info[:name], info[:nickname]
assert_instance_of String, info[:first_name]
assert_instance_of String, info[:last_name]
assert_equal 2, info[:location].split(', ').count
assert_instance_of String, info[:description]
assert_instance_of String, info[:image]
assert_instance_of String, info[:phone]
assert_instance_of String, info[:headline]
assert_instance_of String, info[:industry]
assert_equal url, info[:urls][:public_profile]
assert_instance_of String, credentials[:token]
assert_instance_of String, credentials[:secret]
assert_equal credentials[:token], access_token[:token]
assert_equal credentials[:secret], access_token[:secret]
refute access_token[:consumer]
assert_equal credentials[:token], params[:oauth_token]
assert_equal credentials[:secret], params[:oauth_token_secret]
assert_instance_of Integer, params[:oauth_expires_in]
assert_instance_of Integer, params[:oauth_authorization_expires_in]
refute access_token[:response]
assert_equal info[:first_name], raw_info[:firstName]
assert_equal info[:headline], raw_info[:headline]
assert_equal auth[:uid], raw_info[:id]
assert_equal info[:industry], raw_info[:industry]
assert_equal info[:last_name], raw_info[:lastName]
assert_instance_of String, raw_info[:location][:country][:code]
assert_instance_of String, raw_info[:location][:name]
assert_instance_of String, raw_info[:pictureUrl]
assert_equal info[:urls][:public_profile], raw_info[:publicProfileUrl]
end
def test_omniauth_linkedin_with_name
custom_name = "Alexis O'Connell"
first_name, last_name = custom_name.split
auth = @tester.linkedin(name: custom_name)
info = auth[:info]
assert_equal 2, word_count(info[:name])
assert_instance_of String, info[:name]
assert_equal custom_name, info[:name]
assert_email_regex first_name, last_name, info[:email]
assert_equal custom_name, info[:nickname]
assert_equal first_name, info[:first_name]
assert_equal last_name, info[:last_name]
end
def test_omniauth_linkedin_with_email
custom_email = 'gilmore@happy.com'
auth = @tester.linkedin(email: custom_email)
info = auth[:info]
assert_equal custom_email, info[:email]
end
def test_omniauth_linkedin_with_uid
custom_uid = '12345'
auth = @tester.linkedin(uid: custom_uid)
extra_raw_info = auth[:extra][:raw_info]
assert_instance_of String, auth[:uid]
assert_equal custom_uid, auth[:uid]
assert_equal custom_uid, extra_raw_info[:id]
end
def test_omniauth_github
auth = @tester.github
provider = auth[:provider]
uid = auth[:uid]
info = auth[:info]
extra_raw_info = auth[:extra][:raw_info]
credentials = auth[:credentials]
name = info[:name]
login = info[:nickname]
html_url = "https://github.com/#{login}"
api_url = "https://api.github.com/users/#{login}"
assert_equal 'github', provider
assert_equal 8, uid.length
assert_equal uid, extra_raw_info[:id]
assert_email_regex info[:first_name], info[:last_name], info[:email]
assert_equal info[:email], extra_raw_info[:email]
assert_equal 2, word_count(name)
assert_instance_of String, name
assert_equal name, extra_raw_info[:name]
assert_equal login, extra_raw_info[:login]
assert_instance_of String, login
assert_instance_of String, info[:image]
assert_instance_of Hash, info[:urls]
assert_instance_of String, info[:urls][:GitHub]
assert_equal html_url, info[:urls][:GitHub]
assert_instance_of String, credentials[:token]
refute credentials[:expires]
assert_instance_of String, extra_raw_info[:avatar_url]
assert_equal '', extra_raw_info[:gravatar_id]
assert_equal api_url, extra_raw_info[:url]
assert_equal html_url, extra_raw_info[:html_url]
assert_equal "#{api_url}/followers", extra_raw_info[:followers_url]
assert_equal "#{api_url}/following{/other_user}", extra_raw_info[:following_url]
assert_equal "#{api_url}/gists{/gist_id}", extra_raw_info[:gists_url]
assert_equal "#{api_url}/starred{/owner}{/repo}", extra_raw_info[:starred_url]
assert_equal "#{api_url}/subscriptions", extra_raw_info[:subscriptions_url]
assert_equal "#{api_url}/orgs", extra_raw_info[:organizations_url]
assert_equal "#{api_url}/repos", extra_raw_info[:repos_url]
assert_equal "#{api_url}/events{/privacy}", extra_raw_info[:events_url]
assert_equal "#{api_url}/received_events", extra_raw_info[:received_events_url]
assert_equal 'User', extra_raw_info[:type]
assert boolean?(extra_raw_info[:site_admin])
assert_nil extra_raw_info[:company]
assert_nil extra_raw_info[:blog]
assert_instance_of String, extra_raw_info[:location]
assert_nil extra_raw_info[:hireable]
assert_nil extra_raw_info[:bio]
assert_instance_of Integer, extra_raw_info[:public_repos]
assert_instance_of Integer, extra_raw_info[:public_gists]
assert_instance_of Integer, extra_raw_info[:followers]
assert_instance_of Integer, extra_raw_info[:following]
assert_instance_of String, extra_raw_info[:created_at]
assert_instance_of String, extra_raw_info[:updated_at]
end
def test_omniauth_github_with_name
custom_name = 'Happy Gilmore'
login = custom_name.split.map(&:downcase).join('-')
auth = @tester.github(name: custom_name)
info = auth[:info]
extra_raw_info = auth[:extra][:raw_info]
assert_equal custom_name, info[:name]
assert_equal 2, word_count(info[:name])
assert_instance_of String, info[:name]
assert_equal custom_name, extra_raw_info[:name]
assert_email_regex info[:first_name], info[:last_name], info[:email]
assert_email_regex info[:first_name], info[:last_name], extra_raw_info[:email]
assert_equal login, info[:nickname]
end
def test_omniauth_github_with_email
custom_email = 'gilmore@happy.com'
auth = @tester.github(email: custom_email)
info = auth[:info]
extra_raw_info = auth[:extra][:raw_info]
assert_instance_of String, info[:email]
assert_equal custom_email, info[:email]
assert_equal custom_email, extra_raw_info[:email]
end
def test_omniauth_github_with_uid
custom_uid = '12345'
auth = @tester.github(uid: custom_uid)
extra_raw_info = auth[:extra][:raw_info]
assert_instance_of String, auth[:uid]
assert_equal custom_uid, auth[:uid]
assert_equal custom_uid, extra_raw_info[:id]
end
def test_omniauth_apple
auth = @tester.apple
info = auth[:info]
credentials = auth[:credentials]
extra = auth[:extra]
raw_info = extra[:raw_info]
first_name = info[:first_name].downcase
last_name = info[:last_name].downcase
assert_equal 'apple', auth[:provider]
assert_instance_of String, auth[:uid]
assert_equal 44, auth[:uid].length
assert_email_regex first_name, last_name, info[:email]
assert_equal auth[:uid], info[:sub]
assert_instance_of String, info[:first_name]
assert_instance_of String, info[:last_name]
assert_instance_of String, credentials[:token]
assert_instance_of String, credentials[:refresh_token]
assert_instance_of Integer, credentials[:expires_at]
assert_instance_of Integer, raw_info[:exp]
assert_instance_of Integer, raw_info[:iat]
assert_instance_of Integer, raw_info[:auth_time]
assert_equal 'https://appleid.apple.com', raw_info[:iss]
assert_instance_of String, raw_info[:aud]
assert_equal auth[:uid], raw_info[:sub]
assert_instance_of String, raw_info[:at_hash]
assert_equal info[:email], raw_info[:email]
assert raw_info[:email_verified]
end
def test_omniauth_auth0
auth = @tester.auth0
info = auth[:info]
credentials = auth[:credentials]
extra = auth[:extra]
raw_info = extra[:raw_info]
nick_name = info[:nickname].downcase
first_name = nick_name.split.first
last_name = nick_name.split.last
assert_equal 'auth0', auth[:provider]
assert_instance_of String, auth[:uid]
assert_equal 30, auth[:uid].length
assert_email_regex first_name, last_name, info[:email]
assert_equal auth[:uid], info[:name]
assert_instance_of String, info[:image]
assert_instance_of String, info[:nickname]
assert_instance_of String, info[:name]
assert_equal auth[:uid], info[:name]
assert credentials[:expires]
assert_instance_of String, credentials[:token]
assert_instance_of String, credentials[:token_type]
assert_instance_of String, credentials[:id_token]
assert_instance_of String, credentials[:refresh_token]
assert_instance_of Integer, credentials[:expires_at]
assert_instance_of Integer, raw_info[:exp]
assert_instance_of Integer, raw_info[:iat]
assert_equal 'https://auth0.com/', raw_info[:iss]
assert_instance_of String, raw_info[:aud]
assert_equal auth[:uid], raw_info[:sub]
assert_equal info[:email], raw_info[:email]
assert raw_info[:email_verified]
end
def word_count(string)
string.split.length
end
def boolean?(test)
!test.nil?
end
def gender?(test)
%w[female male].include?(test)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_camera.rb | test/faker/default/test_faker_camera.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerCamera < Test::Unit::TestCase
def setup
@tester = Faker::Camera
end
def test_brand
assert_match(/\w+/, @tester.brand)
end
def test_model
assert_match(/\w+/, @tester.model)
end
def test_brand_with_model
assert_match(/\w+/, @tester.brand_with_model)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_subscription.rb | test/faker/default/test_faker_subscription.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerSubscription < Test::Unit::TestCase
def setup
@tester = Faker::Subscription
end
def test_plan
assert_match(/\w+/, @tester.plan)
end
def test_status
assert_match(/\w+/, @tester.status)
end
def test_payment_method
assert_match(/\w+/, @tester.payment_method)
end
def test_subscription_term
assert_match(/\w+/, @tester.subscription_term)
end
def test_payment_term
assert_match(/\w+/, @tester.payment_term)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_string.rb | test/faker/default/test_faker_string.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerString < Test::Unit::TestCase
def setup
@tester = Faker::String
end
def teardown
@tester = nil
end
def test_is_string
assert_kind_of String, @tester.random
end
def test_has_valid_encoding
assert_predicate @tester.random, :valid_encoding?
128.times { assert_predicate @tester.random(length: 1..128), :valid_encoding? }
end
def test_is_utf8
assert_equal @tester.random.encoding, Encoding::UTF_8
end
def test_default_length
assert_equal(32, @tester.random.length)
end
def test_nil_is_zero
2.times { assert_empty @tester.random(length: nil) }
end
def test_int_length
[0, -1, 1, rand(500), rand(-2048..2047)].each do |len|
8.times { assert_equal @tester.random(length: len).length, [0, len].max }
end
end
def test_range_length
range = (-5..30)
16.times { assert_includes range, @tester.random(length: range).length }
range = (42..42)
assert_equal(42, @tester.random(length: range).length)
end
def test_array_length
array = [0, -1, 1, 1024, rand(2048)]
8.times { assert_includes array, @tester.random(length: array).length }
num = rand(-2048..2047)
array = [num, num, num]
8.times { assert_equal @tester.random(length: array).length, [0, num].max }
end
def test_nested_lengths
test = lambda do
@tester.random(length: [1, (2..5), [3, (-7...6)], nil])
end
16.times { assert(((0..5).cover? test.call.length)) }
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_types.rb | test/faker/default/test_faker_types.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerTypes < Test::Unit::TestCase
module TestModule
end
def setup
@tester = Faker::Types
end
def test_rb_string_is_or_correct_type
assert_instance_of String, @tester.rb_string
end
def test_string_returns_correct_number_of_words
assert_equal(1, @tester.rb_string(words: 1).split.length)
assert_equal(5, @tester.rb_string(words: 5).split.length)
assert_empty @tester.rb_string(words: 0).split
end
def test_character
assert_equal(1, @tester.character.length)
end
def test_integer
assert_instance_of Integer, @tester.rb_integer
end
def test_rb_integer_between
from = Faker::Number.number.to_i
to = from + Faker::Number.number.to_i
val = @tester.rb_integer(from: from, to: to)
assert val < to && val >= from
end
def test_rb_hash_returns_a_hash
assert_instance_of Hash, @tester.rb_hash
end
def test_hash_returns_the_correct_number_of_keys
assert_equal(3, @tester.rb_hash(number: 3).keys.length)
assert_operator @tester.rb_hash(number: 3).values.uniq.length, :>, 1
assert_empty @tester.rb_hash(number: 0).keys
assert_equal(1, @tester.rb_hash.keys.length)
end
def test_complex_rb_hash_returns_a_hash
assert_instance_of Hash, @tester.complex_rb_hash
end
def test_complex_hash_returns_the_correct_number_of_keys
assert_equal(3, @tester.complex_rb_hash(number: 3).keys.length)
assert_operator @tester.complex_rb_hash(number: 3).values.uniq.length, :>, 1
assert_empty @tester.complex_rb_hash(number: 0).keys
assert_equal(1, @tester.complex_rb_hash.keys.length)
end
def test_rb_array_returns_array
assert_instance_of Array, @tester.rb_array
end
def test_rb_array_returns_right_type_of_array
@tester.rb_array(len: 3, type: -> { @tester.rb_string }).each do |value|
assert_instance_of String, value
end
end
def test_array_has_the_right_array
assert_equal(3, @tester.rb_array(len: 3).length)
assert_empty @tester.rb_array(len: 0)
assert_equal(1, @tester.rb_array.length)
end
def test_titleize
val = 'foobar'
expected = 'Foobar'
assert_equal @tester.send(:titleize, val), expected
end
def test_resolve
array = [1, 2, 3]
range = 1..10
assert_includes array, @tester.send(:resolve, array)
assert_includes range, @tester.send(:resolve, range)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_verb.rb | test/faker/default/test_faker_verb.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerVerb < Test::Unit::TestCase
def setup
@tester = Faker::Verb
end
def test_base
assert_match(/\w+/, @tester.base)
end
def test_past
assert_match(/\w+/, @tester.past)
end
def test_past_participle
assert_match(/\w+/, @tester.past_participle)
end
def test_simple_present
assert_match(/\w+/, @tester.simple_present)
end
def test_ing_form
assert_match(/\w+/, @tester.ing_form)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_esport.rb | test/faker/default/test_faker_esport.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerEsport < Test::Unit::TestCase
def setup
@tester = Faker::Esport
end
def test_team
assert_match(/\w+/, @tester.team)
end
def test_league
assert_match(/\w+/, @tester.league)
end
def test_game
assert_match(/\w+/, @tester.game)
end
def test_player
assert_match(/\w+/, @tester.player)
end
def test_event
assert_match(/\w+/, @tester.event)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_slack_emoji.rb | test/faker/default/test_faker_slack_emoji.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerSlackEmoji < Test::Unit::TestCase
def setup
@tester = Faker::SlackEmoji
@emoticon_regex = /^:([\w-]+):$/
end
def test_people
assert_match @emoticon_regex, @tester.people
end
def test_nature
assert_match @emoticon_regex, @tester.nature
end
def test_food_and_drink
assert_match @emoticon_regex, @tester.food_and_drink
end
def test_celebration
assert_match @emoticon_regex, @tester.celebration
end
def test_activity
assert_match @emoticon_regex, @tester.activity
end
def test_travel_and_places
assert_match @emoticon_regex, @tester.travel_and_places
end
def test_objects_and_symbols
assert_match @emoticon_regex, @tester.objects_and_symbols
end
def test_custom
assert_match @emoticon_regex, @tester.custom
end
def test_emoji
assert_match @emoticon_regex, @tester.emoji
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_array_sample_method_compat.rb | test/faker/default/test_array_sample_method_compat.rb | # frozen_string_literal: true
require_relative '../../test_helper'
# when these tests are run under Ruby 1.8.7, they will use the
# self-defined Array#sample method in lib/extensions/array and will test whether it
# behaves as the built-in Array#sample method from Ruby 1.9 or greater.
# Under Ruby 1.9, they simply use the built-in Array#sample method
class TestArraySampleMethodCompatibility < Test::Unit::TestCase
def test_returns_nil_or_empty_array_with_empty_source
source = []
result = source.sample
assert_nil result
result = source.sample(1)
assert_empty(result)
end
def test_returns_one_array_elem_without_param
source = %w[foo bar]
result = source.sample
assert_includes source, result
end
def test_returns_empty_array_with_param_zero
source = %w[foo bar]
result = source.sample(0)
assert_empty(result)
end
def test_returns_an_array_with_integer_param
source = %w[foo bar baz]
result = source.sample(2)
assert_kind_of Array, result
assert_equal(2, result.length)
assert_empty(result - source)
end
def test_returns_source_array_with_integer_param_equal_or_bigger_than_source_length
source = %w[foo bar]
result = source.sample(2)
assert_kind_of Array, result
assert_predicate(source.sort <=> result.sort, :zero?)
result = source.sample(3)
assert_kind_of Array, result
assert_predicate(source.sort <=> result.sort, :zero?)
end
def test_raises_argument_error_with_negative_param
source = %w[foo bar]
assert_raise ArgumentError do
source.sample(-1)
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_chuck_norris.rb | test/faker/default/test_faker_chuck_norris.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerChuckNorris < Test::Unit::TestCase
def setup
@tester = Faker::ChuckNorris
end
def test_fact
assert_match(/.*chuck.*/i, @tester.fact)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_commerce.rb | test/faker/default/test_faker_commerce.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerCommerce < Test::Unit::TestCase
def setup
@tester = Faker::Commerce
end
def test_color
assert_match(/[a-z]+\.?/, @tester.color)
end
def test_promotion_code
assert_match(/[A-Z][a-z]+[A-Z][a-z]+\d{6}/, @tester.promotion_code)
end
def test_promotion_code_should_have_specified_number_of_digits
assert_match(/[A-Z][a-z]+[A-Z][a-z]+\d{3}/, @tester.promotion_code(digits: 3))
end
def test_department
assert_match(/[A-Z][a-z]+\.?/, @tester.department)
end
def test_single_department_should_not_contain_separators
assert_match(/\A[A-Za-z]+\z/, @tester.department(max: 1))
end
def test_department_should_have_ampersand_as_default_separator
assert_match ' & ', @tester.department(max: 2, fixed_amount: true)
end
def test_department_should_accept_localized_separator
@old_locales = I18n.config.available_locales
data = {
faker: {
separator: ' + ',
commerce: {
department: %w[Books Movies]
}
}
}
I18n.config.available_locales += [:xy]
I18n.backend.store_translations(:xy, data)
I18n.with_locale(:xy) do
assert_match ' + ', @tester.department(max: 2, fixed_amount: true)
end
I18n.config.available_locales = @old_locales
end
def test_department_should_have_exact_number_of_categories_when_fixed_amount
assert_match(/\A([A-Za-z]+, ){8}[A-Za-z]+ & [A-Za-z]+\z/, @tester.department(max: 10, fixed_amount: true))
end
def test_department_should_never_exceed_the_max_number_of_categories_when_random_amount
deterministically_verify -> { @tester.department(max: 6) }, depth: 5 do |result|
assert_match(/\A([A-Za-z]+(, | & )){0,5}[A-Za-z]+\z/, result)
end
end
def test_department_should_have_no_duplicate_categories
department = @tester.department(max: 10, fixed_amount: true)
departments = department.split(/[,& ]+/)
assert_equal departments, departments.uniq
end
def test_product_name
assert_match(/[A-Z][a-z]+\.?/, @tester.product_name)
end
def test_material
assert_match(/[A-Z][a-z]+\.?/, @tester.material)
end
def test_price
assert_includes 0..100, @tester.price
assert_instance_of Float, @tester.price(range: 5..6)
assert_includes 5..6, @tester.price(range: 5..6)
assert_includes 990...1000, @tester.price(range: 990...1000)
end
def test_price_with_srand
Faker::Config.random = Random.new(12_345)
assert_in_delta(92.96, @tester.price)
end
def test_price_is_float
assert_kind_of Float, @tester.price
end
def test_when_as_string_is_true
assert_kind_of String, @tester.price(range: 0..100.0, as_string: true)
assert_includes @tester.price(range: 100..500.0, as_string: true), '.'
end
def test_brand
assert_match(/[A-Z][a-z]+\.?/, @tester.brand)
end
def test_vendor
assert_match(/[A-Z][a-z]+\.?/, @tester.vendor)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_internet_http.rb | test/faker/default/test_faker_internet_http.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerInternetHTTP < Test::Unit::TestCase
def setup
@tester = Faker::Internet::HTTP
end
def test_status_code
assert_match(/^[1-5]\d{2}$/, @tester.status_code.to_s)
end
def test_information_status_code
assert_match(/^1\d{2}$/, @tester.status_code(group: :information).to_s)
end
def test_successful_status_code
assert_match(/^2\d{2}$/, @tester.status_code(group: :successful).to_s)
end
def test_redirect_status_code
assert_match(/^3\d{2}$/, @tester.status_code(group: :redirect).to_s)
end
def test_client_error_status_code
assert_match(/^4\d{2}$/, @tester.status_code(group: :client_error).to_s)
end
def test_server_error_status_code
assert_match(/^5\d{2}$/, @tester.status_code(group: :server_error).to_s)
end
def test_invalid_http_status_code_group
exception = assert_raises ArgumentError do
@tester.status_code(group: :inexistent)
end
assert_equal('Invalid HTTP status code group', exception.message)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_educator.rb | test/faker/default/test_faker_educator.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerEducator < Test::Unit::TestCase
def setup
@tester = Faker::Educator
end
def test_university
assert_match(/(\w+\.? ?){2,3}/, @tester.university)
end
def test_degree
assert_match(/(\w+\.? ?\(?\)?){3,6}/, @tester.degree)
end
def test_subject
assert_match(/(\w+\.? ?\(?\)?){1,3}/, @tester.subject)
end
def test_course_name
assert_match(/(\w+\.? ?\(?\)?){1,3} \d{3}/, @tester.course_name)
end
def test_secondary_school
assert_match(/(\w+\.? ?){2,3}/, @tester.secondary_school)
end
def test_primary_school
assert_match(/(\w+\.? ?){2,3}/, @tester.primary_school)
end
def test_campus
assert_match(/(\w+\.? ?){1,2}/, @tester.campus)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_compass.rb | test/faker/default/test_faker_compass.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerCompass < Test::Unit::TestCase
def setup
@tester = Faker::Compass
@word_pattern = /\w+/
@multiword_pattern = /^\w+ by \w+$/
@combined_pattern = /^(?:\w+|\w+ by \w+|[\w-]+)$/
@number_pattern = /^\d+(?:.\d\d?)?$/
@letter_pattern = /^[NEWS]?[NEWS](?:b?[NEWS])?$/
end
def test_cardinal
assert_match @word_pattern, @tester.cardinal
end
def test_ordinal
assert_match @word_pattern, @tester.ordinal
end
def test_half_wind
assert_match @word_pattern, @tester.half_wind
end
def test_quarter_wind
assert_match @multiword_pattern, @tester.quarter_wind
end
def test_direction
assert_match @combined_pattern, @tester.direction
end
def test_abbreviation
assert_match @letter_pattern, @tester.abbreviation
end
def test_azimuth
assert_match @number_pattern, @tester.azimuth
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_military.rb | test/faker/default/test_faker_military.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerMilitary < Test::Unit::TestCase
def setup
@tester = Faker::Military
end
def test_army_rank
assert_match(/\w/, @tester.army_rank)
end
def test_marines_rank
assert_match(/\w/, @tester.marines_rank)
end
def test_navy_rank
assert_match(/\w/, @tester.navy_rank)
end
def test_air_force_rank
assert_match(/\w/, @tester.air_force_rank)
end
def test_space_force_rank
assert_match(/\w/, @tester.space_force_rank)
end
def test_coast_guard_rank
assert_match(/\w/, @tester.coast_guard_rank)
end
def test_dod_paygrade
assert_match(/\w/, @tester.dod_paygrade)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_restaurant.rb | test/faker/default/test_faker_restaurant.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerRestaurant < Test::Unit::TestCase
def setup
@tester = Faker::Restaurant
end
def test_name
assert_kind_of String, @tester.name
end
def test_type
assert_kind_of String, @tester.type
end
def test_description
assert_kind_of String, @tester.description
end
def test_review
assert_kind_of String, @tester.review
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_avatar.rb | test/faker/default/test_avatar.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerAvatar < Test::Unit::TestCase
def setup
@tester = Faker::Avatar
end
def test_avatar
refute_nil @tester.image.match(%r{https://robohash\.org/(.+)\.png})[1]
end
def test_avatar_with_param
assert_equal('faker', @tester.image(slug: 'faker').match(%r{https://robohash\.org/(.+)\.png})[1])
end
def test_avatar_with_correct_size
assert_equal('150x320', @tester.image(slug: 'faker', size: '150x320').match(%r{https://robohash\.org/faker\.png\?size=(.+)&.*})[1])
end
def test_avatar_with_incorrect_size
assert_raise ArgumentError do
@tester.image(slug: nil, size: '150x320z')
end
end
def test_avatar_with_supported_format
assert_match %r{https://robohash\.org/faker\.jpg}, @tester.image(slug: 'faker', size: '300x300', format: 'jpg')
end
def test_avatar_with_incorrect_format
assert_raise ArgumentError do
@tester.image(slug: nil, size: '300x300', format: 'wrong_format')
end
end
def test_avatar_with_set
assert_match %r{https://robohash\.org/faker\.jpg.*set=set2}, @tester.image(slug: 'faker', size: '300x300', format: 'jpg', set: 'set2')
end
def test_avatar_with_bgset
assert_match %r{https://robohash\.org/faker\.jpg.*bgset=bg1}, @tester.image(slug: 'faker', size: '300x300', format: 'jpg', set: 'set1', bgset: 'bg1')
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_artist.rb | test/faker/default/test_faker_artist.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerArtist < Test::Unit::TestCase
def setup
@tester = Faker::Artist
end
def test_name
assert_match(/\w+/, @tester.name)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_blood.rb | test/faker/default/test_faker_blood.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerBlood < Test::Unit::TestCase
def setup
@tester = Faker::Blood
end
def test_type
assert_match(/^(AB|A|B|O)$/, @tester.type)
end
def test_rh_factor
assert_match(/[+-]/, @tester.rh_factor)
end
def test_group
assert_match(/^(AB|A|B|O)[+-]$/, @tester.group)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_markdown.rb | test/faker/default/test_faker_markdown.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerMarkdown < Test::Unit::TestCase
def setup
@tester = Faker::Markdown
@random_method = random_method
end
def test_headers
test_trigger = @tester.headers.split
assert_equal(2, test_trigger.length)
assert_includes(test_trigger.first, '#')
end
def test_emphasis
test_trigger = @tester.emphasis.chars
assert(test_trigger.to_set.intersect?(['_', '~', '*', '**'].to_set))
end
def test_ordered_list
test_trigger = @tester.ordered_list.split("\n")
test_trigger.each do |line|
assert_instance_of(Integer, line[0].to_i)
end
end
def test_unordered_list
test_trigger = @tester.unordered_list.split("\n")
test_trigger.each do |line|
assert_equal('*', line[0])
end
end
def test_inline_code
test_trigger = @tester.inline_code.chars
assert_equal('`', test_trigger.first)
assert_equal('`', test_trigger.last)
end
def test_block_code
test_trigger = @tester.block_code.chars
assert_equal('`', test_trigger[0])
assert_equal('`', test_trigger[1])
assert_equal('`', test_trigger[2])
assert_equal('`', test_trigger[-1])
assert_equal('`', test_trigger[-2])
assert_equal('`', test_trigger[-3])
end
def test_table
test_trigger = @tester.table.split("\n")
test_trigger.each do |table_data|
assert_instance_of(String, table_data)
end
assert_equal(4, test_trigger.length)
assert_equal('---- | ---- | ----', test_trigger[1])
end
def test_random
test_trigger = @tester.random
assert_instance_of(String, test_trigger)
end
def test_random_with_a_randomly_excluded_method
excluded_method = @random_method
test_trigger = @tester.random(excluded_method)
20.times do
refute_equal(test_trigger, @tester.send(excluded_method))
end
end
def test_sandwich
test_trigger = @tester.sandwich
test_array = []
test_trigger.each_line { |substr| test_array << substr }
assert_operator(test_array.length, :>=, 3)
assert_equal(2, test_array[0].split.length)
assert_includes(test_array[0].split.first, '#')
assert_instance_of(String, test_array[0])
assert_instance_of(String, test_array[1])
assert_instance_of(String, test_array[2])
end
private
def random_method
method_list = Faker::Markdown.public_methods(false) - Faker::Base.methods
method_list[rand(0..(method_list.length - 1))]
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_nato_phonetic_alphabet.rb | test/faker/default/test_nato_phonetic_alphabet.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerNatoPhoneticAlphabet < Test::Unit::TestCase
def setup
@tester = Faker::NatoPhoneticAlphabet
end
def test_code_word
assert_match(/\w+/, @tester.code_word)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_stripe.rb | test/faker/default/test_faker_stripe.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerStripe < Test::Unit::TestCase
def setup
@tester = Faker::Stripe
end
def test_valid_card
assert_match(/\A\d{14,16}\z/, @tester.valid_card)
end
def test_valid_card_error
e = assert_raise ArgumentError do
assert @tester.valid_card(card_type: Faker::Lorem.word)
end
assert_match(/\AValid credit cards argument can be left blank or include/, e.message)
end
def test_specific_valid_card
assert_match(/\A\d{16}\z/, @tester.valid_card(card_type: 'visa'))
end
def test_valid_token
assert_match(/\w+/, @tester.valid_token)
end
def test_specific_valid_token
assert_match(/\Atok_visa\z/, @tester.valid_token(card_type: 'visa'))
end
def test_invalid_card
assert_match(/\A\d{16}\z/, @tester.invalid_card)
end
def test_invalid_card_error
e = assert_raise ArgumentError do
assert @tester.invalid_card(card_error: Faker::Lorem.word)
end
assert_match(/\AInvalid credit cards argument can be left blank or include/, e.message)
end
def test_specific_error_invalid_card
assert_match(/\w+/, @tester.invalid_card(card_error: 'zipFail'))
end
def test_valid_exp_mo
assert_match(/\A\d{2}\z/, @tester.month)
end
def test_valid_exp_yr
assert_match(/\A\d{4}\z/, @tester.year)
end
def test_valid_ccv
assert_match(/\A\d{3}\z/, @tester.ccv)
end
def test_valid_amex_ccv
assert_match(/\A\d{4}\z/, @tester.ccv(card_type: 'amex'))
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_invoice.rb | test/faker/default/test_invoice.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerInvoice < Test::Unit::TestCase
def setup
@tester = Faker::Invoice
end
def test_amount_between
from = 1.0
to = 1000.0
deterministically_verify -> { @tester.amount_between(from: from, to: to) }, depth: 5 do |random_amount|
assert_operator random_amount, :>=, from, "Expected >= \"#{from}\", but got #{random_amount}"
assert_operator random_amount, :<=, to, "Expected <= \"#{to}\", but got #{random_amount}"
end
end
def test_creditor_reference
reference = @tester.creditor_reference
assert_match(/RF\d{2}\d{4,20}/, reference)
end
def test_reference
reference = @tester.reference
assert_match(/\d{4,20}/, reference)
end
def test_reference_checksum
reference = @tester.reference(ref: '515141803475128#')
assert_equal('5151418034751285', reference)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_funny_name.rb | test/faker/default/test_faker_funny_name.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerFunnyName < Test::Unit::TestCase
def setup
@tester = Faker::FunnyName
end
def test_name
res = @tester.name
assert res.is_a?(String) && !res.empty?
end
def test_two_word_name
res = @tester.two_word_name
assert_equal(1, res.count(' '))
end
def test_three_word_name
res = @tester.three_word_name
assert_equal(2, res.count(' '))
end
def test_four_word_name
res = @tester.four_word_name
assert_equal(3, res.count(' '))
end
def test_name_with_initial
res = @tester.name_with_initial
assert_predicate res.count('.'), :positive?
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_team.rb | test/faker/default/test_faker_team.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerTeam < Test::Unit::TestCase
def setup
@tester = Faker::Team
end
def test_name
assert_match(/(\w+\.? ?){2}/, @tester.name)
end
def test_creature
assert_match(/(\w+){1}/, @tester.creature)
end
def test_state
assert_match(/(\w+){1}/, @tester.state)
end
def test_sport
assert_match(/(\w+){1}/, @tester.sport)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_dc_comics.rb | test/faker/default/test_faker_dc_comics.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerDcComics < Test::Unit::TestCase
def setup
@tester = Faker::DcComics
end
def test_hero
assert_match(/\w+/, @tester.hero)
end
def test_heroine
assert_match(/\w+/, @tester.heroine)
end
def test_villain
assert_match(/\w+/, @tester.villain)
end
def test_name
assert_match(/\w+/, @tester.name)
end
def test_title
assert_match(/(\w+\.? ?){2,3}/, @tester.title)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_superhero.rb | test/faker/default/test_faker_superhero.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerSuperhero < Test::Unit::TestCase
def setup
@tester = Faker::Superhero
end
def test_power
assert_match(/\w+\.?/, @tester.power)
end
def test_name
assert_match(/\w+\.?/, @tester.name)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_file.rb | test/faker/default/test_faker_file.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerFile < Test::Unit::TestCase
def setup
@tester = Faker::File
end
def test_extension
assert_match(/(flac|mp3|wav|bmp|gif|jpeg|jpg|png|tiff|css|csv|html|js|json|txt|mp4|avi|mov|webm|doc|docx|xls|xlsx|ppt|pptx|odt|ods|odp|pages|numbers|key|pdf)/, @tester.extension)
end
def test_mime_type_format
assert_match %r{(.*)/(.*)+}, @tester.mime_type
end
def test_mime_type_format_with_media_type
media_type = Faker::Base.translate('faker.file.mime_type').keys.sample
assert_match %r{#{media_type}/(.*)+}, @tester.mime_type(media_type: media_type)
end
def test_file_name
assert_match %r{^([a-z\-_.]+)(\\|/)([a-z\-_]+)\.([a-z0-9]+)$}, @tester
.file_name
end
def test_dir
assert_match %r{^(([a-z\-_.]+)(\\|/)){2}([a-z\-_.]+)$}, @tester.dir
end
def test_dir_with_args
assert_match %r{^\\root(\\([a-z\-_.]+)){2}$}, @tester
.dir(segment_count: 2, root: '\\root\\', directory_separator: '\\')
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_twitter.rb | test/faker/default/test_twitter.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerTwitter < Test::Unit::TestCase
def setup
@tester = Faker::Twitter
end
def test_user
user = @tester.user
assert_kind_of Hash, user
assert_equal(41, user.keys.count)
assert_kind_of Hash, user[:status]
assert_nil user[:status][:user]
end
def test_user_with_email
user = @tester.user(include_email: true)
assert_kind_of Hash, user
assert_equal(42, user.keys.count)
assert_kind_of String, user[:email]
end
def test_user_without_status
user = @tester.user(include_status: false)
assert_kind_of Hash, user
assert_equal(40, user.keys.count)
assert_nil user[:status]
end
def test_status
status = @tester.status
assert_kind_of Hash, status
assert_equal(25, status.keys.count)
assert_kind_of Hash, status[:entities]
assert_kind_of Hash, status[:user]
assert_nil status[:user][:status]
end
def test_status_without_user
status = @tester.status(include_user: false)
assert_kind_of Hash, status
assert_equal(24, status.keys.count)
assert_nil status[:user]
end
def test_status_with_photo
status = @tester.status(include_photo: true)
assert_kind_of Hash, status
assert_equal(25, status.keys.count)
assert_kind_of Hash, status[:entities]
assert_equal(1, status[:entities][:media].count)
assert_equal(10, status[:entities][:media].first.keys.count)
end
def test_screen_name
assert_kind_of String, @tester.screen_name
end
end
class TestFakerX < Test::Unit::TestCase
def setup
@tester = Faker::X
end
def test_user
user = @tester.user
assert_kind_of Hash, user
assert_kind_of Array, user[:data]
assert_kind_of Hash, user[:includes]
assert_kind_of Array, user[:includes][:users]
end
def test_tweet
tweet = @tester.tweet
assert_kind_of Hash, tweet
assert_kind_of Array, tweet[:data]
assert_nil tweet[:includes]
end
def test_tweet_with_include_media
tweet = @tester.tweet(include_media: true)
assert_kind_of Hash, tweet
assert_kind_of Array, tweet[:data]
assert_kind_of Array, tweet[:includes][:media]
end
def test_tweet_with_include_user
tweet = @tester.tweet(include_user: true)
assert_kind_of Hash, tweet
assert_kind_of Array, tweet[:data]
assert_kind_of Array, tweet[:includes][:users]
end
def test_tweet_with_include_user_and_include_media
tweet = @tester.tweet(include_user: true, include_media: true)
assert_kind_of Hash, tweet
assert_kind_of Array, tweet[:data]
assert_kind_of Array, tweet[:includes][:users]
assert_kind_of Array, tweet[:includes][:media]
end
def test_screen_name
assert_kind_of String, @tester.screen_name
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_date.rb | test/faker/default/test_faker_date.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerDate < Test::Unit::TestCase
def setup
@tester = Faker::Date
end
def test_between
from = Date.parse('2012-01-01')
to = Date.parse('2013-01-01')
deterministically_verify -> { @tester.between(from: from, to: to) }, depth: 5 do |random_date|
assert_operator random_date, :>=, from, "Expected >= \"#{from}\", but got #{random_date}"
assert_operator random_date, :<=, to, "Expected <= \"#{to}\", but got #{random_date}"
end
end
def test_between_except
from = Date.parse('2012-01-01')
to = Date.parse('2012-01-05')
excepted = Date.parse('2012-01-03')
deterministically_verify -> { @tester.between_except(from: from, to: to, excepted: excepted) }, depth: 5 do |random_date|
assert_not_nil random_date
refute_equal random_date, excepted, "Expected != \"#{excepted}\", but got #{random_date}"
end
end
def test_between_except_with_strings
from = '2012-01-01'
to = '2012-01-05'
excepted = '2012-01-03'
excepted_date = Date.parse(excepted)
deterministically_verify -> { @tester.between_except(from: from, to: to, excepted: excepted) }, depth: 5 do |random_date|
assert_not_nil random_date
refute_equal random_date, excepted_date, "Expected != \"#{excepted}\", but got #{random_date}"
end
end
def test_between_except_with_same_from_to_and_except
assert_raise ArgumentError do
@tester.between_except('2012-01-01', '2012-01-01', '2012-01-01')
end
end
def test_forward
today = Date.today
deterministically_verify -> { @tester.forward(days: 5) }, depth: 5 do |random_date|
assert_operator random_date, :>, today, "Expected > \"#{today}\", but got #{random_date}"
end
end
def test_forward_with_from_parameter
from = Date.parse('2012-01-01')
five_days_after_from = from + 5
random_date = @tester.forward(from: from, days: 5)
assert_operator random_date, :>, from, "Expected > \"#{from}\", but got #{random_date}"
assert_operator five_days_after_from, :>, from, "Expected < \"#{from}\", but got #{random_date}"
end
def test_forward_with_string_parameter
from = '2012-01-01'
from_date = Date.parse(from)
deterministically_verify -> { @tester.forward(from: from, days: 5) }, depth: 5 do |random_date|
assert_operator random_date, :>, from_date, "Expected > \"#{from}\", but got #{random_date}"
end
end
def test_backward
today = Date.today
deterministically_verify -> { @tester.backward(days: 5) }, depth: 5 do |random_date|
assert_operator random_date, :<, today, "Expected < \"#{today}\", but got #{random_date}"
end
end
def test_return_type
random_forward = @tester.forward(days: 5)
random_backward = @tester.backward(days: 5)
random_between = @tester.between(from: Date.today, to: Date.today + 5)
[random_forward, random_backward, random_between].each do |result|
assert_kind_of Date, result, "Expected a Date object, but got #{result.class}"
end
end
def test_invalid_date
assert_raise ArgumentError do
@tester.between('9999-99-99', '9999-99-99')
end
end
def test_birthday
min = 40
max = 90
t = Date.today
birthdate_min = Date.new(t.year - max, t.month, t.day)
birthdate_max = Date.new(t.year - min, t.month, t.day)
deterministically_verify -> { @tester.birthday(min_age: min, max_age: max) }, depth: 5 do |birthday|
assert_operator birthday, :>=, birthdate_min, "Expect >= \"#{birthdate_min}\", but got #{birthday}"
assert_operator birthday, :<=, birthdate_max, "Expect <= \"#{birthdate_max}\", but got #{birthday}"
end
end
def test_birthday_when_min_age_equals_max_age
min = 0
max = 0
birthday = @tester.birthday(min_age: min, max_age: max)
assert_equal birthday, Date.today
end
def test_birthday_on_newborns
min = 0
max = 4
t = Date.today
birthdate_min = Date.new(t.year - max, t.month, t.day)
birthdate_max = Date.new(t.year - min, t.month, t.day)
birthdays = []
10.times do
birthday = @tester.birthday(min_age: min, max_age: max)
birthdays << birthday
assert_operator birthday, :>=, birthdate_min, "Expect >= \"#{birthdate_min}\", but got #{birthday}"
assert_operator birthday, :<=, birthdate_max, "Expect <= \"#{birthdate_max}\", but got #{birthday}"
end
assert_operator birthdays.uniq.size, :>, 1
end
def test_default_birthday
min = 10
max = 65
t = Date.today
birthdate_min = Date.new(t.year - max, t.month, t.day)
birthdate_max = Date.new(t.year - min, t.month, t.day)
deterministically_verify -> { @tester.birthday }, depth: 5 do |birthday|
assert_operator birthday, :>=, birthdate_min, "Expect >= \"#{birthdate_min}\", but got #{birthday}"
assert_operator birthday, :<, birthdate_max, "Expect < \"#{birthdate_max}\", but got #{birthday}"
end
end
def test_default_in_date_period
current_year = Date.today.year
deterministically_verify -> { @tester.in_date_period } do |date|
assert_equal date.year, current_year
end
end
def test_in_date_period_with_year
year = 2015
deterministically_verify -> { @tester.in_date_period(year: year) } do |date|
assert_equal date.year, year
end
end
def test_in_date_period_with_month
month = 2
current_year = Date.today.year
deterministically_verify -> { @tester.in_date_period(month: month) } do |date|
assert_equal date.month, month
assert_equal date.year, current_year
end
end
def test_in_date_period_date
year = 2008
month = 3
deterministically_verify -> { @tester.in_date_period(year: year, month: month) } do |date|
assert_equal date.month, month
assert_equal date.year, year
end
end
def test_on_day_of_week_between
days = %i[tuesday saturday]
from = Date.parse('2012-01-01')
to = Date.parse('2012-02-01')
deterministically_verify -> { @tester.on_day_of_week_between(day: days, from: from, to: to) } do |date|
assert_operator date, :>=, from, "Expected >= \"#{from}\", but got #{date}"
assert_operator date, :<=, to, "Expected <= \"#{to}\", but got #{date}"
assert date.tuesday? || date.saturday?, "Expected #{date} to be Tuesday or Saturday, but was #{Faker::Date::DAYS_OF_WEEK[date.wday].capitalize}"
end
end
def test_unknown_day_of_week
error = assert_raise ArgumentError do
@tester.on_day_of_week_between(day: :unknown, from: '2012-01-01', to: '2013-01-01')
end
assert_equal 'unknown is not a valid day of the week', error.message
end
def test_empty_day_of_week
error = assert_raise ArgumentError do
@tester.on_day_of_week_between(day: [], from: '2012-01-01', to: '2013-01-01')
end
assert_equal 'Day of week cannot be empty', error.message
end
def test_day_of_week_outside_date_range
error = assert_raise ArgumentError do
@tester.on_day_of_week_between(day: :friday, from: '2012-01-01', to: '2012-01-03')
end
assert_equal 'There is no Friday between 2012-01-01 and 2012-01-03. Increase the from/to date range or choose a different day of the week.',
error.message
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_color.rb | test/faker/default/test_faker_color.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerColor < Test::Unit::TestCase
def setup
@tester = Faker::Color
end
def test_color_name
assert_match(/[a-z]+\.?/, @tester.color_name)
end
def test_hex_color
assert_match(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/, @tester.hex_color)
end
# @see https://www.rapidtables.com/convert/color/rgb-to-hsl.html
def helper_hex_lightness(hex_color)
result = hex_color.scan(/([A-Fa-f0-9]{2})/).flatten.map { |x| x.hex / 255.0 }
(result.max + result.min) / 2
end
def test_hex_color_light
assert_in_delta(0.8, helper_hex_lightness(@tester.hex_color(:light)))
end
def test_hex_color_dark
assert_in_delta(0.2, helper_hex_lightness(@tester.hex_color(:dark)))
end
def test_hex_color_with_hash_is_passed_to_hsl_color
mock_hsl_color = lambda do |args|
assert_equal(100, args[:hue])
assert_in_delta(0.2, args[:saturation])
assert_in_delta(0.8, args[:lightness])
[args[:hue], args[:saturation], args[:lightness]]
end
@tester.stub :hsl_color, mock_hsl_color do
result = @tester.hex_color(hue: 100, saturation: 0.2, lightness: 0.8)
assert_match(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/, result)
end
end
def test_single_rgb_color
assert @tester.single_rgb_color.between?(0, 255)
end
def test_rgb_color
@result = @tester.rgb_color
assert_equal(3, @result.length)
@result.each do |color|
assert color.between?(0, 255)
end
end
def test_hsl_color
@result = @tester.hsl_color
assert_equal(3, @result.length)
assert @result[0].between?(0, 360)
assert_kind_of Integer, @result[0]
assert @result[1].between?(0.0, 1.0)
assert @result[2].between?(0.0, 1.0)
end
def test_hsl_color_with_a_speficied_hue
@result = @tester.hsl_color(hue: 5)
assert_in_delta(5, @result[0])
end
def test_hsl_color_with_a_speficied_saturation
@result = @tester.hsl_color(saturation: 0.35)
assert_in_delta(0.35, @result[1])
end
def test_hsl_color_with_a_speficied_but_invalid_saturation
@result = @tester.hsl_color(saturation: 3.05)
assert_in_delta(1, @result[1])
end
def test_hsl_color_with_a_speficied_lightness
@result = @tester.hsl_color(lightness: 0.5)
assert_in_delta(0.5, @result[2])
end
def test_hsl_color_with_a_speficied_but_invalid_lightness
@result = @tester.hsl_color(lightness: -2.5)
assert_in_delta(0, @result[2])
end
def test_hsla_color
@result = @tester.hsla_color
assert_equal(4, @result.length)
assert @result[0].between?(0, 360)
assert @result[1].between?(0.0, 1.0)
assert @result[2].between?(0.0, 1.0)
assert @result[3].between?(0.0, 1.0)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_drone.rb | test/faker/default/test_faker_drone.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerDrone < Test::Unit::TestCase
def setup
@tester = Faker::Drone
end
def test_name
assert_match(/[A-Za-z0-9]+/, @tester.name)
end
def test_weight
assert_match(/[0-9]{3}\sg/, @tester.weight)
end
def test_max_ascent_speed
assert_match(/[0-9]\sm\/s/, @tester.max_ascent_speed)
end
def test_max_descent_speed
assert_match(/[0-9]\sm\/s/, @tester.max_descent_speed)
end
def test_max_flight_time
assert_match(/[0-9]{2} min/, @tester.flight_time)
end
def test_max_altitude
assert_match(/[0-9]{4}\sm/, @tester.max_altitude)
end
def test_max_flight_distance
assert_match(/[0-9]{4}\sm/, @tester.max_flight_distance)
end
def test_max_speed
assert_match(/[0-9]{2}\sm\/s/, @tester.max_speed)
end
def test_max_wind_resistance
assert_match(/[0-9]{2}\.[0-9]\sm\/s/, @tester.max_wind_resistance)
end
def test_max_anngular_velocity
assert_match(/[0-9]{2}\W\/s/, @tester.max_angular_velocity)
end
def test_max_tilt_angle
assert_match(/[0-9]{2}\W/, @tester.max_tilt_angle)
end
def test_operating_temperature
assert_match(/[0-9]{2}\W-[0-9]{3}\WF/, @tester.operating_temperature)
end
def test_battery_capacity
assert_match(/[2-3][0-9]{3}\smAh/, @tester.battery_capacity)
end
def test_battery_type
assert_match(/Li(Po\s|-)[3-4]*[A-Za-z]+/, @tester.battery_type)
end
def test_battery_weight
assert_match(/[0-9]{3}\sg/, @tester.battery_weight)
end
def test_battery_voltage
assert_match(/[0-9]{2}\.[0-9]V/, @tester.battery_voltage)
end
def test_charging_temperature
assert_match(/[0-9]{2}\W-[0-9]{3}\WF/, @tester.charging_temperature)
end
def test_max_charging_power
assert_match(/[0-9]{2}W/, @tester.max_charging_power)
end
def test_camera_iso
assert_match(/(100-3200|100-6400)/, @tester.iso)
end
def test_max_resolution
assert_match(/[0-9]{2}MP/, @tester.max_resolution)
end
def test_photo_format
assert_match(/(JPEG|PNG|TIF)/, @tester.photo_format)
end
def video_format
assert_match(/MP4|FLV|MOV/, @tester.video_format)
end
def test_max_shutter_speed_range
assert_match(/[0-9]{1,2}-1\/[0-9]{1,4}s/, @tester.shutter_speed_range)
end
def test_max_shutter_speed
assert_match(/[0-9]{1,2}s/, @tester.max_shutter_speed)
end
def test_min_shutter_speed
assert_match(/1\/[0-9]{1,4}s/, @tester.min_shutter_speed)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_company.rb | test/faker/default/test_faker_company.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerCompany < Test::Unit::TestCase
def setup
@tester = Faker::Company
end
def test_ein
assert_match(/\d\d-\d\d\d\d\d\d\d/, @tester.ein)
end
def test_duns_number
assert_match(/\d\d-\d\d\d-\d\d\d\d/, @tester.duns_number)
end
def test_logo
assert_match %r{https://pigment.github.io/fake-logos/logos/medium/color/\d+\.png}, @tester.logo
end
def test_buzzword
assert_match(/\w+\.?/, @tester.buzzword)
end
def test_type
assert_match(/\w+/, @tester.type)
end
def test_spanish_organisation_number
assert cif_valid?(@tester.spanish_organisation_number(organization_type: 'A'))
assert cif_valid?(@tester.spanish_organisation_number)
end
def test_swedish_organisation_number
org_no = @tester.swedish_organisation_number
assert_match(/\d{10}/, org_no)
assert_includes [1, 2, 3, 5, 6, 7, 8, 9], org_no[0].to_i
assert_operator org_no[2].to_i, :>=, 2
assert_equal org_no[9], @tester.send(:luhn_algorithm, org_no[0..8]).to_s
end
def test_czech_organisation_number
org_no = @tester.czech_organisation_number
assert_match(/\d{8}/, org_no)
assert_includes [0, 1, 2, 3, 5, 6, 7, 8, 9], org_no[0].to_i
assert_equal czech_o_n_checksum(org_no), org_no[-1].to_i
end
def test_french_siren_number
siren = @tester.french_siren_number
assert_match(/\A\d{9}\z/, siren)
assert_equal siren[8], @tester.send(:luhn_algorithm, siren[0..-2]).to_s
end
def test_french_siret_number
siret = @tester.french_siret_number
assert_match(/\A\d{14}\z/, siret)
assert_equal siret[8], @tester.send(:luhn_algorithm, siret[0..7]).to_s
assert_equal siret[13], @tester.send(:luhn_algorithm, siret[0..-2]).to_s
end
def test_norwegian_organisation_number
org_no = @tester.norwegian_organisation_number
assert_match(/\d{9}/, org_no)
assert_includes [8, 9], org_no[0].to_i
assert_equal org_no[8], @tester.send(:mod11, org_no[0..7]).to_s
end
def test_australian_business_number
abn = @tester.australian_business_number
checksum = abn_checksum(abn)
assert_match(/\d{11}/, abn)
assert_predicate(checksum % 89, :zero?)
end
def test_profession
assert_match(/[a-z ]+\.?/, @tester.profession)
end
def test_department
assert_match(/\w+/, @tester.department)
end
def test_polish_taxpayer_identification_number
number = @tester.polish_taxpayer_identification_number
control_sum = 0
[6, 5, 7, 2, 3, 4, 5, 6, 7].each.with_index do |control, index|
control_sum += control * number[index].to_i
end
refute_equal control_sum.modulo(11), 10
end
def test_polish_register_of_national_economy
# 8 length should fail
assert_raise ArgumentError do
@tester.polish_register_of_national_economy(length: 8)
end
# 9 length
number = @tester.polish_register_of_national_economy
control_sum = 0
[8, 9, 2, 3, 4, 5, 6, 7].each.with_index do |control, index|
control_sum += control * number[index].to_i
end
control_number = control_sum.modulo(11) == 10 ? 0 : control_sum.modulo(11)
assert_equal control_number, number[8].to_i
# 14 length
number = @tester.polish_register_of_national_economy(length: 14)
control_sum = 0
[2, 4, 8, 5, 0, 9, 7, 3, 6, 1, 2, 4, 8].each.with_index do |control, index|
control_sum += control * number[index].to_i
end
control_number = control_sum.modulo(11) == 10 ? 0 : control_sum.modulo(11)
assert_equal control_number, number[13].to_i
end
def test_mod11
assert @tester.send(:mod11, 0)
end
def test_south_african_pty_ltd_registration_number
assert_match(
/\A\d{4}\/\d{4,10}\/07\z/,
@tester.south_african_pty_ltd_registration_number
)
end
def test_south_african_close_corporation_registration_number
assert_match(
/\A(CK\d{2}|\d{4})\/\d{4,10}\/23\z/,
@tester.south_african_close_corporation_registration_number
)
end
def test_south_african_listed_company_registration_number
assert_match(
/\A\d{4}\/\d{4,10}\/06\z/,
@tester.south_african_listed_company_registration_number
)
end
def test_south_african_trust_registration_number
assert_match(
/\AIT\d{2,4}\/\d{2,10}\z/,
@tester.south_african_trust_registration_number
)
end
def test_luhn_algorithm
# Odd length base for luhn algorithm
odd_base = Faker::Number.number(digits: [5, 7, 9, 11, 13].sample)
odd_luhn_complement = @tester.send(:luhn_algorithm, odd_base).to_s
odd_control = "#{odd_base}#{odd_luhn_complement}"
# Even length base for luhn algorithm
even_base = Faker::Number.number(digits: [4, 6, 8, 10, 12].sample)
even_luhn_complement = @tester.send(:luhn_algorithm, even_base).to_s
even_control = "#{even_base}#{even_luhn_complement}"
assert_predicate(luhn_checksum(odd_control) % 10, :zero?)
assert_predicate(luhn_checksum(even_control) % 10, :zero?)
end
def test_brazilian_company_number
sample = @tester.brazilian_company_number
assert_match(/^\d{14}$/, sample)
digit_sum = sample[0..11].chars.each.with_index.inject(0) do |acc, (digit, i)|
factor = 2 + (3 - i) % 8
acc + digit.to_i * factor
end
remainder = digit_sum % 11
first_digit = remainder < 2 ? '0' : (11 - remainder).to_s
assert_equal sample[12], first_digit
digit_sum = sample[0..12].chars.each.with_index.inject(0) do |acc, (digit, i)|
factor = 2 + (4 - i) % 8
acc + digit.to_i * factor
end
remainder = digit_sum % 11
second_digit = remainder < 2 ? '0' : (11 - remainder).to_s
assert_equal sample[13], second_digit
end
def test_brazilian_company_number_formatted
sample = @tester.brazilian_company_number(formatted: true)
assert_match(/^\d{2}\.\d{3}\.\d{3}\/\d{4}-\d{2}$/, sample)
end
def test_russian_tax_number_default
assert_match(/\d{10}/, @tester.russian_tax_number)
end
def test_russian_tax_number_individual
assert_match(/\d{12}/, @tester.russian_tax_number(type: :individual))
end
def test_russian_tax_number_region
assert_match(/^77/, @tester.russian_tax_number(region: '77'))
end
def test_russian_tax_number_checksum
base_number = @tester.russian_tax_number
number = base_number[0..-2]
checksum = base_number.chars.last.to_i
assert_predicate(inn_checksum(number) - checksum, :zero?)
end
def test_sic_code
assert_match(/\d\d\d\d/, @tester.sic_code)
end
def test_spanish_cif_control_digit
assert_equal(4, @tester.send(:spanish_cif_control_digit, 'A', '2217680'))
assert_equal(7, @tester.send(:spanish_cif_control_digit, 'B', '4031315'))
assert_equal(9, @tester.send(:spanish_cif_control_digit, 'C', '7191088'))
assert_equal(6, @tester.send(:spanish_cif_control_digit, 'D', '3178686'))
assert_equal(3, @tester.send(:spanish_cif_control_digit, 'E', '4484441'))
assert_equal(4, @tester.send(:spanish_cif_control_digit, 'F', '4830511'))
assert_equal(3, @tester.send(:spanish_cif_control_digit, 'G', '7676903'))
assert_equal(2, @tester.send(:spanish_cif_control_digit, 'H', '8888075'))
assert_equal(5, @tester.send(:spanish_cif_control_digit, 'J', '6840041'))
assert_equal('G', @tester.send(:spanish_cif_control_digit, 'N', '5350867'))
assert_equal('H', @tester.send(:spanish_cif_control_digit, 'P', '5669582'))
assert_equal('D', @tester.send(:spanish_cif_control_digit, 'Q', '5182823'))
assert_equal('E', @tester.send(:spanish_cif_control_digit, 'R', '1099088'))
assert_equal('H', @tester.send(:spanish_cif_control_digit, 'S', '2210399'))
assert_equal(8, @tester.send(:spanish_cif_control_digit, 'U', '3957325'))
assert_equal(4, @tester.send(:spanish_cif_control_digit, 'V', '7536342'))
assert_equal('B', @tester.send(:spanish_cif_control_digit, 'W', '6793772'))
end
def test_spanish_b_algorithm
assert_equal(4, @tester.send(:spanish_b_algorithm, 2))
assert_equal(3, @tester.send(:spanish_b_algorithm, 6))
end
def text_indian_gst_number
assert_match(/^([0-2][0-9]|3[0-7])[A-Z]{3}[ABCFGHLJPTK][A-Z]\d{4}[A-Z][A-Z0-9]Z[A-Z0-9]$/i, @tester.indian_gst_number)
end
def test_state_code_in_indian_gst_number
assert_raise ArgumentError do
@tester.indian_gst_number(state_code: '01')
end
assert_raise ArgumentError do
@tester.indian_gst_number(state_code: '100')
end
end
def test_indian_gst_number_with_state_code
assert_match(/^(22)[A-Z]{3}[ABCFGHLJPTK][A-Z]\d{4}[A-Z][A-Z0-9]Z[A-Z0-9]$/i, @tester.indian_gst_number(state_code: '22'))
end
private
def czech_o_n_checksum(org_no)
weights = [8, 7, 6, 5, 4, 3, 2]
sum = 0
digits = org_no.chars.map(&:to_i)
weights.each.with_index.map do |w, i|
sum += (w * digits[i])
end
(11 - (sum % 11)) % 10
end
def abn_checksum(abn)
abn_weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
abn.chars.map(&:to_i).each.with_index.map do |n, i|
(i.zero? ? n - 1 : n) * abn_weights[i]
end.inject(:+)
end
def luhn_checksum(luhn)
luhn_split = luhn.each_char.map(&:to_i).reverse.each.with_index.map do |n, i|
x = i.odd? ? n * 2 : n
x > 9 ? x - 9 : x
end
luhn_split.compact.inject(0) { |sum, x| sum + x }
end
def inn_checksum(number)
[2, 4, 10, 3, 5, 9, 4, 6, 8].map.with_index.reduce(0) do |v, i|
v + i[0] * number[i[1]].to_i
end % 11 % 10
end
def cif_valid?(cif)
letters_cif = %w[A B C D E F G H J N P Q R S U V W]
letter_cif_number = %w[P Q S W]
letters_cif_control = %w[J A B C D E F G H I]
regex_cif = /^(#{letters_cif.join('|')})-?(\d{7})-?(\d|#{letters_cif_control.join('|')})$/
if cif =~ regex_cif
number = Regexp.last_match(2)
first_letter = Regexp.last_match(1)
province_code = number[0..1]
actual_control = Regexp.last_match(3)
total = number.chars.each.with_index.inject(0) do |acc, (element, index)|
acc + if index.even?
(element.to_i * 2).digits.inject(:+)
else
element.to_i
end
end
decimal = total.digits.first
expected_control = decimal.zero? ? decimal : 10 - decimal
# Control code must be a letter
return letters_cif_control[expected_control] if letter_cif_number.include?(first_letter) ||
province_code == '00'
# Control code will be a number or a letter
return [expected_control.to_s,
letters_cif_control[expected_control]].include?(actual_control)
end
false
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_nation.rb | test/faker/default/test_faker_nation.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerNation < Test::Unit::TestCase
def setup
@tester = Faker::Nation
end
def test_flag
assert_match(/\p{M}*+/, @tester.flag)
end
def test_nationality
assert_match(/(\w+\.? ?){2,3}/, @tester.nationality)
end
def test_language
assert_match(/[A-Z][a-z]+\.?/, @tester.language)
end
def test_capital_city
assert_match(/(\w+\.? ?){2,3}/, @tester.capital_city)
end
def test_national_sport
assert_match(/(\w+\.? ?){2,3}/, @tester.national_sport)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_greek_philosophers.rb | test/faker/default/test_faker_greek_philosophers.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerGreekPhilosophers < Test::Unit::TestCase
def setup
@tester = Faker::GreekPhilosophers
end
def test_name
assert_match(/\w+/, @tester.name)
end
def test_quote
assert_match(/\w+/, @tester.quote)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_address.rb | test/faker/default/test_faker_address.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerAddress < Test::Unit::TestCase
def setup
@tester = Faker::Address
end
def test_city
assert_match(/\w+/, @tester.city)
end
def test_city_with_state
assert_match(/\w+,\s\w+/, @tester.city(options: { with_state: true }))
end
def test_street_name
assert_match(/\w+\s\w+/, @tester.street_name)
end
def test_street_address
assert_match(/\d+\s\w+\s\w+/, @tester.street_address)
end
def test_secondary_address
assert_match(/\w+\.?\s\d+/, @tester.secondary_address)
end
def test_building_number
assert_match(/\d+/, @tester.building_number)
end
def test_mail_box
assert_match(/[\w ]+\d+/, @tester.mail_box)
end
def test_zip_code
assert_match(/^\d+-?\d*$/, @tester.zip_code)
end
def test_time_zone
assert_match %r{\w+/\w+}, @tester.time_zone
end
def test_street_suffix
assert_match(/\w+/, @tester.street_suffix)
end
def test_city_suffix
assert_match(/\w+/, @tester.city_suffix)
end
def test_city_prefix
assert_match(/\w+/, @tester.city_prefix)
end
def test_state_abbr
assert_match(/[A-Z]{2}/, @tester.state_abbr)
end
def test_state
assert_match(/\w+/, @tester.state)
end
def test_country
assert_match(/\w+/, @tester.country)
end
def test_country_by_code
assert_match @tester.country_by_code(code: 'NL'), 'Netherlands'
end
def test_country_name_to_code
assert_match @tester.country_name_to_code(name: 'united_states'), 'US'
end
def test_country_code
assert_match(/[A-Z]{2}/, @tester.country_code)
end
def test_latitude
assert_instance_of Float, @tester.latitude
end
def test_longitude
assert_instance_of Float, @tester.longitude
end
def test_full_address
assert_match(/\w*\.?\s?\d*\s?\d+\s\w+\s\w+,\s\w+\s?\w*,\s[A-Z]{2}\s\d+/, @tester.full_address)
end
def test_full_address_as_hash
assert_instance_of Hash, @tester.full_address_as_hash
end
def test_full_address_as_hash_by_longitude
assert_instance_of Float, @tester.full_address_as_hash(:longitude)[:longitude]
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_coffee.rb | test/faker/default/test_faker_coffee.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerCoffee < Test::Unit::TestCase
def setup
@tester = Faker::Coffee
@countries = Faker::Base.fetch_all('coffee.country')
@intensifiers = Faker::Base.fetch_all('coffee.intensifier')
@body_descriptors = Faker::Base.fetch_all('coffee.body')
@flavor_descriptors = Faker::Base.fetch_all('coffee.descriptor')
@varieties = Faker::Base.fetch_all('coffee.variety')
blend_name_words_one = Faker::Base.fetch_all('coffee.name_1')
blend_name_words_two = Faker::Base.fetch_all('coffee.name_2')
@name_words = blend_name_words_one.dup.concat(blend_name_words_two)
end
def test_origin
assert origin = @tester.origin.match(/\A(?<region>(?:[[:alnum:]]+'?-?.?,?\s?){1,5}), (?<country>(?:[[:alnum:]]+\s?){1,5})\z/)
region = origin[:region]
country = origin[:country]
search_format_country = country.split.length > 1 ? country.downcase.split.join('_') : country.downcase
regions = Faker::Base.fetch_all("coffee.regions.#{search_format_country}")
assert_includes @countries, country
assert_includes regions, region
end
def test_notes
assert notes = @tester.notes
.match(/\A(?<intensifier>[\s\w-]+), (?<body>[\s\w-]+), (?<f1>[!\s\w-]+), (?<f2>[!\s\w-]+), (?<f3>[!\s\w-]+)\z/)
assert_includes @intensifiers, notes[:intensifier]
assert_includes @body_descriptors, notes[:body]
[notes[:f1], notes[:f2], notes[:f3]].each do |flavor|
assert_includes @flavor_descriptors, flavor
end
end
def test_variety
assert_match(/\w+\.?/, @tester.variety)
assert_includes @varieties, @tester.variety
end
def test_blend_name
assert blend = @tester.blend_name.match(/(([[:alnum:]]+(-?\w*)*('?\w+)?) ?){1,}/)
blend[0].split.each do |word|
assert_includes @name_words, word
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_theater.rb | test/faker/default/test_faker_theater.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerTheater < Test::Unit::TestCase
def test_adult_musical
assert_match(/\w+/, Faker::Theater.adult_musical)
end
def test_kids_musical
assert_match(/\w+/, Faker::Theater.kids_musical)
end
def test_play
assert_match(/\w+/, Faker::Theater.play)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_lorem_flickr.rb | test/faker/default/test_faker_lorem_flickr.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerLoremFlickr < Test::Unit::TestCase
def setup
@tester = Faker::LoremFlickr
@colorizations = %w[red green blue]
end
def test_image
assert_equal('https://loremflickr.com/300/300', @tester.image)
end
def test_image_with_size
assert_equal('https://loremflickr.com/50/60', @tester.image(size: '50x60'))
end
def test_image_with_incorrect_size
assert_raise ArgumentError do
@tester.image(size: '300x300s')
end
end
def test_image_with_single_search_term
assert_equal('https://loremflickr.com/50/60/faker', @tester.image(size: '50x60', search_terms: %w[faker]))
end
def test_image_with_multiple_search_terms
assert_equal('https://loremflickr.com/50/60/dog,cat', @tester.image(size: '50x60', search_terms: %w[dog cat]))
end
def test_image_with_search_terms_and_match_all
assert_equal('https://loremflickr.com/50/60/dog,cat/all', @tester.image(size: '50x60', search_terms: %w[dog cat], match_all: true))
end
def test_grayscale_image
assert_equal('https://loremflickr.com/g/300/300/all', @tester.grayscale_image)
end
def test_grayscale_image_with_incorrect_size
assert_raise ArgumentError do
@tester.grayscale_image(size: '300x300s')
end
end
def test_grayscale_image_without_search_terms
assert_equal('https://loremflickr.com/g/50/60/all', @tester.grayscale_image(size: '50x60'))
end
def test_grayscale_image_with_single_search_term
assert_equal('https://loremflickr.com/g/50/60/faker', @tester.grayscale_image(size: '50x60', search_terms: %w[faker]))
end
def test_grayscale_image_with_multiple_search_terms
assert_equal('https://loremflickr.com/g/50/60/dog,cat', @tester.grayscale_image(size: '50x60', search_terms: %w[dog cat]))
end
def test_grayscale_image_with_search_terms_and_match_all
assert_equal('https://loremflickr.com/g/50/60/dog,cat/all', @tester.grayscale_image(size: '50x60', search_terms: %w[dog cat], match_all: true))
end
def test_pixelated_image
assert_equal('https://loremflickr.com/p/300/300/all', @tester.pixelated_image)
end
def test_pixelated_image_with_incorrect_size
assert_raise ArgumentError do
@tester.pixelated_image(size: '300x300s')
end
end
def test_pixelated_image_without_search_terms
assert_equal('https://loremflickr.com/p/50/60/all', @tester.pixelated_image(size: '50x60'))
end
def test_pixelated_image_with_single_search_term
assert_equal('https://loremflickr.com/p/50/60/faker', @tester.pixelated_image(size: '50x60', search_terms: %w[faker]))
end
def test_pixelated_image_with_multiple_search_terms
assert_equal('https://loremflickr.com/p/50/60/dog,cat', @tester.pixelated_image(size: '50x60', search_terms: %w[dog cat]))
end
def test_pixelated_image_with_search_terms_and_match_all
assert_equal('https://loremflickr.com/p/50/60/dog,cat/all', @tester.pixelated_image(size: '50x60', search_terms: %w[dog cat], match_all: true))
end
def test_colorized_image
assert_equal('https://loremflickr.com/red/300/300/all', @tester.colorized_image)
end
def test_colorized_image_with_incorrect_size
assert_raise ArgumentError do
@tester.colorized_image(size: '300x300s')
end
end
def test_colorized_image_without_search_terms
assert_equal('https://loremflickr.com/red/50/60/all', @tester.colorized_image(size: '50x60', color: 'red'))
end
def test_colorized_image_with_unsupported_colorization
assert_raise ArgumentError do
@tester.colorized_image(size: '50x60', color: 'yellow')
end
end
def test_colorized_image_with_single_search_term
@colorizations.each do |colorization|
assert_equal @tester.colorized_image(size: '50x60', color: colorization, search_terms: %w[faker]), "https://loremflickr.com/#{colorization}/50/60/faker"
end
end
def test_colorized_image_with_multiple_search_terms
@colorizations.each do |colorization|
assert_equal @tester.colorized_image(size: '50x60', color: colorization, search_terms: %w[dog cat]), "https://loremflickr.com/#{colorization}/50/60/dog,cat"
end
end
def test_colorized_image_with_search_terms_and_match_all
@colorizations.each do |colorization|
assert_equal @tester.colorized_image(size: '50x60', color: colorization, search_terms: %w[dog cat], match_all: true), "https://loremflickr.com/#{colorization}/50/60/dog,cat/all"
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_char.rb | test/faker/default/test_faker_char.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerChar < Test::Unit::TestCase
def setup
@tester = Faker::Char
end
def test_fix_umlauts
assert_equal('ae', @tester.fix_umlauts('ä'))
assert_equal('oe', @tester.fix_umlauts('ö'))
assert_equal('ue', @tester.fix_umlauts('ü'))
assert_equal('ss', @tester.fix_umlauts('ß'))
# tests false positive
assert_equal('ss', @tester.fix_umlauts('ss'))
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_tea.rb | test/faker/default/test_faker_tea.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerTea < Test::Unit::TestCase
def setup
@tester = Faker::Tea
@types = Faker::Base.fetch_all('tea.type')
@varieties_by_type = @types.to_h do |type|
[type, Faker::Base.fetch_all("tea.variety.#{type.downcase}")]
end
@varieties = @varieties_by_type.values.flatten
end
def test_variety
assert(@varieties.all? do |variety|
variety.match?(/^(?:[A-Z]['.\-a-z]+[\s-])*(?:[A-Z]['.\-a-z]+)$/)
end)
assert_includes @varieties, @tester.variety
end
def test_variety_with_argument
@types.each do |type|
assert_includes @varieties_by_type[type], @tester.variety(type: type)
end
end
def test_types
assert @types.all? { |type| type.match?(/^[A-Z][a-z]+$/) }
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_appliance.rb | test/faker/default/test_faker_appliance.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerAppliance < Test::Unit::TestCase
def setup
@tester = Faker::Appliance
end
def test_brand
assert_match(/\w/, @tester.brand)
end
def test_equipment
assert_match(/\w/, @tester.equipment)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_food.rb | test/faker/default/test_faker_food.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerFood < Test::Unit::TestCase
def setup
@tester = Faker::Food
end
def test_flexible_key
assert_equal(:food, @tester.flexible_key)
end
def test_allergen
assert_match(/\w+/, @tester.allergen)
end
def test_dish
assert_match(/\w+/, @tester.dish)
end
def test_description
assert_match(/\w+/, @tester.description)
end
def test_ingredient
assert_match(/\w+/, @tester.ingredient)
end
def test_fruits
assert_match(/\w+/, @tester.fruits)
end
def test_vegetables
assert_match(/\w+/, @tester.vegetables)
end
def test_spice
assert_match(/\w+/, @tester.spice)
end
def test_sushi
assert_match(/\w+/, @tester.sushi)
end
def test_measurement
assert_equal(2, @tester.measurement.split.length)
end
def test_metric_measurement
assert_match(/\w+/, @tester.metric_measurement)
end
def test_ethnic_category
assert_match(/\w+/, @tester.ethnic_category)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_app.rb | test/faker/default/test_faker_app.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerApp < Test::Unit::TestCase
def setup
@tester = Faker::App
end
def test_name
assert_match(/(\w+\.? ?){2,3}/, @tester.author)
end
def test_basic_semantic_version
deterministically_verify -> { @tester.semantic_version.split('.') } do |test_sem_vers|
assert_match(/[0-9]{1}/, test_sem_vers[0])
assert_match(/[0-9]{1}/, test_sem_vers[1])
assert_match(/[1-9]{1}/, test_sem_vers[2])
end
end
def test_major_semantic_version
deterministically_verify -> { @tester.semantic_version(major: (1000..9999)).split('.') } do |test_sem_vers|
assert_match(/[0-9]{4}/, test_sem_vers[0])
assert_match(/[0-9]{1}/, test_sem_vers[1])
assert_match(/[1-9]{1}/, test_sem_vers[2])
end
end
def test_minor_semantic_version
deterministically_verify -> { @tester.semantic_version(minor: (1000..9999)).split('.') } do |test_sem_vers|
assert_match(/[0-9]{1}/, test_sem_vers[0])
assert_match(/[0-9]{4}/, test_sem_vers[1])
assert_match(/[1-9]{1}/, test_sem_vers[2])
end
end
def test_patch_semantic_version
deterministically_verify -> { @tester.semantic_version(patch: (1000..9999)).split('.') } do |test_sem_vers|
assert_match(/[0-9]{1}/, test_sem_vers[0])
assert_match(/[0-9]{1}/, test_sem_vers[1])
assert_match(/[0-9]{4}/, test_sem_vers[2])
end
end
def test_all_semantic_version
deterministically_verify -> { @tester.semantic_version(major: (1000..9999), minor: (1000..9999), patch: (1000..9999)).split('.') } do |test_sem_vers|
assert_match(/[0-9]{4}/, test_sem_vers[0])
assert_match(/[0-9]{4}/, test_sem_vers[1])
assert_match(/[0-9]{4}/, test_sem_vers[2])
end
end
def test_specific_major_version
assert_match(/42\.[0-9]\.[0-9]/, @tester.semantic_version(major: 42))
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_industry_segments.rb | test/faker/default/test_faker_industry_segments.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerIndustrySegments < Test::Unit::TestCase
def setup
@tester = Faker::IndustrySegments
end
def test_industry
assert_match(/(\w+\.? ?){2,3}/, @tester.industry)
end
def test_super_sector
assert_match(/(\w+\.? ?){2,3}/, @tester.super_sector)
end
def test_sector
assert_match(/(\w+\.? ?){2,3}/, @tester.sector)
end
def test_sub_sector
assert_match(/(\w+\.? ?){2,3}/, @tester.sub_sector)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_mountain.rb | test/faker/default/test_faker_mountain.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerMountain < Test::Unit::TestCase
def setup
@tester = Faker::Mountain
end
def test_name
assert_match(/\w+/, @tester.name)
end
def test_range
assert_match(/\w+/, @tester.range)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_national_health_service.rb | test/faker/default/test_faker_national_health_service.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerNationalHealthService < Test::Unit::TestCase
def setup
@tester = Faker::NationalHealthService
end
def test_nhs_british_number
assert_match(/\A9{3}\s\d{3}\s\d{4}\z/, @tester.british_number)
end
def test_check_digit_equals_10
Faker::NationalHealthService.stub(:rand, 999_464_033) do
assert_match('999 464 0321', @tester.british_number)
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_half_life.rb | test/faker/default/test_half_life.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerGamesHalfLife < Test::Unit::TestCase
def setup
@tester = Faker::Games::HalfLife
end
def test_character
assert_match(/\w+/, @tester.character)
end
def test_enemy
assert_match(/\w+/, @tester.enemy)
end
def test_location
assert_match(/\w+/, @tester.location)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_country_code.rb | test/faker/default/test_country_code.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestCountryCode < Test::Unit::TestCase
def setup
@previous_locale = Faker::Config.locale
Faker::Config.locale = 'en'
end
def teardown
Faker::Config.locale = @previous_locale
end
def test_country_code_expected_length
assert_equal(2, Faker::Address.country_code.length)
end
def test_country_code_long_expected_length
assert_equal(3, Faker::Address.country_code_long.length)
end
def test_all_country_code_have_country
codes = Faker::Base.fetch_all('address.country_code')
lonely_codes = codes.reject do |code|
Faker::Address.country_by_code(code: code)
rescue I18n::MissingTranslationData
nil
end
assert_empty(lonely_codes)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_street.rb | test/faker/default/test_faker_street.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerStreet < Test::Unit::TestCase
def setup
@tester = Faker::Address
@old_locales = I18n.config.available_locales
# rubocop:disable Lint/InterpolationCheck
shire = {
faker: {
address: {
street_name: ['#{street_prefix} #{street_root} #{street_suffix}'],
street_prefix: ['Wide'],
street_root: ['Cheerful'],
street_suffix: ['Path'],
secondary_address: ['(Green Door)'],
street_address: ['#{street_name} #{building_number}'],
building_number: ['#'],
community_prefix: ['Pine'],
community_suffix: ['Place'],
time_zone: ['Pacific/Pago_Pago']
}
}
}
# rubocop:enable Lint/InterpolationCheck
I18n.config.available_locales += [:shire]
I18n.backend.store_translations(:shire, shire)
end
def teardown
I18n.config.available_locales = @old_locales
end
def test_street_name_supports_flexible_formats
I18n.with_locale(:shire) do
assert_equal 'Wide Cheerful Path', @tester.street_name
end
end
def test_street_address_supports_flexible_formats
I18n.with_locale(:shire) do
assert_match(/Wide Cheerful Path \d/, @tester.street_address)
end
end
def test_community_supports_flexible_formats
I18n.with_locale(:shire) do
assert_match(/Pine Place/, @tester.community)
end
end
def test_street_address_optionally_provides_secondary_address
I18n.with_locale(:shire) do
assert_match(/Wide Cheerful Path \d \(Green Door\)/, @tester.street_address(include_secondary: true))
end
end
def test_street_address_with_locale_fallback
I18n.with_locale('en-GB') do
assert_match(/^\d+ [\w']+ \w+/, @tester.street_address)
end
end
def test_timezone_support
I18n.with_locale(:shire) do
assert_equal 'Pacific/Pago_Pago', @tester.time_zone
end
end
def test_full_address
I18n.with_locale('en') do
assert_match(/^(.+\s)?\d+ [\w'\s]+, [\w'\s]+, [\w']+ \d+/, @tester.full_address)
end
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
faker-ruby/faker | https://github.com/faker-ruby/faker/blob/a4d5e503edda970fc085e942018ee235622bfb11/test/faker/default/test_faker_cosmere.rb | test/faker/default/test_faker_cosmere.rb | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerCosmere < Test::Unit::TestCase
def setup
@tester = Faker::Cosmere
end
def test_aon
assert_match(/\w+\.?/, @tester.aon)
end
def test_shard_world
assert_match(/\w+\.?/, @tester.shard_world)
end
def test_shard
assert_match(/\w+\.?/, @tester.shard)
end
def test_surge
assert_match(/\w+\.?/, @tester.surge)
end
def test_knight_radiant
assert_match(/\w+\.?/, @tester.knight_radiant)
end
def test_metal
assert_match(/\w+\.?/, @tester.metal)
end
def test_allomancer
assert_match(/\w+\.?/, @tester.allomancer)
end
def test_herald
assert_match(/\w+\.?/, @tester.herald)
end
def test_spren
assert_match(/\w+\.?/, @tester.spren)
end
end
| ruby | MIT | a4d5e503edda970fc085e942018ee235622bfb11 | 2026-01-04T15:37:50.353881Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.