ffaker 2.22.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 +120 -17
- data/Gemfile +15 -0
- data/README.md +3 -2
- data/REFERENCE.md +885 -868
- data/Rakefile +7 -7
- data/ffaker.gemspec +2 -6
- 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/avatar.rb +11 -3
- data/lib/ffaker/bank.rb +1 -1
- data/lib/ffaker/bank_us.rb +33 -0
- data/lib/ffaker/book.rb +10 -2
- data/lib/ffaker/cheesy_lingo.rb +2 -2
- data/lib/ffaker/code.rb +1 -1
- data/lib/ffaker/company.rb +1 -1
- data/lib/ffaker/company_fr.rb +1 -1
- data/lib/ffaker/crypto.rb +14 -0
- data/lib/ffaker/date.rb +9 -0
- data/lib/ffaker/filesystem.rb +12 -2
- data/lib/ffaker/identification_br.rb +2 -11
- data/lib/ffaker/identification_ec.rb +1 -1
- data/lib/ffaker/identification_es_cl.rb +1 -1
- data/lib/ffaker/identification_kr.rb +10 -3
- data/lib/ffaker/identification_pl.rb +2 -2
- data/lib/ffaker/image.rb +28 -4
- 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/number.rb +4 -0
- 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/string.rb +1 -1
- data/lib/ffaker/utils/module_utils.rb +2 -2
- data/lib/ffaker/utils/unique_utils.rb +9 -5
- data/lib/ffaker/version.rb +1 -1
- data/lib/ffaker.rb +60 -191
- data/scripts/reference.rb +8 -10
- data/test/helper.rb +1 -1
- 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_crypto.rb +15 -0
- data/test/test_date.rb +11 -1
- data/test/test_filesystem.rb +28 -2
- data/test/test_healthcare_ru.rb +1 -1
- data/test/test_identification.rb +12 -2
- data/test/test_identification_ec.rb +1 -1
- 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 +3 -1
- data/test/test_lorem_br.rb +1 -1
- data/test/test_lorem_ru.rb +1 -1
- data/test/test_lorem_ua.rb +1 -1
- data/test/test_name_ua.rb +1 -1
- data/test/test_number.rb +13 -1
- data/test/test_phone_number_nl.rb +1 -1
- data/test/test_unique_utils.rb +4 -0
- data/test/test_units.rb +6 -6
- data/test/test_units_english.rb +15 -15
- data/test/test_units_metric.rb +15 -15
- metadata +7 -45
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'
|
@@ -28,197 +31,63 @@ module FFaker
|
|
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 :EducationCN, 'ffaker/education_cn'
|
89
|
-
autoload :Filesystem, 'ffaker/filesystem'
|
90
|
-
autoload :Food, 'ffaker/food'
|
91
|
-
autoload :FoodPL, 'ffaker/food_pl'
|
92
|
-
autoload :FreedomIpsum, 'ffaker/freedom_ipsum'
|
93
|
-
autoload :Game, 'ffaker/game'
|
94
|
-
autoload :Gender, 'ffaker/gender'
|
95
|
-
autoload :GenderBR, 'ffaker/gender_br'
|
96
|
-
autoload :GenderCN, 'ffaker/gender_cn'
|
97
|
-
autoload :GenderID, 'ffaker/gender_id'
|
98
|
-
autoload :GenderIT, 'ffaker/gender_it'
|
99
|
-
autoload :GenderJA, 'ffaker/gender_ja'
|
100
|
-
autoload :GenderJP, 'ffaker/gender_jp'
|
101
|
-
autoload :GenderKR, 'ffaker/gender_kr'
|
102
|
-
autoload :GenderPL, 'ffaker/gender_pl'
|
103
|
-
autoload :GenderRU, 'ffaker/gender_ru'
|
104
|
-
autoload :Geolocation, 'ffaker/geolocation'
|
105
|
-
autoload :Guid, 'ffaker/guid'
|
106
|
-
autoload :HealthcareIpsum, 'ffaker/healthcare_ipsum'
|
107
|
-
autoload :HealthcareRU, 'ffaker/healthcare_ru'
|
108
|
-
autoload :HipsterIpsum, 'ffaker/hipster_ipsum'
|
109
|
-
autoload :HTMLIpsum, 'ffaker/html_ipsum'
|
110
|
-
autoload :Identification, 'ffaker/identification'
|
111
|
-
autoload :IdentificationBR, 'ffaker/identification_br'
|
112
|
-
autoload :IdentificationES, 'ffaker/identification_es'
|
113
|
-
autoload :IdentificationESCL, 'ffaker/identification_es_cl'
|
114
|
-
autoload :IdentificationESCO, 'ffaker/identification_es_co'
|
115
|
-
autoload :IdentificationIN, 'ffaker/identification_in'
|
116
|
-
autoload :IdentificationIT, 'ffaker/identification_it'
|
117
|
-
autoload :IdentificationKr, 'ffaker/identification_kr'
|
118
|
-
autoload :IdentificationMX, 'ffaker/identification_mx'
|
119
|
-
autoload :IdentificationPL, 'ffaker/identification_pl'
|
120
|
-
autoload :IdentificationTW, 'ffaker/identification_tw'
|
121
|
-
autoload :IdentificationEC, 'ffaker/identification_ec'
|
122
|
-
autoload :Image, 'ffaker/image'
|
123
|
-
autoload :Internet, 'ffaker/internet'
|
124
|
-
autoload :InternetSE, 'ffaker/internet_se'
|
125
|
-
autoload :Job, 'ffaker/job'
|
126
|
-
autoload :JobBR, 'ffaker/job_br'
|
127
|
-
autoload :JobCN, 'ffaker/job_cn'
|
128
|
-
autoload :JobFR, 'ffaker/job_fr'
|
129
|
-
autoload :JobIT, 'ffaker/job_it'
|
130
|
-
autoload :JobJA, 'ffaker/job_ja'
|
131
|
-
autoload :JobKR, 'ffaker/job_kr'
|
132
|
-
autoload :JobVN, 'ffaker/job_vn'
|
133
|
-
autoload :JoJo, 'ffaker/jo_jo'
|
134
|
-
autoload :Locale, 'ffaker/locale'
|
135
|
-
autoload :Lorem, 'ffaker/lorem'
|
136
|
-
autoload :LoremAR, 'ffaker/lorem_ar'
|
137
|
-
autoload :LoremBR, 'ffaker/lorem_br'
|
138
|
-
autoload :LoremCN, 'ffaker/lorem_cn'
|
139
|
-
autoload :LoremFR, 'ffaker/lorem_fr'
|
140
|
-
autoload :LoremIE, 'ffaker/lorem_ie'
|
141
|
-
autoload :LoremIT, 'ffaker/lorem_it'
|
142
|
-
autoload :LoremJA, 'ffaker/lorem_ja'
|
143
|
-
autoload :LoremKR, 'ffaker/lorem_kr'
|
144
|
-
autoload :LoremPL, 'ffaker/lorem_pl'
|
145
|
-
autoload :LoremRU, 'ffaker/lorem_ru'
|
146
|
-
autoload :LoremUA, 'ffaker/lorem_ua'
|
147
|
-
autoload :Movie, 'ffaker/movie'
|
148
|
-
autoload :Music, 'ffaker/music'
|
149
|
-
autoload :Name, 'ffaker/name'
|
150
|
-
autoload :NameAR, 'ffaker/name_ar'
|
151
|
-
autoload :NameBR, 'ffaker/name_br'
|
152
|
-
autoload :NameCN, 'ffaker/name_cn'
|
153
|
-
autoload :NameCS, 'ffaker/name_cs'
|
154
|
-
autoload :NameDA, 'ffaker/name_da'
|
155
|
-
autoload :NameDE, 'ffaker/name_de'
|
156
|
-
autoload :NameES, 'ffaker/name_es'
|
157
|
-
autoload :NameFR, 'ffaker/name_fr'
|
158
|
-
autoload :NameGA, 'ffaker/name_ga'
|
159
|
-
autoload :NameGR, 'ffaker/name_gr'
|
160
|
-
autoload :NameID, 'ffaker/name_id'
|
161
|
-
autoload :NameIN, 'ffaker/name_in'
|
162
|
-
autoload :NameIT, 'ffaker/name_it'
|
163
|
-
autoload :NameJA, 'ffaker/name_ja'
|
164
|
-
autoload :NameKH, 'ffaker/name_kh'
|
165
|
-
autoload :NameKR, 'ffaker/name_kr'
|
166
|
-
autoload :NameMX, 'ffaker/name_mx'
|
167
|
-
autoload :NameNB, 'ffaker/name_nb'
|
168
|
-
autoload :NameNL, 'ffaker/name_nl'
|
169
|
-
autoload :NamePH, 'ffaker/name_ph'
|
170
|
-
autoload :NamePL, 'ffaker/name_pl'
|
171
|
-
autoload :NameRU, 'ffaker/name_ru'
|
172
|
-
autoload :NameSE, 'ffaker/name_se'
|
173
|
-
autoload :NameSN, 'ffaker/name_sn'
|
174
|
-
autoload :NameTH, 'ffaker/name_th'
|
175
|
-
autoload :NameTW, 'ffaker/name_tw'
|
176
|
-
autoload :NameTHEN, 'ffaker/name_th_en'
|
177
|
-
autoload :NameUA, 'ffaker/name_ua'
|
178
|
-
autoload :NameVN, 'ffaker/name_vn'
|
179
|
-
autoload :NatoAlphabet, 'ffaker/nato_alphabet'
|
180
|
-
autoload :Number, 'ffaker/number'
|
181
|
-
autoload :PhoneNumber, 'ffaker/phone_number'
|
182
|
-
autoload :PhoneNumberAU, 'ffaker/phone_number_au'
|
183
|
-
autoload :PhoneNumberBR, 'ffaker/phone_number_br'
|
184
|
-
autoload :PhoneNumberCH, 'ffaker/phone_number_ch'
|
185
|
-
autoload :PhoneNumberCU, 'ffaker/phone_number_cu'
|
186
|
-
autoload :PhoneNumberDA, 'ffaker/phone_number_da'
|
187
|
-
autoload :PhoneNumberDE, 'ffaker/phone_number_de'
|
188
|
-
autoload :PhoneNumberFR, 'ffaker/phone_number_fr'
|
189
|
-
autoload :PhoneNumberID, 'ffaker/phone_number_id'
|
190
|
-
autoload :PhoneNumberIT, 'ffaker/phone_number_it'
|
191
|
-
autoload :PhoneNumberJA, 'ffaker/phone_number_ja'
|
192
|
-
autoload :PhoneNumberKR, 'ffaker/phone_number_kr'
|
193
|
-
autoload :PhoneNumberMX, 'ffaker/phone_number_mx'
|
194
|
-
autoload :PhoneNumberNL, 'ffaker/phone_number_nl'
|
195
|
-
autoload :PhoneNumberPL, 'ffaker/phone_number_pl'
|
196
|
-
autoload :PhoneNumberSE, 'ffaker/phone_number_se'
|
197
|
-
autoload :PhoneNumberSG, 'ffaker/phone_number_sg'
|
198
|
-
autoload :PhoneNumberSN, 'ffaker/phone_number_sn'
|
199
|
-
autoload :PhoneNumberTW, 'ffaker/phone_number_tw'
|
200
|
-
autoload :PhoneNumberUA, 'ffaker/phone_number_ua'
|
201
|
-
autoload :PhoneNumberRU, 'ffaker/phone_number_ru'
|
202
|
-
autoload :Product, 'ffaker/product'
|
203
|
-
autoload :SemVer, 'ffaker/sem_ver'
|
204
|
-
autoload :Skill, 'ffaker/skill'
|
205
|
-
autoload :Sport, 'ffaker/sport'
|
206
|
-
autoload :SportPL, 'ffaker/sport_pl'
|
207
|
-
autoload :SportUS, 'ffaker/sport_us'
|
208
|
-
autoload :SportRU, 'ffaker/sport_ru'
|
209
|
-
autoload :SSN, 'ffaker/ssn'
|
210
|
-
autoload :SSNMX, 'ffaker/ssn_mx'
|
211
|
-
autoload :SSNSE, 'ffaker/ssn_se'
|
212
|
-
autoload :String, 'ffaker/string'
|
213
|
-
autoload :Time, 'ffaker/time'
|
214
|
-
autoload :Tweet, 'ffaker/tweet'
|
215
|
-
autoload :Unit, 'ffaker/unit'
|
216
|
-
autoload :UnitEnglish, 'ffaker/unit_english'
|
217
|
-
autoload :UnitMetric, 'ffaker/unit_metric'
|
218
|
-
autoload :VERSION, 'ffaker/version'
|
219
|
-
autoload :Vehicle, 'ffaker/vehicle'
|
220
|
-
autoload :Venue, 'ffaker/venue'
|
221
|
-
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
|
222
91
|
|
223
92
|
# Random Number Generator (RNG) used with ModuleUtils#fetch, #shuffle, #rand
|
224
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
@@ -14,7 +14,7 @@ module DeterministicHelper
|
|
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
16
|
def assert_deterministic(options = {}, &block)
|
17
|
-
raise ArgumentError, 'Must pass a block' unless
|
17
|
+
raise ArgumentError, 'Must pass a block' unless block
|
18
18
|
|
19
19
|
options = { message: 'Results are not repeatable' }.merge(options)
|
20
20
|
|
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
|
data/test/test_book.rb
CHANGED
@@ -39,6 +39,35 @@ class TestBook < Test::Unit::TestCase
|
|
39
39
|
@tester.cover)
|
40
40
|
end
|
41
41
|
|
42
|
+
def test_cover_with_format
|
43
|
+
assert_match(%r{\Ahttps://robohash\.org/.+\.jpg\?size=300x300\z},
|
44
|
+
@tester.cover(format: 'jpg'))
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_cover_output_with_keyword_arguments
|
48
|
+
output = capture_output do
|
49
|
+
@tester.cover(format: 'jpg')
|
50
|
+
end
|
51
|
+
|
52
|
+
assert_equal ['', ''], output
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_cover_with_slug_as_positional_argument
|
56
|
+
assert_match(%r{\Ahttps://robohash\.org/foobar\.png\?size=300x300\z},
|
57
|
+
@tester.cover('foobar'))
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_cover_output_with_positional_arguments
|
61
|
+
output = capture_output do
|
62
|
+
@tester.cover('foobar')
|
63
|
+
end
|
64
|
+
|
65
|
+
assert_equal(
|
66
|
+
['', "Positional arguments for Book#cover are deprecated. Please use keyword arguments.\n"],
|
67
|
+
output
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
42
71
|
def test_orly_cover
|
43
72
|
assert_match(%r{\Ahttps://orly-appstore\.herokuapp\.com/generate},
|
44
73
|
@tester.orly_cover)
|
data/test/test_crypto.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helper'
|
4
|
+
|
5
|
+
class TestCrypto < Test::Unit::TestCase
|
6
|
+
include DeterministicHelper
|
7
|
+
|
8
|
+
assert_methods_are_deterministic(FFaker::Crypto, :sha256)
|
9
|
+
|
10
|
+
def test_sha256
|
11
|
+
assert FFaker::Crypto.sha256.is_a?(String)
|
12
|
+
assert FFaker::Crypto.sha256.length == 64
|
13
|
+
assert_match(/\A[a-z\d]{64}\z/, FFaker::Crypto.sha256)
|
14
|
+
end
|
15
|
+
end
|
data/test/test_date.rb
CHANGED
@@ -9,7 +9,7 @@ class TestFakerDate < Test::Unit::TestCase
|
|
9
9
|
@tester = FFaker::Date
|
10
10
|
end
|
11
11
|
|
12
|
-
assert_methods_are_deterministic(FFaker::Date, :backward, :forward)
|
12
|
+
assert_methods_are_deterministic(FFaker::Date, :backward, :forward, :birthday)
|
13
13
|
|
14
14
|
def test_between
|
15
15
|
from = Date.new(2015, 1, 1)
|
@@ -34,4 +34,14 @@ class TestFakerDate < Test::Unit::TestCase
|
|
34
34
|
assert_random_between(today + 1..today + 30) { @tester.forward(30) }
|
35
35
|
assert_instance_of Date, @tester.forward
|
36
36
|
end
|
37
|
+
|
38
|
+
def test_birthday
|
39
|
+
today = Date.today
|
40
|
+
|
41
|
+
assert_random_between(today.prev_year(65).next_day..today.prev_year(18)) { @tester.birthday }
|
42
|
+
assert_random_between(today.prev_year(43).next_day..today.prev_year(42)) do
|
43
|
+
@tester.birthday(min_age: 42, max_age: 42)
|
44
|
+
end
|
45
|
+
assert_instance_of Date, @tester.birthday
|
46
|
+
end
|
37
47
|
end
|
data/test/test_filesystem.rb
CHANGED
@@ -30,7 +30,33 @@ class TestFakerFilesystem < Test::Unit::TestCase
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_file_name
|
33
|
-
assert_match %r{\A(?:[a-z_-]+[\\/])+[a-z_-]+\.\w{2,4}\z},
|
34
|
-
|
33
|
+
assert_match %r{\A(?:[a-z_-]+[\\/])+[a-z_-]+\.\w{2,4}\z}, @tester.file_name
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_file_name_with_extension
|
37
|
+
assert_match %r{\A(?:[a-z_-]+[\\/])+[a-z_-]+\.rb\z}, @tester.file_name(ext: 'rb')
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_file_name_output_with_keyword_arguments
|
41
|
+
output = capture_output do
|
42
|
+
@tester.file_name(ext: 'rb')
|
43
|
+
end
|
44
|
+
|
45
|
+
assert_equal ['', ''], output
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_file_name_with_directory_as_positional_argument
|
49
|
+
assert_match %r{\Asome_directory/[a-z_-]+\.\w{2,4}\z}, @tester.file_name('some_directory')
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_file_name_output_with_positional_arguments
|
53
|
+
output = capture_output do
|
54
|
+
@tester.file_name('some_directory')
|
55
|
+
end
|
56
|
+
|
57
|
+
assert_equal(
|
58
|
+
['', "Positional arguments for Filesystem#file_name are deprecated. Please use keyword arguments.\n"],
|
59
|
+
output
|
60
|
+
)
|
35
61
|
end
|
36
62
|
end
|
data/test/test_healthcare_ru.rb
CHANGED
@@ -5,7 +5,7 @@ require_relative 'helper'
|
|
5
5
|
class TestHealthcareRU < Test::Unit::TestCase
|
6
6
|
include DeterministicHelper
|
7
7
|
|
8
|
-
SPECIALIZATION_REGEX = /\A[А-Яа-я\ ()
|
8
|
+
SPECIALIZATION_REGEX = /\A[А-Яа-я\ ()-]+\z/
|
9
9
|
|
10
10
|
assert_methods_are_deterministic(FFaker::HealthcareRU, :doctor_specialization)
|
11
11
|
|
data/test/test_identification.rb
CHANGED
@@ -15,7 +15,6 @@ class TestFakerIdentification < Test::Unit::TestCase
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_drivers_license
|
18
|
-
###-###-##-###-#
|
19
18
|
drivers_license_regex = /\A[A-Z]\d{3}-\d{3}-\d{2}-\d{3}-\d{1}\z/
|
20
19
|
assert_match(drivers_license_regex, @tester.drivers_license)
|
21
20
|
end
|
@@ -29,7 +28,18 @@ class TestFakerIdentification < Test::Unit::TestCase
|
|
29
28
|
end
|
30
29
|
|
31
30
|
def test_ethnicity
|
32
|
-
ethnicity_regex = %r{
|
31
|
+
ethnicity_regex = %r{
|
32
|
+
\A(
|
33
|
+
African\ American|
|
34
|
+
Asian/Pacific\ Islander|
|
35
|
+
Caucasian|
|
36
|
+
Hispanic|
|
37
|
+
Native\ American|
|
38
|
+
Multiracial|
|
39
|
+
Other|
|
40
|
+
Prefer\ not\ to\ respond
|
41
|
+
)\z
|
42
|
+
}x
|
33
43
|
assert_match(ethnicity_regex, @tester.ethnicity)
|
34
44
|
end
|
35
45
|
end
|
@@ -22,7 +22,9 @@ class TestIdentificationMX < Test::Unit::TestCase
|
|
22
22
|
|
23
23
|
def test_curp
|
24
24
|
or_curp_states_abbr = FFaker::IdentificationMX::ESTADOS_CURP.join('|')
|
25
|
-
re =
|
25
|
+
re = /
|
26
|
+
\A[a-z][aeioux][a-z]{2}\d{2}[0-1]\d[0-3]\d[hm](?:#{or_curp_states_abbr})[bcdfghjklmñpqrstvwxyz]{3}[0-9a-z]\d\z
|
27
|
+
/uix
|
26
28
|
assert_match(re, FFaker::IdentificationMX.curp)
|
27
29
|
end
|
28
30
|
end
|
@@ -28,7 +28,18 @@ class TestFakerIdentificationIT < Test::Unit::TestCase
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_ethnicity
|
31
|
-
ethnicity_regex = %r{
|
31
|
+
ethnicity_regex = %r{
|
32
|
+
\A(
|
33
|
+
Afroamericano|
|
34
|
+
Asiatico/isolano\ del\ Pacifico|
|
35
|
+
Caucasico|
|
36
|
+
Ispanico|
|
37
|
+
Nativo\ americano|
|
38
|
+
Multirazziale|
|
39
|
+
Altro|
|
40
|
+
Preferisco\ non\ rispondere
|
41
|
+
)\z
|
42
|
+
}x
|
32
43
|
assert_match(ethnicity_regex, @tester.ethnicity)
|
33
44
|
end
|
34
45
|
end
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
require_relative 'helper'
|
4
4
|
|
5
|
-
class
|
5
|
+
class TestFakerIdentificationKR < Test::Unit::TestCase
|
6
6
|
include DeterministicHelper
|
7
7
|
|
8
|
-
assert_methods_are_deterministic(FFaker::
|
8
|
+
assert_methods_are_deterministic(FFaker::IdentificationKR, :rrn)
|
9
9
|
|
10
10
|
def setup
|
11
|
-
@tester = FFaker::
|
11
|
+
@tester = FFaker::IdentificationKR
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_rrn
|