ffaker 2.21.0 → 2.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +131 -17
- data/Gemfile +15 -0
- data/README.md +18 -6
- data/REFERENCE.md +1012 -969
- data/Rakefile +16 -47
- data/bin/console +9 -0
- data/ffaker.gemspec +9 -23
- data/lib/ffaker/address.rb +4 -4
- data/lib/ffaker/address_fr.rb +3 -5
- data/lib/ffaker/address_it.rb +1 -4
- data/lib/ffaker/address_ua.rb +1 -1
- data/lib/ffaker/avatar.rb +11 -3
- data/lib/ffaker/bank.rb +1 -1
- data/lib/ffaker/bank_us.rb +33 -0
- data/lib/ffaker/book.rb +15 -7
- data/lib/ffaker/cheesy_lingo.rb +2 -2
- data/lib/ffaker/code.rb +1 -1
- data/lib/ffaker/company.rb +2 -2
- data/lib/ffaker/company_fr.rb +2 -2
- data/lib/ffaker/crypto.rb +14 -0
- data/lib/ffaker/data/address_de/state +1 -0
- data/lib/ffaker/data/jo_jo/first_names +356 -0
- data/lib/ffaker/data/jo_jo/full_names +225 -0
- data/lib/ffaker/data/jo_jo/last_names +153 -0
- data/lib/ffaker/data/jo_jo/stands +149 -0
- data/lib/ffaker/date.rb +40 -0
- data/lib/ffaker/filesystem.rb +12 -2
- data/lib/ffaker/geolocation.rb +2 -2
- data/lib/ffaker/identification_br.rb +3 -12
- data/lib/ffaker/identification_ec.rb +39 -0
- data/lib/ffaker/identification_es_cl.rb +2 -2
- data/lib/ffaker/identification_es_co.rb +1 -1
- data/lib/ffaker/identification_kr.rb +11 -4
- data/lib/ffaker/identification_pl.rb +6 -6
- data/lib/ffaker/identification_tw.rb +1 -1
- data/lib/ffaker/image.rb +28 -4
- data/lib/ffaker/jo_jo.rb +24 -0
- data/lib/ffaker/lorem_ja.rb +1 -1
- data/lib/ffaker/lorem_ru.rb +1 -1
- data/lib/ffaker/movie.rb +1 -1
- data/lib/ffaker/name_fr.rb +4 -3
- data/lib/ffaker/name_pl.rb +1 -1
- data/lib/ffaker/number.rb +6 -2
- data/lib/ffaker/phone_number_de.rb +3 -3
- data/lib/ffaker/skill.rb +1 -1
- data/lib/ffaker/ssn.rb +4 -2
- data/lib/ffaker/ssn_se.rb +2 -2
- data/lib/ffaker/string.rb +1 -1
- data/lib/ffaker/time.rb +3 -3
- data/lib/ffaker/utils/module_utils.rb +5 -6
- data/lib/ffaker/utils/unique_utils.rb +33 -21
- data/lib/ffaker/vehicle.rb +2 -2
- data/lib/{version.rb → ffaker/version.rb} +1 -1
- data/lib/ffaker.rb +63 -191
- data/scripts/reference.rb +8 -10
- data/test/helper.rb +3 -5
- data/test/test_address_da.rb +3 -3
- data/test/test_address_fi.rb +2 -2
- data/test/test_address_se.rb +2 -2
- data/test/test_avatar.rb +30 -7
- data/test/test_bank_us.rb +35 -0
- data/test/test_book.rb +29 -0
- data/test/test_cheesy_lingo.rb +1 -1
- data/test/test_color.rb +3 -3
- data/test/test_crypto.rb +15 -0
- data/test/test_date.rb +47 -0
- data/test/test_filesystem.rb +30 -4
- data/test/test_freedom_ipsum.rb +1 -1
- data/test/test_gender_it.rb +1 -1
- data/test/test_gender_ja.rb +1 -1
- data/test/test_gender_jp.rb +1 -1
- data/test/test_gender_pl.rb +1 -1
- data/test/test_healthcare_ru.rb +1 -1
- data/test/test_hipster_ipsum.rb +1 -1
- data/test/test_html_ipsum.rb +2 -2
- data/test/test_identification.rb +12 -2
- data/test/test_identification_ec.rb +33 -0
- data/test/test_identification_es_mx.rb +3 -1
- data/test/test_identification_it.rb +12 -1
- data/test/test_identification_kr.rb +3 -3
- data/test/test_image.rb +51 -5
- data/test/test_internet.rb +3 -1
- data/test/test_internet_se.rb +5 -2
- data/test/test_jo_jo.rb +29 -0
- data/test/test_lorem_br.rb +2 -2
- data/test/test_lorem_cn.rb +3 -3
- data/test/test_lorem_fr.rb +3 -3
- data/test/test_lorem_ie.rb +2 -2
- data/test/test_lorem_kr.rb +3 -3
- data/test/test_lorem_pl.rb +2 -2
- data/test/test_lorem_ru.rb +3 -3
- data/test/test_lorem_ua.rb +3 -3
- data/test/test_module_utils.rb +33 -0
- data/test/test_name_da.rb +1 -1
- data/test/test_name_ph.rb +1 -1
- data/test/test_name_ru.rb +2 -2
- data/test/test_name_ua.rb +2 -2
- data/test/test_number.rb +13 -1
- data/test/test_phone_number_nl.rb +1 -1
- data/test/test_phone_number_se.rb +1 -1
- data/test/test_phone_number_sg.rb +8 -8
- data/test/test_unique_utils.rb +29 -5
- data/test/test_units.rb +6 -6
- data/test/test_units_english.rb +15 -15
- data/test/test_units_metric.rb +15 -15
- data/test/test_vehicle.rb +22 -0
- metadata +24 -241
@@ -13,7 +13,7 @@ module FFaker
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def const_missing(const_name)
|
16
|
-
if const_name
|
16
|
+
if const_name.match?(/[a-z]/) # Not a constant, probably a class/module name.
|
17
17
|
super const_name
|
18
18
|
else
|
19
19
|
mod_name = ancestors.first.to_s.split('::').last
|
@@ -25,7 +25,7 @@ module FFaker
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def underscore(string)
|
28
|
-
string.gsub(
|
28
|
+
string.gsub('::', '/')
|
29
29
|
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
30
30
|
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
31
31
|
.tr('-', '_')
|
@@ -33,14 +33,14 @@ module FFaker
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def unique(max_retries = 10_000)
|
36
|
-
|
36
|
+
FFaker::UniqueUtils.add_instance(self, max_retries)
|
37
37
|
end
|
38
38
|
|
39
39
|
# http://en.wikipedia.org/wiki/Luhn_algorithm
|
40
40
|
def luhn_check(number)
|
41
41
|
multiplications = []
|
42
42
|
|
43
|
-
number.
|
43
|
+
number.chars.each_with_index do |digit, i|
|
44
44
|
multiplications << i.even? ? digit.to_i * 2 : digit.to_i
|
45
45
|
end
|
46
46
|
|
@@ -51,9 +51,8 @@ module FFaker
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
control_digit = (sum % 10).zero? ? 0 : (sum / 10 + 1) * 10 - sum
|
54
|
+
control_digit = (sum % 10).zero? ? 0 : (((sum / 10) + 1) * 10) - sum
|
55
55
|
control_digit.to_s
|
56
56
|
end
|
57
|
-
|
58
57
|
end
|
59
58
|
end
|
@@ -1,44 +1,56 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'set'
|
3
4
|
|
4
5
|
module FFaker
|
5
6
|
class UniqueUtils
|
6
|
-
|
7
|
-
@generator = generator
|
8
|
-
@max_retries = max_retries
|
9
|
-
@previous_results = Hash.new { |hash, key| hash[key] = Set.new }
|
10
|
-
end
|
7
|
+
RetryLimitExceeded = Class.new(StandardError)
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
class << self
|
10
|
+
def add_instance(generator, max_retries)
|
11
|
+
instances[generator] ||= FFaker::UniqueUtils.new(generator, max_retries)
|
12
|
+
end
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
def instances
|
15
|
+
Thread.current[:ffaker_unique_utils] ||= {}
|
16
|
+
end
|
19
17
|
|
20
|
-
|
18
|
+
def clear
|
19
|
+
instances.each_value(&:clear)
|
20
|
+
instances.clear
|
21
|
+
end
|
22
|
+
end
|
21
23
|
|
22
|
-
def
|
23
|
-
@
|
24
|
+
def initialize(generator, max_retries)
|
25
|
+
@generator = generator
|
26
|
+
@max_retries = max_retries
|
24
27
|
end
|
25
28
|
|
26
|
-
def
|
27
|
-
|
29
|
+
def clear
|
30
|
+
previous_results.clear
|
28
31
|
end
|
29
32
|
|
30
33
|
private
|
31
34
|
|
32
|
-
def
|
35
|
+
def method_missing(name, *args, **kwargs)
|
33
36
|
@max_retries.times do
|
34
|
-
result = @generator.
|
37
|
+
result = @generator.public_send(name, *args, **kwargs)
|
35
38
|
|
36
|
-
next if
|
39
|
+
next if previous_results[[name, args, kwargs]].include?(result)
|
37
40
|
|
38
|
-
|
41
|
+
previous_results[[name, args, kwargs]] << result
|
39
42
|
return result
|
40
43
|
end
|
41
|
-
|
44
|
+
|
45
|
+
raise RetryLimitExceeded, "Retry limit exceeded for #{name}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def respond_to_missing?(name, *args)
|
49
|
+
@generator.respond_to?(name, *args) || super
|
50
|
+
end
|
51
|
+
|
52
|
+
def previous_results
|
53
|
+
@previous_results ||= Hash.new { |hash, key| hash[key] = Set.new }
|
42
54
|
end
|
43
55
|
end
|
44
56
|
end
|
data/lib/ffaker/vehicle.rb
CHANGED
@@ -7,7 +7,7 @@ module FFaker
|
|
7
7
|
extend self
|
8
8
|
|
9
9
|
# https://en.wikibooks.org/wiki/Vehicle_Identification_Numbers_(VIN_codes)/World_Manufacturer_Identifier_(WMI)
|
10
|
-
VALID_WMI_REGIONS = [*'A'..'C', *'J'..'Z', *'1'..'9'].freeze
|
10
|
+
VALID_WMI_REGIONS = [*'A'..'C', *'J'..'N', 'P', *'R'..'Z', *'1'..'9'].freeze
|
11
11
|
|
12
12
|
VALID_YEAR_CHARS = %w[
|
13
13
|
5 6 7 8 9 A B C D E F G H J K L M N P R S T V W X Y 1 2 3 4 5 6 7 8 9
|
@@ -53,7 +53,7 @@ module FFaker
|
|
53
53
|
|
54
54
|
# Calculate the Check Digit
|
55
55
|
weighted_sum = generated_vin.chars.each_with_index.sum do |char, idx|
|
56
|
-
(TRANSLITERATION_VALUES[char
|
56
|
+
(TRANSLITERATION_VALUES[char] || char).to_i * POSITION_WEIGHTS[idx]
|
57
57
|
end
|
58
58
|
|
59
59
|
check_digit = weighted_sum % 11
|
data/lib/ffaker.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'ffaker/version'
|
4
|
+
require 'pathname'
|
5
|
+
|
3
6
|
module FFaker
|
4
7
|
require_relative 'ffaker/utils/array_utils'
|
5
8
|
require_relative 'ffaker/utils/module_utils'
|
@@ -13,209 +16,78 @@ module FFaker
|
|
13
16
|
HEX = %w[0 1 2 3 4 5 6 7 8 9 A B C D E F].freeze
|
14
17
|
|
15
18
|
def self.hexify(*masks)
|
16
|
-
fetch_sample(masks.flatten).gsub(
|
19
|
+
fetch_sample(masks.flatten).gsub('#') { fetch_sample(HEX) }
|
17
20
|
end
|
18
21
|
|
19
22
|
def self.numerify(*masks)
|
20
|
-
fetch_sample(masks.flatten).gsub(
|
23
|
+
fetch_sample(masks.flatten).gsub('#') { rand(0..9).to_s }
|
21
24
|
end
|
22
25
|
|
23
26
|
def self.letterify(*masks)
|
24
|
-
fetch_sample(masks.flatten).gsub(
|
27
|
+
fetch_sample(masks.flatten).gsub('?') { fetch_sample(LETTERS) }
|
25
28
|
end
|
26
29
|
|
27
30
|
def self.bothify(masks)
|
28
31
|
letterify(numerify(masks))
|
29
32
|
end
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
autoload :Filesystem, 'ffaker/filesystem'
|
89
|
-
autoload :Food, 'ffaker/food'
|
90
|
-
autoload :FoodPL, 'ffaker/food_pl'
|
91
|
-
autoload :FreedomIpsum, 'ffaker/freedom_ipsum'
|
92
|
-
autoload :Game, 'ffaker/game'
|
93
|
-
autoload :Gender, 'ffaker/gender'
|
94
|
-
autoload :GenderBR, 'ffaker/gender_br'
|
95
|
-
autoload :GenderCN, 'ffaker/gender_cn'
|
96
|
-
autoload :GenderID, 'ffaker/gender_id'
|
97
|
-
autoload :GenderIT, 'ffaker/gender_it'
|
98
|
-
autoload :GenderJA, 'ffaker/gender_ja'
|
99
|
-
autoload :GenderJP, 'ffaker/gender_jp'
|
100
|
-
autoload :GenderKR, 'ffaker/gender_kr'
|
101
|
-
autoload :GenderPL, 'ffaker/gender_pl'
|
102
|
-
autoload :GenderRU, 'ffaker/gender_ru'
|
103
|
-
autoload :Geolocation, 'ffaker/geolocation'
|
104
|
-
autoload :Guid, 'ffaker/guid'
|
105
|
-
autoload :HealthcareIpsum, 'ffaker/healthcare_ipsum'
|
106
|
-
autoload :HealthcareRU, 'ffaker/healthcare_ru'
|
107
|
-
autoload :HipsterIpsum, 'ffaker/hipster_ipsum'
|
108
|
-
autoload :HTMLIpsum, 'ffaker/html_ipsum'
|
109
|
-
autoload :Identification, 'ffaker/identification'
|
110
|
-
autoload :IdentificationBR, 'ffaker/identification_br'
|
111
|
-
autoload :IdentificationES, 'ffaker/identification_es'
|
112
|
-
autoload :IdentificationESCL, 'ffaker/identification_es_cl'
|
113
|
-
autoload :IdentificationESCO, 'ffaker/identification_es_co'
|
114
|
-
autoload :IdentificationIN, 'ffaker/identification_in'
|
115
|
-
autoload :IdentificationIT, 'ffaker/identification_it'
|
116
|
-
autoload :IdentificationKr, 'ffaker/identification_kr'
|
117
|
-
autoload :IdentificationMX, 'ffaker/identification_mx'
|
118
|
-
autoload :IdentificationPL, 'ffaker/identification_pl'
|
119
|
-
autoload :IdentificationTW, 'ffaker/identification_tw'
|
120
|
-
autoload :Image, 'ffaker/image'
|
121
|
-
autoload :Internet, 'ffaker/internet'
|
122
|
-
autoload :InternetSE, 'ffaker/internet_se'
|
123
|
-
autoload :Job, 'ffaker/job'
|
124
|
-
autoload :JobBR, 'ffaker/job_br'
|
125
|
-
autoload :JobCN, 'ffaker/job_cn'
|
126
|
-
autoload :JobFR, 'ffaker/job_fr'
|
127
|
-
autoload :JobIT, 'ffaker/job_it'
|
128
|
-
autoload :JobJA, 'ffaker/job_ja'
|
129
|
-
autoload :JobKR, 'ffaker/job_kr'
|
130
|
-
autoload :JobVN, 'ffaker/job_vn'
|
131
|
-
autoload :Locale, 'ffaker/locale'
|
132
|
-
autoload :Lorem, 'ffaker/lorem'
|
133
|
-
autoload :LoremAR, 'ffaker/lorem_ar'
|
134
|
-
autoload :LoremBR, 'ffaker/lorem_br'
|
135
|
-
autoload :LoremCN, 'ffaker/lorem_cn'
|
136
|
-
autoload :LoremFR, 'ffaker/lorem_fr'
|
137
|
-
autoload :LoremIE, 'ffaker/lorem_ie'
|
138
|
-
autoload :LoremIT, 'ffaker/lorem_it'
|
139
|
-
autoload :LoremJA, 'ffaker/lorem_ja'
|
140
|
-
autoload :LoremKR, 'ffaker/lorem_kr'
|
141
|
-
autoload :LoremPL, 'ffaker/lorem_pl'
|
142
|
-
autoload :LoremRU, 'ffaker/lorem_ru'
|
143
|
-
autoload :LoremUA, 'ffaker/lorem_ua'
|
144
|
-
autoload :Movie, 'ffaker/movie'
|
145
|
-
autoload :Music, 'ffaker/music'
|
146
|
-
autoload :Name, 'ffaker/name'
|
147
|
-
autoload :NameAR, 'ffaker/name_ar'
|
148
|
-
autoload :NameBR, 'ffaker/name_br'
|
149
|
-
autoload :NameCN, 'ffaker/name_cn'
|
150
|
-
autoload :NameCS, 'ffaker/name_cs'
|
151
|
-
autoload :NameDA, 'ffaker/name_da'
|
152
|
-
autoload :NameDE, 'ffaker/name_de'
|
153
|
-
autoload :NameES, 'ffaker/name_es'
|
154
|
-
autoload :NameFR, 'ffaker/name_fr'
|
155
|
-
autoload :NameGA, 'ffaker/name_ga'
|
156
|
-
autoload :NameGR, 'ffaker/name_gr'
|
157
|
-
autoload :NameID, 'ffaker/name_id'
|
158
|
-
autoload :NameIN, 'ffaker/name_in'
|
159
|
-
autoload :NameIT, 'ffaker/name_it'
|
160
|
-
autoload :NameJA, 'ffaker/name_ja'
|
161
|
-
autoload :NameKH, 'ffaker/name_kh'
|
162
|
-
autoload :NameKR, 'ffaker/name_kr'
|
163
|
-
autoload :NameMX, 'ffaker/name_mx'
|
164
|
-
autoload :NameNB, 'ffaker/name_nb'
|
165
|
-
autoload :NameNL, 'ffaker/name_nl'
|
166
|
-
autoload :NamePH, 'ffaker/name_ph'
|
167
|
-
autoload :NamePL, 'ffaker/name_pl'
|
168
|
-
autoload :NameRU, 'ffaker/name_ru'
|
169
|
-
autoload :NameSE, 'ffaker/name_se'
|
170
|
-
autoload :NameSN, 'ffaker/name_sn'
|
171
|
-
autoload :NameTH, 'ffaker/name_th'
|
172
|
-
autoload :NameTW, 'ffaker/name_tw'
|
173
|
-
autoload :NameTHEN, 'ffaker/name_th_en'
|
174
|
-
autoload :NameUA, 'ffaker/name_ua'
|
175
|
-
autoload :NameVN, 'ffaker/name_vn'
|
176
|
-
autoload :NatoAlphabet, 'ffaker/nato_alphabet'
|
177
|
-
autoload :Number, 'ffaker/number'
|
178
|
-
autoload :PhoneNumber, 'ffaker/phone_number'
|
179
|
-
autoload :PhoneNumberAU, 'ffaker/phone_number_au'
|
180
|
-
autoload :PhoneNumberBR, 'ffaker/phone_number_br'
|
181
|
-
autoload :PhoneNumberCH, 'ffaker/phone_number_ch'
|
182
|
-
autoload :PhoneNumberCU, 'ffaker/phone_number_cu'
|
183
|
-
autoload :PhoneNumberDA, 'ffaker/phone_number_da'
|
184
|
-
autoload :PhoneNumberDE, 'ffaker/phone_number_de'
|
185
|
-
autoload :PhoneNumberFR, 'ffaker/phone_number_fr'
|
186
|
-
autoload :PhoneNumberID, 'ffaker/phone_number_id'
|
187
|
-
autoload :PhoneNumberIT, 'ffaker/phone_number_it'
|
188
|
-
autoload :PhoneNumberJA, 'ffaker/phone_number_ja'
|
189
|
-
autoload :PhoneNumberKR, 'ffaker/phone_number_kr'
|
190
|
-
autoload :PhoneNumberMX, 'ffaker/phone_number_mx'
|
191
|
-
autoload :PhoneNumberNL, 'ffaker/phone_number_nl'
|
192
|
-
autoload :PhoneNumberPL, 'ffaker/phone_number_pl'
|
193
|
-
autoload :PhoneNumberSE, 'ffaker/phone_number_se'
|
194
|
-
autoload :PhoneNumberSG, 'ffaker/phone_number_sg'
|
195
|
-
autoload :PhoneNumberSN, 'ffaker/phone_number_sn'
|
196
|
-
autoload :PhoneNumberTW, 'ffaker/phone_number_tw'
|
197
|
-
autoload :PhoneNumberUA, 'ffaker/phone_number_ua'
|
198
|
-
autoload :PhoneNumberRU, 'ffaker/phone_number_ru'
|
199
|
-
autoload :Product, 'ffaker/product'
|
200
|
-
autoload :SemVer, 'ffaker/sem_ver'
|
201
|
-
autoload :Skill, 'ffaker/skill'
|
202
|
-
autoload :Sport, 'ffaker/sport'
|
203
|
-
autoload :SportPL, 'ffaker/sport_pl'
|
204
|
-
autoload :SportUS, 'ffaker/sport_us'
|
205
|
-
autoload :SportRU, 'ffaker/sport_ru'
|
206
|
-
autoload :SSN, 'ffaker/ssn'
|
207
|
-
autoload :SSNMX, 'ffaker/ssn_mx'
|
208
|
-
autoload :SSNSE, 'ffaker/ssn_se'
|
209
|
-
autoload :String, 'ffaker/string'
|
210
|
-
autoload :Time, 'ffaker/time'
|
211
|
-
autoload :Tweet, 'ffaker/tweet'
|
212
|
-
autoload :Unit, 'ffaker/unit'
|
213
|
-
autoload :UnitEnglish, 'ffaker/unit_english'
|
214
|
-
autoload :UnitMetric, 'ffaker/unit_metric'
|
215
|
-
autoload :VERSION, 'version'
|
216
|
-
autoload :Vehicle, 'ffaker/vehicle'
|
217
|
-
autoload :Venue, 'ffaker/venue'
|
218
|
-
autoload :Youtube, 'ffaker/youtube'
|
34
|
+
autoload_acronyms = {
|
35
|
+
'ar' => 'AR',
|
36
|
+
'au' => 'AU',
|
37
|
+
'aws' => 'AWS',
|
38
|
+
'br' => 'BR',
|
39
|
+
'ca' => 'CA',
|
40
|
+
'ch' => 'CH',
|
41
|
+
'cl' => 'CL',
|
42
|
+
'cn' => 'CN',
|
43
|
+
'co' => 'CO',
|
44
|
+
'cs' => 'CS',
|
45
|
+
'cu' => 'CU',
|
46
|
+
'da' => 'DA',
|
47
|
+
'de' => 'DE',
|
48
|
+
'ec' => 'EC',
|
49
|
+
'en' => 'EN',
|
50
|
+
'es' => 'ES',
|
51
|
+
'fi' => 'FI',
|
52
|
+
'fr' => 'FR',
|
53
|
+
'ga' => 'GA',
|
54
|
+
'gr' => 'GR',
|
55
|
+
'html' => 'HTML',
|
56
|
+
'id' => 'ID',
|
57
|
+
'ie' => 'IE',
|
58
|
+
'in' => 'IN',
|
59
|
+
'it' => 'IT',
|
60
|
+
'ja' => 'JA',
|
61
|
+
'jp' => 'JP',
|
62
|
+
'kh' => 'KH',
|
63
|
+
'kr' => 'KR',
|
64
|
+
'mx' => 'MX',
|
65
|
+
'nb' => 'NB',
|
66
|
+
'nl' => 'NL',
|
67
|
+
'ph' => 'PH',
|
68
|
+
'pl' => 'PL',
|
69
|
+
'ru' => 'RU',
|
70
|
+
'se' => 'SE',
|
71
|
+
'sg' => 'SG',
|
72
|
+
'sn' => 'SN',
|
73
|
+
'ssn' => 'SSN',
|
74
|
+
'th' => 'TH',
|
75
|
+
'tw' => 'TW',
|
76
|
+
'ua' => 'UA',
|
77
|
+
'uk' => 'UK',
|
78
|
+
'us' => 'US',
|
79
|
+
'vn' => 'VN'
|
80
|
+
}
|
81
|
+
|
82
|
+
directory = "#{__dir__}/ffaker"
|
83
|
+
Dir["#{directory}/*.rb"].each do |file_name|
|
84
|
+
relative_file_path = Pathname.new(file_name).relative_path_from(directory).to_s.chomp('.rb')
|
85
|
+
## Don't consider files in sub-directories
|
86
|
+
constant_name = relative_file_path.split('_').map do |part|
|
87
|
+
autoload_acronyms.fetch(part) { part.capitalize }
|
88
|
+
end.join
|
89
|
+
autoload constant_name, file_name
|
90
|
+
end
|
219
91
|
|
220
92
|
# Random Number Generator (RNG) used with ModuleUtils#fetch, #shuffle, #rand
|
221
93
|
# in order to provide deterministic repeatability.
|
data/scripts/reference.rb
CHANGED
@@ -11,8 +11,8 @@ ICONS = {
|
|
11
11
|
warning: '❗'
|
12
12
|
}.freeze
|
13
13
|
|
14
|
-
UTILS_MODULES = %i[ArrayUtils ModuleUtils RandomUtils Random]
|
15
|
-
UTILS_METHODS = %i[k underscore fetch_sample rand shuffle unique luhn_check]
|
14
|
+
UTILS_MODULES = %i[ArrayUtils ModuleUtils RandomUtils Random Version].freeze
|
15
|
+
UTILS_METHODS = %i[k underscore fetch_sample rand shuffle unique luhn_check].freeze
|
16
16
|
|
17
17
|
# Get a list of sections
|
18
18
|
def faker_modules
|
@@ -36,12 +36,14 @@ end
|
|
36
36
|
# Catch deprecation warnings.
|
37
37
|
# This `#warn` overrides Kernel#warn
|
38
38
|
def warn(msg)
|
39
|
-
|
39
|
+
return unless Kernel.instance_variable_get(:@ffaker_warnings)
|
40
|
+
|
41
|
+
Kernel.instance_variable_set(:@ffaker_warnings, Kernel.instance_variable_get(:@ffaker_warnings) << msg)
|
40
42
|
end
|
41
43
|
|
42
44
|
def catch_warnings
|
43
|
-
|
44
|
-
[yield,
|
45
|
+
Kernel.instance_variable_set(:@ffaker_warnings, [])
|
46
|
+
[yield, Kernel.instance_variable_get(:@ffaker_warnings)]
|
45
47
|
end
|
46
48
|
|
47
49
|
def escape(str)
|
@@ -70,11 +72,7 @@ sections = faker_modules.map do |mod|
|
|
70
72
|
examples, warnings = catch_warnings do
|
71
73
|
Array.new(3) { mod.unique.send meth }
|
72
74
|
end
|
73
|
-
right =
|
74
|
-
"#{ICONS[:warning]} *#{warnings.first}*"
|
75
|
-
else
|
76
|
-
(escape examples.join(', ')).to_s
|
77
|
-
end
|
75
|
+
right = warnings.any? ? "#{ICONS[:warning]} *#{warnings.first}*" : (escape examples.join(', ')).to_s
|
78
76
|
rescue StandardError => e
|
79
77
|
right = "#{ICONS[:error]} #{e.class}: #{e.message}"
|
80
78
|
end
|
data/test/helper.rb
CHANGED
@@ -13,16 +13,14 @@ module DeterministicHelper
|
|
13
13
|
# Accepts a block. Executes the block multiple times after resetting
|
14
14
|
# the internal Random Number Generator state and compared the results of
|
15
15
|
# each execution to make sure they are the same.
|
16
|
-
def assert_deterministic(options = {})
|
17
|
-
raise ArgumentError, 'Must pass a block' unless
|
16
|
+
def assert_deterministic(options = {}, &block)
|
17
|
+
raise ArgumentError, 'Must pass a block' unless block
|
18
18
|
|
19
19
|
options = { message: 'Results are not repeatable' }.merge(options)
|
20
20
|
|
21
21
|
returns = Array.new(2) do
|
22
22
|
FFaker::Random.reset!
|
23
|
-
Array.new(5)
|
24
|
-
yield
|
25
|
-
end
|
23
|
+
Array.new(5, &block)
|
26
24
|
end
|
27
25
|
|
28
26
|
assert(returns.uniq.length == 1, options[:message])
|
data/test/test_address_da.rb
CHANGED
@@ -20,11 +20,11 @@ class TestAddressDA < Test::Unit::TestCase
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_state
|
23
|
-
assert_match(/\A[-ÆØÅæøåa-z
|
23
|
+
assert_match(/\A[-ÆØÅæøåa-z]+\z/i, FFaker::AddressDA.state)
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_kommune
|
27
|
-
assert_match(/\A[-ÆØÅæøåa-z
|
27
|
+
assert_match(/\A[-ÆØÅæøåa-z]+\z/i, FFaker::AddressDA.kommune)
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_region
|
@@ -32,7 +32,7 @@ class TestAddressDA < Test::Unit::TestCase
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_city
|
35
|
-
assert_match(/\A[- ÆØÅæøåla-z
|
35
|
+
assert_match(/\A[- ÆØÅæøåla-z]+\z/i, FFaker::AddressDA.city)
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_street_name
|
data/test/test_address_fi.rb
CHANGED
@@ -5,8 +5,8 @@ require_relative 'helper'
|
|
5
5
|
class TestAddressFI < Test::Unit::TestCase
|
6
6
|
include DeterministicHelper
|
7
7
|
|
8
|
-
ALPHA = /\A\p{Alpha}
|
9
|
-
DIGIT = /\d{1}
|
8
|
+
ALPHA = /\A\p{Alpha}+/
|
9
|
+
DIGIT = /\d{1}/
|
10
10
|
|
11
11
|
assert_methods_are_deterministic(
|
12
12
|
FFaker::AddressFI,
|
data/test/test_address_se.rb
CHANGED
@@ -5,8 +5,8 @@ require_relative 'helper'
|
|
5
5
|
class TestAddressSE < Test::Unit::TestCase
|
6
6
|
include DeterministicHelper
|
7
7
|
|
8
|
-
ALPHA = /\A\p{Alpha}
|
9
|
-
DIGIT = /\d{1}
|
8
|
+
ALPHA = /\A\p{Alpha}+/
|
9
|
+
DIGIT = /\d{1}/
|
10
10
|
|
11
11
|
assert_methods_are_deterministic(
|
12
12
|
FFaker::AddressSE,
|
data/test/test_avatar.rb
CHANGED
@@ -18,40 +18,63 @@ class TestAvatar < Test::Unit::TestCase
|
|
18
18
|
@tester.image)
|
19
19
|
end
|
20
20
|
|
21
|
+
def test_image_output_with_keyword_arguments
|
22
|
+
output = capture_output do
|
23
|
+
@tester.image(format: 'jpg')
|
24
|
+
end
|
25
|
+
|
26
|
+
assert_equal ['', ''], output
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_image_with_slug_as_positional_argument
|
30
|
+
assert_equal("#{ROBOHASH}/foobar.png?size=300x300", @tester.image('foobar'))
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_image_output_with_positional_arguments
|
34
|
+
output = capture_output do
|
35
|
+
@tester.image('foobar')
|
36
|
+
end
|
37
|
+
|
38
|
+
assert_equal(
|
39
|
+
['', "Positional arguments for Avatar#image are deprecated. Please use keyword arguments.\n"],
|
40
|
+
output
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
21
44
|
def test_avatar_with_param
|
22
|
-
assert_equal("#{ROBOHASH}/faker.png?size=300x300", @tester.image('faker'))
|
45
|
+
assert_equal("#{ROBOHASH}/faker.png?size=300x300", @tester.image(slug: 'faker'))
|
23
46
|
end
|
24
47
|
|
25
48
|
def test_avatar_with_correct_size
|
26
49
|
assert_equal("#{ROBOHASH}/faker.png?size=150x320",
|
27
|
-
@tester.image('faker', '150x320'))
|
50
|
+
@tester.image(slug: 'faker', size: '150x320'))
|
28
51
|
end
|
29
52
|
|
30
53
|
def test_avatar_with_incorrect_size
|
31
54
|
assert_raise ArgumentError do
|
32
|
-
@tester.image(
|
55
|
+
@tester.image(size: '150x320z')
|
33
56
|
end
|
34
57
|
end
|
35
58
|
|
36
59
|
def test_avatar_with_supported_format
|
37
60
|
assert_equal("#{ROBOHASH}/faker.jpg?size=300x300",
|
38
|
-
@tester.image('faker', '300x300', 'jpg'))
|
61
|
+
@tester.image(slug: 'faker', size: '300x300', format: 'jpg'))
|
39
62
|
end
|
40
63
|
|
41
64
|
def test_avatar_with_incorrect_format
|
42
65
|
assert_raise ArgumentError do
|
43
|
-
@tester.image(
|
66
|
+
@tester.image(size: '300x300', format: 'wrong_format')
|
44
67
|
end
|
45
68
|
end
|
46
69
|
|
47
70
|
def test_avatar_with_correct_background
|
48
71
|
assert_equal("#{ROBOHASH}/faker.png?size=300x300&bgset=bg1",
|
49
|
-
@tester.image('faker', '300x300', 'png', '1'))
|
72
|
+
@tester.image(slug: 'faker', size: '300x300', format: 'png', bgset: '1'))
|
50
73
|
end
|
51
74
|
|
52
75
|
def test_avatar_with_incorrect_background
|
53
76
|
assert_raise ArgumentError do
|
54
|
-
@tester.image('faker', '300x300', 'png', 'not_a_number')
|
77
|
+
@tester.image(slug: 'faker', size: '300x300', format: 'png', bgset: 'not_a_number')
|
55
78
|
end
|
56
79
|
end
|
57
80
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helper'
|
4
|
+
|
5
|
+
class TestBankUS < Test::Unit::TestCase
|
6
|
+
include DeterministicHelper
|
7
|
+
|
8
|
+
assert_methods_are_deterministic(
|
9
|
+
FFaker::BankUS,
|
10
|
+
:account_number, :routing_number
|
11
|
+
)
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@tester = FFaker::BankUS
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_account_number
|
18
|
+
assert_instance_of String, @tester.account_number
|
19
|
+
assert_match(/\A\d{8}\z/, @tester.account_number(min_digits: 8, max_digits: 8))
|
20
|
+
assert_match(/\A\d{12}\z/, @tester.account_number(min_digits: 12, max_digits: 12))
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_routing_number
|
24
|
+
routing_number = @tester.routing_number
|
25
|
+
assert_match(/\A\d{9}\z/, routing_number)
|
26
|
+
|
27
|
+
checksum = (
|
28
|
+
(7 * (routing_number[0].to_i + routing_number[3].to_i + routing_number[6].to_i)) +
|
29
|
+
(3 * (routing_number[1].to_i + routing_number[4].to_i + routing_number[7].to_i)) +
|
30
|
+
(9 * (routing_number[2].to_i + routing_number[5].to_i + routing_number[8].to_i))
|
31
|
+
)
|
32
|
+
|
33
|
+
assert_equal(0, checksum % 10, 'The routing number\'s checksum is not a multiple of ten')
|
34
|
+
end
|
35
|
+
end
|