ffaker 2.21.0 → 2.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +11 -0
  3. data/README.md +15 -4
  4. data/REFERENCE.md +316 -290
  5. data/Rakefile +9 -40
  6. data/bin/console +9 -0
  7. data/ffaker.gemspec +9 -19
  8. data/lib/ffaker/address_ua.rb +1 -1
  9. data/lib/ffaker/book.rb +5 -5
  10. data/lib/ffaker/code.rb +1 -1
  11. data/lib/ffaker/company.rb +1 -1
  12. data/lib/ffaker/company_fr.rb +1 -1
  13. data/lib/ffaker/data/address_de/state +1 -0
  14. data/lib/ffaker/data/jo_jo/first_names +356 -0
  15. data/lib/ffaker/data/jo_jo/full_names +225 -0
  16. data/lib/ffaker/data/jo_jo/last_names +153 -0
  17. data/lib/ffaker/data/jo_jo/stands +149 -0
  18. data/lib/ffaker/date.rb +31 -0
  19. data/lib/ffaker/geolocation.rb +2 -2
  20. data/lib/ffaker/identification_br.rb +1 -1
  21. data/lib/ffaker/identification_ec.rb +39 -0
  22. data/lib/ffaker/identification_es_cl.rb +2 -2
  23. data/lib/ffaker/identification_es_co.rb +1 -1
  24. data/lib/ffaker/identification_kr.rb +3 -3
  25. data/lib/ffaker/identification_pl.rb +4 -4
  26. data/lib/ffaker/identification_tw.rb +1 -1
  27. data/lib/ffaker/jo_jo.rb +24 -0
  28. data/lib/ffaker/name_pl.rb +1 -1
  29. data/lib/ffaker/number.rb +2 -2
  30. data/lib/ffaker/ssn_se.rb +2 -2
  31. data/lib/ffaker/string.rb +1 -1
  32. data/lib/ffaker/time.rb +3 -3
  33. data/lib/ffaker/utils/module_utils.rb +4 -5
  34. data/lib/ffaker/utils/unique_utils.rb +29 -21
  35. data/lib/ffaker/vehicle.rb +2 -2
  36. data/lib/{version.rb → ffaker/version.rb} +1 -1
  37. data/lib/ffaker.rb +7 -4
  38. data/test/helper.rb +2 -4
  39. data/test/test_address_da.rb +3 -3
  40. data/test/test_address_fi.rb +2 -2
  41. data/test/test_address_se.rb +2 -2
  42. data/test/test_cheesy_lingo.rb +1 -1
  43. data/test/test_color.rb +3 -3
  44. data/test/test_date.rb +37 -0
  45. data/test/test_filesystem.rb +3 -3
  46. data/test/test_freedom_ipsum.rb +1 -1
  47. data/test/test_gender_it.rb +1 -1
  48. data/test/test_gender_ja.rb +1 -1
  49. data/test/test_gender_jp.rb +1 -1
  50. data/test/test_gender_pl.rb +1 -1
  51. data/test/test_healthcare_ru.rb +1 -1
  52. data/test/test_hipster_ipsum.rb +1 -1
  53. data/test/test_html_ipsum.rb +2 -2
  54. data/test/test_identification_ec.rb +33 -0
  55. data/test/test_identification_es_mx.rb +1 -1
  56. data/test/test_internet_se.rb +2 -1
  57. data/test/test_jo_jo.rb +29 -0
  58. data/test/test_lorem_br.rb +1 -1
  59. data/test/test_lorem_cn.rb +3 -3
  60. data/test/test_lorem_fr.rb +3 -3
  61. data/test/test_lorem_ie.rb +2 -2
  62. data/test/test_lorem_kr.rb +3 -3
  63. data/test/test_lorem_pl.rb +2 -2
  64. data/test/test_lorem_ru.rb +3 -3
  65. data/test/test_lorem_ua.rb +3 -3
  66. data/test/test_module_utils.rb +33 -0
  67. data/test/test_name_da.rb +1 -1
  68. data/test/test_name_ph.rb +1 -1
  69. data/test/test_name_ru.rb +2 -2
  70. data/test/test_name_ua.rb +2 -2
  71. data/test/test_phone_number_se.rb +1 -1
  72. data/test/test_phone_number_sg.rb +8 -8
  73. data/test/test_unique_utils.rb +25 -5
  74. data/test/test_vehicle.rb +22 -0
  75. metadata +19 -198
@@ -11,7 +11,7 @@ module FFaker
11
11
  GENDERS = %i[random female male].freeze
12
12
  MALE_PREFIXES = %w[Pan].freeze
13
13
  FEMALE_PREFIXES = %w[Pani].freeze
14
- ACADEMIC_DEGREE_PREFIXES = %w[lic. inż. mgr mgr\ inż. dr dr\ hab. prof.].freeze
14
+ ACADEMIC_DEGREE_PREFIXES = ['lic.', 'inż.', 'mgr', 'mgr inż.', 'dr', 'dr hab.', 'prof.'].freeze
15
15
  PREFIXES = (MALE_PREFIXES + FEMALE_PREFIXES + ACADEMIC_DEGREE_PREFIXES).freeze
16
16
 
17
17
  # Generates a random full name for a given gender (random by default).
data/lib/ffaker/number.rb CHANGED
@@ -18,9 +18,9 @@ module FFaker
18
18
  private
19
19
 
20
20
  def generate_pattern(digits)
21
- raise ArgumentError.new('Digits cannot be less than 1') if digits < 1
21
+ raise ArgumentError, 'Digits cannot be less than 1' if digits < 1
22
22
 
23
- "#{fetch_sample(1..9)}#{"#" * (digits - 1)}"
23
+ "#{fetch_sample(1..9)}#{'#' * (digits - 1)}"
24
24
  end
25
25
  end
26
26
  end
data/lib/ffaker/ssn_se.rb CHANGED
@@ -54,7 +54,7 @@ module FFaker
54
54
  end
55
55
 
56
56
  def random_birth_time_between(from = ::Time.local(1940, 1, 1), to = ::Time.now)
57
- ::Time.at(from + rand * (to.to_f - from.to_f))
57
+ ::Time.at(from + (rand * (to.to_f - from.to_f)))
58
58
  end
59
59
 
60
60
  def random_region_for(gender)
@@ -70,7 +70,7 @@ module FFaker
70
70
  end
71
71
 
72
72
  def random_region_odd
73
- rand(0..498) * 2 + 1
73
+ (rand(0..498) * 2) + 1
74
74
  end
75
75
 
76
76
  def three_character_string(number)
data/lib/ffaker/string.rb CHANGED
@@ -21,7 +21,7 @@ module FFaker
21
21
  @last_token = nil
22
22
 
23
23
  # Drop surrounding /'s and split into characters
24
- tokens = exp.inspect[1...-1].split(//)
24
+ tokens = exp.inspect[1...-1].split('')
25
25
  result << process_token(tokens) until tokens.empty?
26
26
 
27
27
  result
data/lib/ffaker/time.rb CHANGED
@@ -25,14 +25,14 @@ module FFaker
25
25
  latest_year = params[:year_latest] || 0
26
26
  year = (rand * years_back).ceil + (::DateTime.now.year - latest_year - years_back)
27
27
  month = rand(1..12)
28
- day = rand(1..Date.new(year, month, -1).day)
28
+ day = rand(1..::Date.new(year, month, -1).day)
29
29
  hours = params[:hours] || rand(0..23)
30
30
  minutes = params[:minutes] || rand(0..59)
31
31
  series = [date = ::DateTime.new(year, month, day, hours, minutes)]
32
32
  return date unless params[:series]
33
33
 
34
34
  params[:series].each do |some_time_after|
35
- series << series.last + (rand * some_time_after).ceil
35
+ series << (series.last + (rand * some_time_after).ceil)
36
36
  end
37
37
  series
38
38
  end
@@ -44,7 +44,7 @@ module FFaker
44
44
  def between(from, to)
45
45
  from_value = convert_to_time(from)
46
46
  to_value = convert_to_time(to)
47
- ::Time.at(from_value + rand * (to_value.to_f - from_value.to_f))
47
+ ::Time.at(from_value + (rand * (to_value.to_f - from_value.to_f)))
48
48
  end
49
49
 
50
50
  private
@@ -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
- @unique_generator ||= FFaker::UniqueUtils.new(self, max_retries)
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.split(//).each_with_index do |digit, i|
43
+ number.split('').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,52 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'set'
3
4
 
4
5
  module FFaker
5
6
  class UniqueUtils
6
- def initialize(generator, max_retries)
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
- def method_missing(name, *arguments)
13
- @generator.respond_to?(name) ? add_results_to_hash(name, *arguments) : super
14
- end
9
+ class << self
10
+ def add_instance(generator, max_retries)
11
+ instances[generator] ||= FFaker::UniqueUtils.new(generator, max_retries)
12
+ end
15
13
 
16
- def respond_to_missing?(method_name, include_private = false)
17
- super
18
- end
14
+ def instances
15
+ Thread.current[:ffaker_unique_utils] ||= {}
16
+ end
19
17
 
20
- RetryLimitExceeded = Class.new(StandardError)
18
+ def clear
19
+ instances.values.each(&:clear)
20
+ instances.clear
21
+ end
22
+ end
21
23
 
22
- def clear
23
- @previous_results.clear
24
+ def initialize(generator, max_retries)
25
+ @generator = generator
26
+ @max_retries = max_retries
24
27
  end
25
28
 
26
- def self.clear
27
- ObjectSpace.each_object(self, &:clear)
29
+ def clear
30
+ previous_results.clear
28
31
  end
29
32
 
30
33
  private
31
34
 
32
- def add_results_to_hash(name, *arguments)
35
+ def method_missing(name, *arguments)
33
36
  @max_retries.times do
34
- result = @generator.send(name, *arguments)
37
+ result = @generator.public_send(name, *arguments)
35
38
 
36
- next if @previous_results[[name, arguments]].include?(result)
39
+ next if previous_results[[name, arguments]].include?(result)
37
40
 
38
- @previous_results[[name, arguments]] << result
41
+ previous_results[[name, arguments]] << result
39
42
  return result
40
43
  end
41
- raise RetryLimitExceeded
44
+
45
+ raise RetryLimitExceeded, "Retry limit exceeded for #{name}"
46
+ end
47
+
48
+ def previous_results
49
+ @previous_results ||= Hash.new { |hash, key| hash[key] = Set.new }
42
50
  end
43
51
  end
44
52
  end
@@ -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.to_sym] || char).to_i * POSITION_WEIGHTS[idx]
56
+ (TRANSLITERATION_VALUES[char] || char).to_i * POSITION_WEIGHTS[idx]
57
57
  end
58
58
 
59
59
  check_digit = weighted_sum % 11
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FFaker
4
- VERSION = '2.21.0'
4
+ VERSION = '2.22.0'
5
5
  end
data/lib/ffaker.rb CHANGED
@@ -13,15 +13,15 @@ module FFaker
13
13
  HEX = %w[0 1 2 3 4 5 6 7 8 9 A B C D E F].freeze
14
14
 
15
15
  def self.hexify(*masks)
16
- fetch_sample(masks.flatten).gsub(/#/) { fetch_sample(HEX) }
16
+ fetch_sample(masks.flatten).gsub('#') { fetch_sample(HEX) }
17
17
  end
18
18
 
19
19
  def self.numerify(*masks)
20
- fetch_sample(masks.flatten).gsub(/#/) { rand(0..9).to_s }
20
+ fetch_sample(masks.flatten).gsub('#') { rand(0..9).to_s }
21
21
  end
22
22
 
23
23
  def self.letterify(*masks)
24
- fetch_sample(masks.flatten).gsub(/\?/) { fetch_sample(LETTERS) }
24
+ fetch_sample(masks.flatten).gsub('?') { fetch_sample(LETTERS) }
25
25
  end
26
26
 
27
27
  def self.bothify(masks)
@@ -82,6 +82,7 @@ module FFaker
82
82
  autoload :Conference, 'ffaker/conference'
83
83
  autoload :CoursesFR, 'ffaker/courses_fr'
84
84
  autoload :Currency, 'ffaker/currency'
85
+ autoload :Date, 'ffaker/date'
85
86
  autoload :DizzleIpsum, 'ffaker/dizzle_ipsum'
86
87
  autoload :Education, 'ffaker/education'
87
88
  autoload :EducationCN, 'ffaker/education_cn'
@@ -117,6 +118,7 @@ module FFaker
117
118
  autoload :IdentificationMX, 'ffaker/identification_mx'
118
119
  autoload :IdentificationPL, 'ffaker/identification_pl'
119
120
  autoload :IdentificationTW, 'ffaker/identification_tw'
121
+ autoload :IdentificationEC, 'ffaker/identification_ec'
120
122
  autoload :Image, 'ffaker/image'
121
123
  autoload :Internet, 'ffaker/internet'
122
124
  autoload :InternetSE, 'ffaker/internet_se'
@@ -128,6 +130,7 @@ module FFaker
128
130
  autoload :JobJA, 'ffaker/job_ja'
129
131
  autoload :JobKR, 'ffaker/job_kr'
130
132
  autoload :JobVN, 'ffaker/job_vn'
133
+ autoload :JoJo, 'ffaker/jo_jo'
131
134
  autoload :Locale, 'ffaker/locale'
132
135
  autoload :Lorem, 'ffaker/lorem'
133
136
  autoload :LoremAR, 'ffaker/lorem_ar'
@@ -212,7 +215,7 @@ module FFaker
212
215
  autoload :Unit, 'ffaker/unit'
213
216
  autoload :UnitEnglish, 'ffaker/unit_english'
214
217
  autoload :UnitMetric, 'ffaker/unit_metric'
215
- autoload :VERSION, 'version'
218
+ autoload :VERSION, 'ffaker/version'
216
219
  autoload :Vehicle, 'ffaker/vehicle'
217
220
  autoload :Venue, 'ffaker/venue'
218
221
  autoload :Youtube, 'ffaker/youtube'
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 = {})
16
+ def assert_deterministic(options = {}, &block)
17
17
  raise ArgumentError, 'Must pass a block' unless block_given?
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) do
24
- yield
25
- end
23
+ Array.new(5, &block)
26
24
  end
27
25
 
28
26
  assert(returns.uniq.length == 1, options[:message])
@@ -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-]+\z/i, FFaker::AddressDA.state)
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-]+\z/i, FFaker::AddressDA.kommune)
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-]+\z/i, FFaker::AddressDA.city)
35
+ assert_match(/\A[- ÆØÅæøåla-z]+\z/i, FFaker::AddressDA.city)
36
36
  end
37
37
 
38
38
  def test_street_name
@@ -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}+/.freeze
9
- DIGIT = /\d{1}/.freeze
8
+ ALPHA = /\A\p{Alpha}+/
9
+ DIGIT = /\d{1}/
10
10
 
11
11
  assert_methods_are_deterministic(
12
12
  FFaker::AddressFI,
@@ -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}+/.freeze
9
- DIGIT = /\d{1}/.freeze
8
+ ALPHA = /\A\p{Alpha}+/
9
+ DIGIT = /\d{1}/
10
10
 
11
11
  assert_methods_are_deterministic(
12
12
  FFaker::AddressSE,
@@ -5,7 +5,7 @@ require_relative 'helper'
5
5
  class TestCheesyLingo < Test::Unit::TestCase
6
6
  include DeterministicHelper
7
7
 
8
- TEST_REGEX = /\+1|[a-z]+/i.freeze
8
+ TEST_REGEX = /\+1|[a-z]+/i
9
9
 
10
10
  assert_methods_are_deterministic(
11
11
  FFaker::CheesyLingo,
data/test/test_color.rb CHANGED
@@ -5,9 +5,9 @@ require_relative 'helper'
5
5
  class TestColor < Test::Unit::TestCase
6
6
  include DeterministicHelper
7
7
 
8
- VALID_RGB_REGEX = /\A([0-9]{1,3})\z/.freeze
9
- VALID_OPACITY_REGEX = /^([0-9].[0-9]{1,2})$/.freeze
10
- VALID_PERCENTAGE_REGEX = /^([0-9]{1,3}%)$/.freeze
8
+ VALID_RGB_REGEX = /\A([0-9]{1,3})\z/
9
+ VALID_OPACITY_REGEX = /^([0-9].[0-9]{1,2})$/
10
+ VALID_PERCENTAGE_REGEX = /^([0-9]{1,3}%)$/
11
11
 
12
12
  assert_methods_are_deterministic(
13
13
  FFaker::Color,
data/test/test_date.rb ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helper'
4
+
5
+ class TestFakerDate < Test::Unit::TestCase
6
+ include DeterministicHelper
7
+
8
+ def setup
9
+ @tester = FFaker::Date
10
+ end
11
+
12
+ assert_methods_are_deterministic(FFaker::Date, :backward, :forward)
13
+
14
+ def test_between
15
+ from = Date.new(2015, 1, 1)
16
+ to = Date.new(2016, 12, 31)
17
+
18
+ assert_random_between(from..to) { @tester.between(from, to) }
19
+ assert_instance_of Date, @tester.between(from, to)
20
+ end
21
+
22
+ def test_backward
23
+ today = Date.today
24
+
25
+ assert_random_between(today - 365..today - 1) { @tester.backward }
26
+ assert_random_between(today - 30..today - 1) { @tester.backward(30) }
27
+ assert_instance_of Date, @tester.backward
28
+ end
29
+
30
+ def test_forward
31
+ today = Date.today
32
+
33
+ assert_random_between(today + 1..today + 365) { @tester.forward }
34
+ assert_random_between(today + 1..today + 30) { @tester.forward(30) }
35
+ assert_instance_of Date, @tester.forward
36
+ end
37
+ end
@@ -15,10 +15,10 @@ class TestFakerFilesystem < Test::Unit::TestCase
15
15
  end
16
16
 
17
17
  def test_extension
18
- assert_match /\A(?:flac|mp3|wav|bmp|gif|jpeg|jpg|png|tiff|css|csv|html|js|
18
+ assert_match(/\A(?:flac|mp3|wav|bmp|gif|jpeg|jpg|png|tiff|css|csv|html|js|
19
19
  json|txt|mp4|avi|mov|webm|doc|docx|xls|xlsx|ppt|pptx|odt|
20
20
  ods|odp|pages|numbers|key|pdf)\z/x,
21
- @tester.extension
21
+ @tester.extension)
22
22
  end
23
23
 
24
24
  def test_mime_type_format
@@ -31,6 +31,6 @@ class TestFakerFilesystem < Test::Unit::TestCase
31
31
 
32
32
  def test_file_name
33
33
  assert_match %r{\A(?:[a-z_-]+[\\/])+[a-z_-]+\.\w{2,4}\z},
34
- @tester.file_name
34
+ @tester.file_name
35
35
  end
36
36
  end
@@ -9,7 +9,7 @@ class TestFreedomIpsum < Test::Unit::TestCase
9
9
  :word, :words
10
10
  )
11
11
 
12
- TEST_REGEX = /[a-z0-9 -]+/i.freeze
12
+ TEST_REGEX = /[a-z0-9 -]+/i
13
13
 
14
14
  def test_words
15
15
  assert_match(TEST_REGEX, FFaker::FreedomIpsum.words.join(' '))
@@ -5,7 +5,7 @@ require_relative 'helper'
5
5
  class TestFakerGenderIT < Test::Unit::TestCase
6
6
  include DeterministicHelper
7
7
 
8
- GENDER_REGEX = /\A(maschio|femmina)\z/.freeze
8
+ GENDER_REGEX = /\A(maschio|femmina)\z/
9
9
 
10
10
  assert_methods_are_deterministic(FFaker::GenderIT, :random)
11
11
 
@@ -5,7 +5,7 @@ require_relative 'helper'
5
5
  class TestFakerGenderJA < Test::Unit::TestCase
6
6
  include DeterministicHelper
7
7
 
8
- GENDER_REGEX = /\A[女男]\z/.freeze
8
+ GENDER_REGEX = /\A[女男]\z/
9
9
 
10
10
  assert_methods_are_deterministic(FFaker::GenderJP, :random)
11
11
 
@@ -5,7 +5,7 @@ require_relative 'helper'
5
5
  class TestFakerGenderJP < Test::Unit::TestCase
6
6
  include DeterministicHelper
7
7
 
8
- GENDER_REGEX = /\A[女男]\z/.freeze
8
+ GENDER_REGEX = /\A[女男]\z/
9
9
 
10
10
  assert_methods_are_deterministic(FFaker::GenderJP, :random)
11
11
 
@@ -5,7 +5,7 @@ require_relative 'helper'
5
5
  class TestFakerGenderPL < Test::Unit::TestCase
6
6
  include DeterministicHelper
7
7
 
8
- GENDER_REGEX = /\A(kobieta|mężczyzna)\z/.freeze
8
+ GENDER_REGEX = /\A(kobieta|mężczyzna)\z/
9
9
 
10
10
  assert_methods_are_deterministic(FFaker::GenderPL, :random)
11
11
 
@@ -5,7 +5,7 @@ require_relative 'helper'
5
5
  class TestHealthcareRU < Test::Unit::TestCase
6
6
  include DeterministicHelper
7
7
 
8
- SPECIALIZATION_REGEX = /\A[А-Яа-я\ ()\-]+\z/.freeze
8
+ SPECIALIZATION_REGEX = /\A[А-Яа-я\ ()\-]+\z/
9
9
 
10
10
  assert_methods_are_deterministic(FFaker::HealthcareRU, :doctor_specialization)
11
11
 
@@ -10,7 +10,7 @@ class TestHipsterIpsum < Test::Unit::TestCase
10
10
  :paragraph, :paragraphs, :sentence, :sentences, :word, :words
11
11
  )
12
12
 
13
- TEST_REGEX = /\+1|[ a-z]+/i.freeze
13
+ TEST_REGEX = /\+1|[ a-z]+/i
14
14
 
15
15
  def test_paragraph
16
16
  assert_match(TEST_REGEX, FFaker::HipsterIpsum.paragraph)
@@ -92,8 +92,8 @@ class TestHTMLIpsum < Test::Unit::TestCase
92
92
 
93
93
  def test_fancy_string_tags
94
94
  # It returns a string with at least one HTML tag
95
- assert_match(%r{(<.*>[\w\s]+<\/\w+>){1}}i, FFaker::HTMLIpsum.fancy_string(1))
96
- assert_match(%r{(<.*>[\w\s]+<\/\w+>){1}}i, FFaker::HTMLIpsum.fancy_string(3))
95
+ assert_match(%r{(<.*>[\w\s]+</\w+>){1}}i, FFaker::HTMLIpsum.fancy_string(1))
96
+ assert_match(%r{(<.*>[\w\s]+</\w+>){1}}i, FFaker::HTMLIpsum.fancy_string(3))
97
97
  end
98
98
 
99
99
  def test_fancy_string_breaks
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helper'
4
+
5
+ class TestIdentificationEC < Test::Unit::TestCase
6
+ include DeterministicHelper
7
+
8
+ assert_methods_are_deterministic(FFaker::IdentificationEC, :ci)
9
+
10
+ def setup
11
+ @tester = FFaker::IdentificationEC
12
+ end
13
+
14
+ def test_ci
15
+ assert_match(/^[0-9]{10}$/, @tester.ci)
16
+ end
17
+
18
+ def test_last_digit
19
+ ci = @tester.ci
20
+ sum = 0
21
+ ci[0..8].chars.each_with_index do |char, index|
22
+ if index.even?
23
+ multiple = char.to_i * 2
24
+ sum += multiple > 9 ? multiple - 9 : multiple
25
+ else
26
+ sum += char.to_i
27
+ end
28
+ end
29
+ mod = sum % 10
30
+ mod = 10 - mod if mod > 0
31
+ assert(ci[9].to_i == mod)
32
+ end
33
+ end
@@ -22,7 +22,7 @@ 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 = /\A[a-z][aeioux][a-z]{2}\d{2}[0-1]\d[0-3]\d[hm](?:#{or_curp_states_abbr})[bcdfghjklmnñpqrstvwxyz]{3}[0-9a-z]\d\z/ui
25
+ re = /\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/ui
26
26
  assert_match(re, FFaker::IdentificationMX.curp)
27
27
  end
28
28
  end
@@ -30,7 +30,8 @@ class TestFakerInternetSE < Test::Unit::TestCase
30
30
 
31
31
  def test_free_email
32
32
  email = @tester.free_email
33
- assert email.match(/.+@(gmail\.com|hotmail\.com|yahoo\.com|spray\.se|passagen\.se)/), "mail: #{email} does not match"
33
+ assert email.match(/.+@(gmail\.com|hotmail\.com|yahoo\.com|spray\.se|passagen\.se)/),
34
+ "mail: #{email} does not match"
34
35
  end
35
36
 
36
37
  def test_login_user_name
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helper'
4
+
5
+ class TestJoJo < Test::Unit::TestCase
6
+ include DeterministicHelper
7
+
8
+ assert_methods_are_deterministic(FFaker::JoJo, :full_name, :first_name, :last_name, :stand)
9
+
10
+ def setup
11
+ @tester = FFaker::JoJo
12
+ end
13
+
14
+ def test_full_name
15
+ assert_include @tester::FULL_NAMES, @tester.full_name
16
+ end
17
+
18
+ def test_first_name
19
+ assert_include @tester::FIRST_NAMES, @tester.first_name
20
+ end
21
+
22
+ def test_last_name
23
+ assert_include @tester::LAST_NAMES, @tester.last_name
24
+ end
25
+
26
+ def test_stand
27
+ assert_include @tester::STANDS, @tester.stand
28
+ end
29
+ end
@@ -10,7 +10,7 @@ class TestLoremBR < Test::Unit::TestCase
10
10
  :paragraph, :sentence, :phrase, :paragraphs, :sentences, :phrases, :words, :word, :characters
11
11
  )
12
12
 
13
- CHARACTERS = /\A[A-zÀ-ü0-9]+\z/i
13
+ CHARACTERS = /\A[A-zÀ-ü0-9]+\z/i
14
14
  WORD = /\A[A-zÀ-ü-]+\z/i
15
15
  WORDS = /[ A-zÀ-ü-.]+/i
16
16
 
@@ -27,7 +27,7 @@ class TestLoremCN < Test::Unit::TestCase
27
27
  end
28
28
 
29
29
  def test_paragraphs_is_an_array
30
- assert FFaker::LoremCN.paragraphs.class == Array
30
+ assert FFaker::LoremCN.paragraphs.instance_of?(Array)
31
31
  end
32
32
 
33
33
  def test_sentences
@@ -35,12 +35,12 @@ class TestLoremCN < Test::Unit::TestCase
35
35
  end
36
36
 
37
37
  def test_sentences_is_an_array
38
- assert FFaker::LoremCN.sentences.class == Array
38
+ assert FFaker::LoremCN.sentences.instance_of?(Array)
39
39
  end
40
40
 
41
41
  def test_sentences_via_to_s_produces_string_terminated_with_period
42
42
  string = FFaker::LoremCN.sentences.to_s
43
- assert string.class == String
43
+ assert string.instance_of?(String)
44
44
  assert string =~ /。$/
45
45
  end
46
46
 
@@ -10,9 +10,9 @@ class TestLoremFR < Test::Unit::TestCase
10
10
  :paragraph, :paragraphs, :sentence, :sentences, :phrase, :phrases, :word, :words
11
11
  )
12
12
 
13
- REGEX = /\A[ -.ÀÂÉÈÊÎÔÚÛàâéèêîôùûa-z]+\z/i.freeze
14
- REGEX_WORD = /\A[-ÀÂÉÈÊÎÔÚÛàâéèêîôùûa-z]+\z/i.freeze
15
- REGEX_WORDS = /\A[ -ÀÂÉÈÊÎÔÚÛàâéèêîôùûa-z]+\z/i.freeze
13
+ REGEX = /\A[ -.ÀÂÉÈÊÎÔÚÛàâéèêîôùûa-z]+\z/i
14
+ REGEX_WORD = /\A[-ÀÂÉÈÊÎÔÚÛàâéèêîôùûa-z]+\z/i
15
+ REGEX_WORDS = /\A[ -ÀÂÉÈÊÎÔÚÛàâéèêîôùûa-z]+\z/i
16
16
 
17
17
  def test_paragraph
18
18
  assert_match(REGEX, FFaker::LoremFR.paragraph)
@@ -11,8 +11,8 @@ class TestLoremIE < Test::Unit::TestCase
11
11
  :phrase, :phrases, :word, :words, :question
12
12
  )
13
13
 
14
- WORDS_REGEX = /\A[\w\W]+\z/i.freeze # spaces, alphanumeric & perioids, etc.
15
- WORD_REGEX = /\A[áéíóúa-z]+\z/i.freeze
14
+ WORDS_REGEX = /\A[\w\W]+\z/i # spaces, alphanumeric & perioids, etc.
15
+ WORD_REGEX = /\A[áéíóúa-z]+\z/i
16
16
 
17
17
  def test_paragraph
18
18
  assert_match(WORDS_REGEX, FFaker::LoremIE.paragraph)