From 704699088f28620380b15077133ccf6286c181b1 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 28 Oct 2020 16:24:21 +0900 Subject: [PATCH] Rubocop 1.0 fixes (#2182) * rubocop -a --only Style/AccessorGrouping * rubocop -a --only Style/RedundantRegexpEscape * Adjust broken commend indentation with the previous commit * rubocop -A --only Style/StringConcatenation * rubocop -a --only Style/RedundantParentheses * rubocop -a --only Style/RedundantAssignment * rubocop -A --only Style/CaseLikeIf * rubocop -a --only Lint/RedundantStringCoercion * rubocop -a --only Style/ClassEqualityComparison * rubocop -a --only Layout/ElseAlignment * rubocop -a --only Layout/EndAlignment * rubocop -a --only Layout/TrailingWhitespace * rubocop -a --only Layout/EmptyLinesAroundMethodBody * rubocop -a --only Layout/SpaceAroundMethodCallOperator * rubocop -A --only Style/ExplicitBlockArgument * Remove empty test file This empty file was introduced at the initial commit for this michael_scott faker: bcb8cf0573e1ebb9aa6669a87bff60f6a2a9643b The actual tests are written in another file: test/faker/tv_shows/test_michael_scott.rb * rubocop -a --only Layout/IndentationWidth * Address rubocop Lint/MissingSuper offence * Address rubocop Lint/MixedRegexpCaptureTypes offences * Address rubocop Style/StringConcatenation offence * Address rubocop Style/OptionalBooleanParameter offence * Address rubocop Style/RedundantRegexpCharacterClass offences * `method_missing` here falls back to `raise` so never calls `super` * Faker::Music is not a Hash. It has #keys but has no #each_key --- lib/faker.rb | 21 +++++++------- lib/faker/blockchain/aeternity.rb | 8 +++--- lib/faker/books/dune.rb | 4 +-- lib/faker/books/lovecraft.rb | 6 ++-- lib/faker/default/address.rb | 8 +++--- lib/faker/default/bank.rb | 8 ++---- lib/faker/default/beer.rb | 6 ++-- lib/faker/default/chile_rut.rb | 5 ++-- lib/faker/default/code.rb | 4 +-- lib/faker/default/commerce.rb | 2 +- lib/faker/default/company.rb | 12 ++++---- lib/faker/default/food.rb | 2 +- lib/faker/default/hipster.rb | 6 ++-- lib/faker/default/id_number.rb | 4 +-- lib/faker/default/internet.rb | 7 +++-- lib/faker/default/invoice.rb | 2 +- lib/faker/default/json.rb | 8 +++--- lib/faker/default/lorem.rb | 4 +-- lib/faker/default/measurement.rb | 5 ++-- lib/faker/default/number.rb | 2 +- lib/faker/default/omniauth.rb | 2 ++ lib/faker/default/relationship.rb | 2 +- lib/faker/default/space.rb | 2 +- lib/faker/default/stripe.rb | 6 ++-- lib/faker/default/vehicle.rb | 2 +- lib/faker/movies/star_wars.rb | 4 +-- lib/helpers/unique_generator.rb | 3 ++ script/txt2html | 2 +- test/faker/default/test_avatar.rb | 12 ++++---- test/faker/default/test_faker_address.rb | 2 +- test/faker/default/test_faker_bank.rb | 2 +- test/faker/default/test_faker_cannabis.rb | 20 ++++++------- test/faker/default/test_faker_code.rb | 2 +- test/faker/default/test_faker_coffee.rb | 2 +- test/faker/default/test_faker_compass.rb | 2 +- test/faker/default/test_faker_computer.rb | 2 +- test/faker/default/test_faker_construction.rb | 12 ++++---- test/faker/default/test_faker_crypto_coin.rb | 2 +- test/faker/default/test_faker_currency.rb | 2 +- test/faker/default/test_faker_drone.rb | 6 ++-- test/faker/default/test_faker_file.rb | 6 ++-- test/faker/default/test_faker_fillmurray.rb | 4 +-- test/faker/default/test_faker_id_number.rb | 6 ++-- test/faker/default/test_faker_internet.rb | 24 ++++++++-------- test/faker/default/test_faker_lorem.rb | 2 +- test/faker/default/test_faker_measurement.rb | 6 ++-- test/faker/default/test_faker_phone_number.rb | 2 +- test/faker/default/test_faker_street.rb | 2 +- test/faker/default/test_faker_types.rb | 10 +++---- test/faker/default/test_lorem_pixel.rb | 16 +++++------ test/faker/default/test_michael_scott.rb | 0 test/faker/default/test_placeholdit.rb | 22 +++++++-------- test/faker/music/test_faker_music.rb | 2 ++ test/faker/tv_shows/test_breaking_bad.rb | 4 +-- test/faker/tv_shows/test_dr_who.rb | 28 +++++++++---------- test/faker/tv_shows/test_futurama.rb | 8 +++--- test/faker/tv_shows/test_simpsons.rb | 12 ++++---- test/test_da_dk_locale.rb | 4 +-- test/test_en_ind_locale.rb | 2 +- test/test_en_locale.rb | 2 +- test/test_fi_locale.rb | 4 +-- test/test_fr_locale.rb | 10 +++---- test/test_helper.rb | 6 ++-- test/test_locale.rb | 2 +- test/test_no_no_locale.rb | 2 +- test/test_pt_br_locale.rb | 8 +++--- test/test_pt_locale.rb | 8 +++--- test/test_sv_locale.rb | 2 +- 68 files changed, 211 insertions(+), 206 deletions(-) delete mode 100644 test/faker/default/test_michael_scott.rb diff --git a/lib/faker.rb b/lib/faker.rb index 9e81318ae0..4d881329cc 100644 --- a/lib/faker.rb +++ b/lib/faker.rb @@ -34,8 +34,7 @@ class Config @random = nil class << self - attr_writer :locale - attr_writer :random + attr_writer :locale, :random def locale Faker.load_i18n @@ -100,13 +99,13 @@ def bothify(string) def regexify(reg) reg = reg.source if reg.respond_to?(:source) # Handle either a Regexp or a String that looks like a Regexp reg - .gsub(%r{^\/?\^?}, '').gsub(%r{\$?\/?$}, '') # Ditch the anchors + .gsub(%r{^/?\^?}, '').gsub(%r{\$?/?$}, '') # Ditch the anchors .gsub(/\{(\d+)\}/, '{\1,\1}').gsub(/\?/, '{0,1}') # All {2} become {2,2} and ? become {0,1} .gsub(/(\[[^\]]+\])\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # [12]{1,2} becomes [12] or [12][12] - .gsub(/(\([^\)]+\))\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # (12|34){1,2} becomes (12|34) or (12|34)(12|34) + .gsub(/(\([^)]+\))\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # (12|34){1,2} becomes (12|34) or (12|34)(12|34) .gsub(/(\\?.)\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # A{1,2} becomes A or AA or \d{3} becomes \d\d\d - .gsub(/\((.*?)\)/) { |match| sample(match.gsub(/[\(\)]/, '').split('|')) } # (this|that) becomes 'this' or 'that' - .gsub(/\[([^\]]+)\]/) { |match| match.gsub(/(\w\-\w)/) { |range| sample(Array(Range.new(*range.split('-')))) } } # All A-Z inside of [] become C (or X, or whatever) + .gsub(/\((.*?)\)/) { |match| sample(match.gsub(/[()]/, '').split('|')) } # (this|that) becomes 'this' or 'that' + .gsub(/\[([^\]]+)\]/) { |match| match.gsub(/(\w-\w)/) { |range| sample(Array(Range.new(*range.split('-')))) } } # All A-Z inside of [] become C (or X, or whatever) .gsub(/\[([^\]]+)\]/) { |_match| sample(Regexp.last_match(1).split('')) } # All [ABC] become B (or A or C) .gsub('\d') { |_match| sample(Numbers) } .gsub('\w') { |_match| sample(Letters) } @@ -116,7 +115,7 @@ def regexify(reg) # with an array of values and selecting one of them. def fetch(key) fetched = sample(translate("faker.#{key}")) - if fetched&.match(%r{^\/}) && fetched&.match(%r{\/$}) # A regex + if fetched&.match(%r{^/}) && fetched&.match(%r{/$}) # A regex regexify(fetched) else fetched @@ -128,7 +127,7 @@ def fetch(key) def fetch_all(key) fetched = translate("faker.#{key}") fetched = fetched.last if fetched.size <= 1 - if !fetched.respond_to?(:sample) && fetched.match(%r{^\/}) && fetched.match(%r{\/$}) # A regex + if !fetched.respond_to?(:sample) && fetched.match(%r{^/}) && fetched.match(%r{/$}) # A regex regexify(fetched) else fetched @@ -140,7 +139,7 @@ def fetch_all(key) # formatted translation: e.g., "#{first_name} #{last_name}". def parse(key) fetched = fetch(key) - parts = fetched.scan(/(\(?)#\{([A-Za-z]+\.)?([^\}]+)\}([^#]+)?/).map do |prefix, kls, meth, etc| + parts = fetched.scan(/(\(?)#\{([A-Za-z]+\.)?([^}]+)\}([^#]+)?/).map do |prefix, kls, meth, etc| # If the token had a class Prefix (e.g., Name.first_name) # grab the constant, otherwise use self cls = kls ? Faker.const_get(kls.chop) : self @@ -186,14 +185,14 @@ def translate(*args, **opts) end # Executes block with given locale set. - def with_locale(tmp_locale = nil) + def with_locale(tmp_locale = nil, &block) Faker.load_i18n current_locale = Faker::Config.own_locale Faker::Config.locale = tmp_locale disable_enforce_available_locales do - I18n.with_locale(tmp_locale) { yield } + I18n.with_locale(tmp_locale, &block) end ensure Faker::Config.locale = current_locale diff --git a/lib/faker/blockchain/aeternity.rb b/lib/faker/blockchain/aeternity.rb index ec7f9359aa..4ee4556a32 100644 --- a/lib/faker/blockchain/aeternity.rb +++ b/lib/faker/blockchain/aeternity.rb @@ -14,7 +14,7 @@ class << self # #=> "ak_zvU8YQLagjcfng7Tg8yCdiZ1rpiWNp1PBn3vtUs44utSvbJVR" # def address - 'ak_' + rand_strings + "ak_#{rand_strings}" end ## @@ -27,7 +27,7 @@ def address # #=> "th_147nDP22h3pHrLt2qykTH4txUwQh1ccaXp" # def transaction - 'th_' + rand_strings(51) + "th_#{rand_strings(51)}" end ## @@ -40,7 +40,7 @@ def transaction # #=> "ct_Hk2JsNeWGEYQEHHQCfcBeGrwbhtYSwFTPdDhW2SvjFYVojyhW" # def contract - 'ct_' + rand_strings + "ct_#{rand_strings}" end ## @@ -53,7 +53,7 @@ def contract # #=> "ok_28QDg7fkF5qiKueSdUvUBtCYPJdmMEoS73CztzXCRAwMGKHKZh" # def oracle - 'ok_' + rand_strings(51) + "ok_#{rand_strings(51)}" end protected diff --git a/lib/faker/books/dune.rb b/lib/faker/books/dune.rb index bb596b204a..4365919769 100644 --- a/lib/faker/books/dune.rb +++ b/lib/faker/books/dune.rb @@ -89,7 +89,7 @@ def quote(legacy_character = NOT_GIVEN, character: nil) end end - fetch('dune.quotes.' + character) + fetch("dune.quotes.#{character}") end ## @@ -124,7 +124,7 @@ def saying(legacy_source = NOT_GIVEN, source: nil) end end - fetch('dune.sayings.' + source) + fetch("dune.sayings.#{source}") end end end diff --git a/lib/faker/books/lovecraft.rb b/lib/faker/books/lovecraft.rb index 35d9e24e81..bca5027b91 100644 --- a/lib/faker/books/lovecraft.rb +++ b/lib/faker/books/lovecraft.rb @@ -92,7 +92,7 @@ def sentence(legacy_word_count = NOT_GIVEN, legacy_random_words_to_add = NOT_GIV keywords << :random_words_to_add if legacy_random_words_to_add != NOT_GIVEN end - words(number: word_count + rand(random_words_to_add.to_i).to_i, spaces_allowed: open_compounds_allowed).join(' ').capitalize + '.' + "#{words(number: word_count + rand(random_words_to_add.to_i).to_i, spaces_allowed: open_compounds_allowed).join(' ').capitalize}." end ## @@ -270,9 +270,9 @@ def paragraph_by_chars(legacy_characters = NOT_GIVEN, characters: 256) paragraph = paragraph(sentence_count: 3) - paragraph += ' ' + paragraph(sentence_count: 3) while paragraph.length < characters + paragraph += " #{paragraph(sentence_count: 3)}" while paragraph.length < characters - paragraph[0...characters - 1] + '.' + "#{paragraph[0...characters - 1]}." end end end diff --git a/lib/faker/default/address.rb b/lib/faker/default/address.rb index fd6d6a3eab..81e679060d 100644 --- a/lib/faker/default/address.rb +++ b/lib/faker/default/address.rb @@ -54,7 +54,7 @@ def street_address(legacy_include_secondary = NOT_GIVEN, include_secondary: fals keywords << :include_secondary if legacy_include_secondary != NOT_GIVEN end - numerify(parse('address.street_address') + (include_secondary ? ' ' + secondary_address : '')) + numerify(parse('address.street_address') + (include_secondary ? " #{secondary_address}" : '')) end ## @@ -133,7 +133,7 @@ def zip_code(legacy_state_abbreviation = NOT_GIVEN, state_abbreviation: '') # provide a zip code that is valid for the state provided # see http://www.fincen.gov/forms/files/us_state_territory_zip_codes.pdf - bothify(fetch('address.postcode_by_state.' + state_abbreviation)) + bothify(fetch("address.postcode_by_state.#{state_abbreviation}")) end ## @@ -247,7 +247,7 @@ def country_by_code(legacy_code = NOT_GIVEN, code: 'US') keywords << :code if legacy_code != NOT_GIVEN end - fetch('address.country_by_code.' + code) + fetch("address.country_by_code.#{code}") end ## @@ -265,7 +265,7 @@ def country_name_to_code(legacy_name = NOT_GIVEN, name: 'united_states') keywords << :name if legacy_name != NOT_GIVEN end - fetch('address.country_by_name.' + name) + fetch("address.country_by_name.#{name}") end ## diff --git a/lib/faker/default/bank.rb b/lib/faker/default/bank.rb index 85b2f1817f..688abdc6ea 100644 --- a/lib/faker/default/bank.rb +++ b/lib/faker/default/bank.rb @@ -140,15 +140,13 @@ def checksum(num_string) def compile_routing_number digit_one_two = %w[00 01 02 03 04 05 06 07 08 09 10 11 12] ((21..32).to_a + (61..72).to_a + [80]).each { |x| digit_one_two << x.to_s } - routing_num = digit_one_two.sample + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring - routing_num + digit_one_two.sample + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring end def compile_bsb_number digit_one_two = %w[01 03 06 08 11 12 73 76 78 30] state = (2..7).to_a.map(&:to_s).sample - bsb_num = digit_one_two.sample + state + rand_numstring + rand_numstring + rand_numstring - bsb_num + digit_one_two.sample + state + rand_numstring + rand_numstring + rand_numstring end # Calculates the mandatory checksum in 3rd and 4th characters in IBAN format @@ -182,7 +180,7 @@ def compile_fraction(routing_num) prefix = (1..50).to_a.map(&:to_s).sample numerator = routing_num.split('')[5..8].join.to_i.to_s denominator = routing_num.split('')[0..4].join.to_i.to_s - prefix + '-' + numerator + '/' + denominator + "#{prefix}-#{numerator}/#{denominator}" end def rand_numstring diff --git a/lib/faker/default/beer.rb b/lib/faker/default/beer.rb index 3b1abfa761..18369bf953 100644 --- a/lib/faker/default/beer.rb +++ b/lib/faker/default/beer.rb @@ -80,7 +80,7 @@ def malts # # @faker.version 1.6.2 def ibu - rand(10..100).to_s + ' IBU' + "#{rand(10..100)} IBU" end ## @@ -93,7 +93,7 @@ def ibu # # @faker.version 1.6.2 def alcohol - rand(2.0..10.0).round(1).to_s + '%' + "#{rand(2.0..10.0).round(1)}%" end ## @@ -106,7 +106,7 @@ def alcohol # # @faker.version 1.6.2 def blg - rand(5.0..20.0).round(1).to_s + '°Blg' + "#{rand(5.0..20.0).round(1)}°Blg" end end end diff --git a/lib/faker/default/chile_rut.rb b/lib/faker/default/chile_rut.rb index c74b1e04d9..ce0c529ee7 100644 --- a/lib/faker/default/chile_rut.rb +++ b/lib/faker/default/chile_rut.rb @@ -46,9 +46,10 @@ def dv partial_result end partial_check_digit = 11 - (digit_sum % 11) - if partial_check_digit == 11 + case partial_check_digit + when 11 '0' - elsif partial_check_digit == 10 + when 10 'k' else partial_check_digit.to_s diff --git a/lib/faker/default/code.rb b/lib/faker/default/code.rb index 8163e50761..8f34b2ef78 100644 --- a/lib/faker/default/code.rb +++ b/lib/faker/default/code.rb @@ -160,7 +160,7 @@ def sin partial = Array.new(7) { Faker::Config.random.rand(0..9) }.join # Generate 9th digit - check_digit = generate_sin_check_digit(registry + partial + '0').to_s + check_digit = generate_sin_check_digit("#{registry}#{partial}0").to_s registry + partial + check_digit end @@ -218,7 +218,7 @@ def generate_base10_isbn def generate_base13_isbn values = regexify(/\d{12}/) remainder = sum(values) { |value, index| index.even? ? value.to_i : value.to_i * 3 } % 10 - values << "-#{((10 - remainder) % 10)}" + values << "-#{(10 - remainder) % 10}" end def sum(values) diff --git a/lib/faker/default/commerce.rb b/lib/faker/default/commerce.rb index c2a3e5b2e2..a01e3bc608 100644 --- a/lib/faker/default/commerce.rb +++ b/lib/faker/default/commerce.rb @@ -121,7 +121,7 @@ def price(legacy_range = NOT_GIVEN, legacy_as_string = NOT_GIVEN, range: 0..100. price = (rand(range) * 100).floor / 100.0 if as_string price_parts = price.to_s.split('.') - price = price_parts[0] + '.' + price_parts[-1].ljust(2, '0') + price = "#{price_parts[0]}.#{price_parts[-1].ljust(2, '0')}" end price end diff --git a/lib/faker/default/company.rb b/lib/faker/default/company.rb index 00e4381829..c44bc52738 100644 --- a/lib/faker/default/company.rb +++ b/lib/faker/default/company.rb @@ -464,13 +464,11 @@ def luhn_algorithm(number) end end - control_digit = if (sum % 10).zero? - 0 - else - (sum / 10 + 1) * 10 - sum - end - - control_digit + if (sum % 10).zero? + 0 + else + (sum / 10 + 1) * 10 - sum + end end def abn_checksum(abn) diff --git a/lib/faker/default/food.rb b/lib/faker/default/food.rb index d50125aab7..7eebe60de1 100644 --- a/lib/faker/default/food.rb +++ b/lib/faker/default/food.rb @@ -93,7 +93,7 @@ def spice # # @faker.version 1.7.0 def measurement - fetch('food.measurement_sizes') + ' ' + fetch('food.measurements') + "#{fetch('food.measurement_sizes')} #{fetch('food.measurements')}" end ## diff --git a/lib/faker/default/hipster.rb b/lib/faker/default/hipster.rb index 0376d01ebc..4d5644b86a 100644 --- a/lib/faker/default/hipster.rb +++ b/lib/faker/default/hipster.rb @@ -82,7 +82,7 @@ def sentence(legacy_word_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, leg keywords << :random_words_to_add if legacy_random_words_to_add != NOT_GIVEN end - words(number: word_count + rand(random_words_to_add.to_i).to_i, supplemental: supplemental, spaces_allowed: open_compounds_allowed).join(' ').capitalize + '.' + "#{words(number: word_count + rand(random_words_to_add.to_i).to_i, supplemental: supplemental, spaces_allowed: open_compounds_allowed).join(' ').capitalize}." end ## @@ -185,9 +185,9 @@ def paragraph_by_chars(legacy_characters = NOT_GIVEN, legacy_supplemental = NOT_ paragraph = paragraph(sentence_count: 3, supplemental: supplemental) - paragraph += ' ' + paragraph(sentence_count: 3, supplemental: supplemental) while paragraph.length < characters + paragraph += " #{paragraph(sentence_count: 3, supplemental: supplemental)}" while paragraph.length < characters - paragraph[0...characters - 1] + '.' + "#{paragraph[0...characters - 1]}." end end end diff --git a/lib/faker/default/id_number.rb b/lib/faker/default/id_number.rb index 5f1411d286..3522177a1e 100644 --- a/lib/faker/default/id_number.rb +++ b/lib/faker/default/id_number.rb @@ -197,7 +197,7 @@ def chilean_id digits = Faker::Number.number(digits: 8) verification_code = chilean_verification_code(digits) - digits.to_s + '-' + verification_code.to_s + "#{digits}-#{verification_code}" end private @@ -256,7 +256,7 @@ def brazilian_document_checksum(digits) end * 10 end - def brazilian_document_digit(checksum, id = false) + def brazilian_document_digit(checksum, id: false) remainder = checksum % 11 id ? brazilian_id_digit(remainder) : brazilian_citizen_number_digit(remainder) end diff --git a/lib/faker/default/internet.rb b/lib/faker/default/internet.rb index 192f8dd9eb..60c53e557c 100644 --- a/lib/faker/default/internet.rb +++ b/lib/faker/default/internet.rb @@ -37,7 +37,7 @@ def safe_email(legacy_name = NOT_GIVEN, name: nil) construct_email( sanitize_email_local_part(username(specifier: name)), - 'example.' + sample(%w[org com net]) + "example.#{sample(%w[org com net])}" ) end @@ -50,7 +50,8 @@ def username(legacy_specifier = NOT_GIVEN, legacy_separators = NOT_GIVEN, specif with_locale(:en) do return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan) - if specifier.is_a?(Integer) + case specifier + when Integer # If specifier is Integer and has large value, Argument error exception is raised to overcome memory full error raise ArgumentError, 'Given argument is too large' if specifier > 10**6 @@ -62,7 +63,7 @@ def username(legacy_specifier = NOT_GIVEN, legacy_separators = NOT_GIVEN, specif break unless result.length < specifier && tries < 7 end return result * (specifier / result.length + 1) if specifier.positive? - elsif specifier.is_a?(Range) + when Range tries = 0 result = nil loop do diff --git a/lib/faker/default/invoice.rb b/lib/faker/default/invoice.rb index 6f1467c679..1d90b33196 100644 --- a/lib/faker/default/invoice.rb +++ b/lib/faker/default/invoice.rb @@ -43,7 +43,7 @@ def creditor_reference(legacy_ref = NOT_GIVEN, ref: '') ref = reference if ref.empty? - 'RF' + iban_checksum('RF', ref) + ref + "RF#{iban_checksum('RF', ref)}#{ref}" end ## diff --git a/lib/faker/default/json.rb b/lib/faker/default/json.rb index f23980f68f..4d091276b6 100644 --- a/lib/faker/default/json.rb +++ b/lib/faker/default/json.rb @@ -26,8 +26,8 @@ def shallow_json(legacy_width = NOT_GIVEN, legacy_options = NOT_GIVEN, width: 3, keywords << :options if legacy_options != NOT_GIVEN end - options[:key] = 'Faker::' + options[:key] - options[:value] = 'Faker::' + options[:value] + options[:key] = "Faker::#{options[:key]}" + options[:value] = "Faker::#{options[:value]}" hash = build_shallow_hash(width, options) JSON.generate(hash) @@ -84,8 +84,8 @@ def add_depth_to_json(legacy_json = NOT_GIVEN, legacy_width = NOT_GIVEN, legacy_ keywords << :options if legacy_options != NOT_GIVEN end - options[:key] = 'Faker::' + options[:key] - options[:value] = 'Faker::' + options[:value] + options[:key] = "Faker::#{options[:key]}" + options[:value] = "Faker::#{options[:value]}" hash = JSON.parse(json) hash.each do |key, _| diff --git a/lib/faker/default/lorem.rb b/lib/faker/default/lorem.rb index a67c97bc30..eb582f632c 100644 --- a/lib/faker/default/lorem.rb +++ b/lib/faker/default/lorem.rb @@ -107,9 +107,9 @@ def paragraph_by_chars(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVE paragraph = paragraph(sentence_count: 3, supplemental: supplemental) - paragraph += ' ' + paragraph(sentence_count: 3, supplemental: supplemental) while paragraph.length < number + paragraph += " #{paragraph(sentence_count: 3, supplemental: supplemental)}" while paragraph.length < number - paragraph[0...number - 1] + '.' + "#{paragraph[0...number - 1]}." end # rubocop:disable Metrics/ParameterLists diff --git a/lib/faker/default/measurement.rb b/lib/faker/default/measurement.rb index d736b86e80..c2eeede946 100644 --- a/lib/faker/default/measurement.rb +++ b/lib/faker/default/measurement.rb @@ -172,9 +172,10 @@ def check_for_plural(text, number) def define_measurement_locale(amount, locale) ensure_valid_amount(amount) - if amount == ALL + case amount + when ALL make_plural(fetch("measurement.#{locale}")) - elsif amount == NONE + when NONE fetch("measurement.#{locale}") else locale = check_for_plural(fetch("measurement.#{locale}"), amount) diff --git a/lib/faker/default/number.rb b/lib/faker/default/number.rb index e71ce9227d..02b35d0f3a 100644 --- a/lib/faker/default/number.rb +++ b/lib/faker/default/number.rb @@ -40,7 +40,7 @@ def leading_zero_number(legacy_digits = NOT_GIVEN, digits: 10) keywords << :digits if legacy_digits != NOT_GIVEN end - '0' + (2..digits).collect { digit }.join + "0#{(2..digits).collect { digit }.join}" end ## diff --git a/lib/faker/default/omniauth.rb b/lib/faker/default/omniauth.rb index 38ee773f94..dfabc8d204 100644 --- a/lib/faker/default/omniauth.rb +++ b/lib/faker/default/omniauth.rb @@ -9,6 +9,8 @@ class Omniauth < Base :email def initialize(name: nil, email: nil) + super() + @name = name || "#{Name.first_name} #{Name.last_name}" @email = email || Internet.safe_email(name: self.name) @first_name, @last_name = self.name.split diff --git a/lib/faker/default/relationship.rb b/lib/faker/default/relationship.rb index fadea00e78..b026db57b5 100644 --- a/lib/faker/default/relationship.rb +++ b/lib/faker/default/relationship.rb @@ -32,7 +32,7 @@ def familial(legacy_connection = NOT_GIVEN, connection: nil) end end - fetch('relationship.familial.' + connection) + fetch("relationship.familial.#{connection}") end ## diff --git a/lib/faker/default/space.rb b/lib/faker/default/space.rb index c2c5361c4a..b7e30ba43f 100644 --- a/lib/faker/default/space.rb +++ b/lib/faker/default/space.rb @@ -158,7 +158,7 @@ def company # # @faker.version 1.6.4 def distance_measurement - rand(10..100).to_s + ' ' + fetch('space.distance_measurement') + "#{rand(10..100)} #{fetch('space.distance_measurement')}" end ## diff --git a/lib/faker/default/stripe.rb b/lib/faker/default/stripe.rb index a5704f5224..19a146ff21 100644 --- a/lib/faker/default/stripe.rb +++ b/lib/faker/default/stripe.rb @@ -30,7 +30,7 @@ def valid_card(legacy_card_type = NOT_GIVEN, card_type: nil) end end - fetch('stripe.valid_cards.' + card_type) + fetch("stripe.valid_cards.#{card_type}") end ## @@ -60,7 +60,7 @@ def valid_token(legacy_card_type = NOT_GIVEN, card_type: nil) end end - fetch('stripe.valid_tokens.' + card_type) + fetch("stripe.valid_tokens.#{card_type}") end ## @@ -89,7 +89,7 @@ def invalid_card(legacy_card_error = NOT_GIVEN, card_error: nil) end end - fetch('stripe.invalid_cards.' + card_error) + fetch("stripe.invalid_cards.#{card_error}") end ## diff --git a/lib/faker/default/vehicle.rb b/lib/faker/default/vehicle.rb index 29e51069c3..97fa3813d9 100644 --- a/lib/faker/default/vehicle.rb +++ b/lib/faker/default/vehicle.rb @@ -278,7 +278,7 @@ def license_plate(legacy_state_abreviation = NOT_GIVEN, state_abbreviation: '') return regexify(bothify(fetch('vehicle.license_plate'))) if state_abbreviation.empty? - key = 'vehicle.license_plate_by_state.' + state_abbreviation + key = "vehicle.license_plate_by_state.#{state_abbreviation}" regexify(bothify(fetch(key))) end diff --git a/lib/faker/movies/star_wars.rb b/lib/faker/movies/star_wars.rb index c565b22211..a212f055fc 100644 --- a/lib/faker/movies/star_wars.rb +++ b/lib/faker/movies/star_wars.rb @@ -119,7 +119,7 @@ def vehicle def wookiee_sentence sentence = sample(wookiee_words).capitalize - rand(0..10).times { sentence += ' ' + sample(wookiee_words) } + rand(0..10).times { sentence += " #{sample(wookiee_words)}" } sentence + sample(['.', '?', '!']) end @@ -158,7 +158,7 @@ def quote(legacy_character = NOT_GIVEN, character: nil) raise ArgumentError, "Character for quotes can be left blank or #{quoted_characters.keys.join(', ')}" unless quoted_characters.key?(character.to_sym) end - fetch('star_wars.quotes.' + character) + fetch("star_wars.quotes.#{character}") end def call_numbers diff --git a/lib/helpers/unique_generator.rb b/lib/helpers/unique_generator.rb index 21f375d679..1663dac6c3 100644 --- a/lib/helpers/unique_generator.rb +++ b/lib/helpers/unique_generator.rb @@ -14,6 +14,7 @@ def initialize(generator, max_retries) @previous_results = Hash.new { |hash, key| hash[key] = Set.new } end + # rubocop:disable Lint/MissingSuper def method_missing(name, *arguments) self.class.marked_unique.add(self) @@ -28,6 +29,8 @@ def method_missing(name, *arguments) raise RetryLimitExceeded, "Retry limit exceeded for #{name}" end + # rubocop:enable Lint/MissingSuper + # Have method_missing use ruby 2.x keywords if the method exists. # This is necessary because the syntax for passing arguments (`...`) # is invalid on versions before Ruby 2.7, so it can't be used. diff --git a/script/txt2html b/script/txt2html index 51f835caea..65d207ba51 100755 --- a/script/txt2html +++ b/script/txt2html @@ -12,7 +12,7 @@ end require 'redcloth' require 'syntax/convertors/html' require 'erb' -require File.dirname(__FILE__) + '/../lib/faker/version.rb' +require "#{File.dirname(__FILE__)}/../lib/faker/version.rb" version = Faker::VERSION download = 'http://rubyforge.org/projects/faker' diff --git a/test/faker/default/test_avatar.rb b/test/faker/default/test_avatar.rb index 3760bf6c0d..1a9e879e6b 100644 --- a/test/faker/default/test_avatar.rb +++ b/test/faker/default/test_avatar.rb @@ -8,15 +8,15 @@ def setup end def test_avatar - assert !@tester.image.match(%r{https:\/\/robohash\.org\/(.+)\.png})[1].nil? + assert !@tester.image.match(%r{https://robohash\.org/(.+)\.png})[1].nil? end def test_avatar_with_param - assert @tester.image(slug: 'faker').match(%r{https:\/\/robohash\.org\/(.+)\.png})[1] == 'faker' + assert @tester.image(slug: 'faker').match(%r{https://robohash\.org/(.+)\.png})[1] == 'faker' end def test_avatar_with_correct_size - assert @tester.image(slug: 'faker', size: '150x320').match(%r{https:\/\/robohash\.org\/faker\.png\?size=(.+)&.*})[1] == '150x320' + assert @tester.image(slug: 'faker', size: '150x320').match(%r{https://robohash\.org/faker\.png\?size=(.+)&.*})[1] == '150x320' end def test_avatar_with_incorrect_size @@ -26,7 +26,7 @@ def test_avatar_with_incorrect_size end def test_avatar_with_supported_format - assert @tester.image(slug: 'faker', size: '300x300', format: 'jpg').match(%r{https:\/\/robohash\.org\/faker\.jpg}) + assert @tester.image(slug: 'faker', size: '300x300', format: 'jpg').match(%r{https://robohash\.org/faker\.jpg}) end def test_avatar_with_incorrect_format @@ -36,10 +36,10 @@ def test_avatar_with_incorrect_format end def test_avatar_with_set - assert @tester.image(slug: 'faker', size: '300x300', format: 'jpg', set: 'set2').match(%r{https:\/\/robohash\.org\/faker\.jpg.*set=set2}) + assert @tester.image(slug: 'faker', size: '300x300', format: 'jpg', set: 'set2').match(%r{https://robohash\.org/faker\.jpg.*set=set2}) end def test_avatar_with_bgset - assert @tester.image(slug: 'faker', size: '300x300', format: 'jpg', set: 'set1', bgset: 'bg1').match(%r{https:\/\/robohash\.org\/faker\.jpg.*bgset=bg1}) + assert @tester.image(slug: 'faker', size: '300x300', format: 'jpg', set: 'set1', bgset: 'bg1').match(%r{https://robohash\.org/faker\.jpg.*bgset=bg1}) end end diff --git a/test/faker/default/test_faker_address.rb b/test/faker/default/test_faker_address.rb index c16b30febc..7be96d3404 100644 --- a/test/faker/default/test_faker_address.rb +++ b/test/faker/default/test_faker_address.rb @@ -40,7 +40,7 @@ def test_zip_code end def test_time_zone - assert @tester.time_zone.match(%r{\w+\/\w+}) + assert @tester.time_zone.match(%r{\w+/\w+}) end def test_street_suffix diff --git a/test/faker/default/test_faker_bank.rb b/test/faker/default/test_faker_bank.rb index 4b307a18f7..ae4864c55c 100644 --- a/test/faker/default/test_faker_bank.rb +++ b/test/faker/default/test_faker_bank.rb @@ -23,7 +23,7 @@ def test_routing_number def test_routing_number_with_format fraction = Faker::Bank.routing_number_with_format - assert fraction.match(/\d{1,2}[-]\d{1,4}[\/]\d{1,4}/) + assert fraction.match(/\d{1,2}-\d{1,4}\/\d{1,4}/) end def test_bsb_number diff --git a/test/faker/default/test_faker_cannabis.rb b/test/faker/default/test_faker_cannabis.rb index 40a681fb3d..5ef1ce7768 100644 --- a/test/faker/default/test_faker_cannabis.rb +++ b/test/faker/default/test_faker_cannabis.rb @@ -8,43 +8,43 @@ def setup end def test_strain - 10.times { assert Faker::Cannabis.strain.match(/[\w]+/) } + 10.times { assert Faker::Cannabis.strain.match(/\w+/) } end def test_cannabinoid_abbreviation - 10.times { assert Faker::Cannabis.cannabinoid_abbreviation.match(/[\w]+/) } + 10.times { assert Faker::Cannabis.cannabinoid_abbreviation.match(/\w+/) } end def test_cannabinoid - 10.times { assert Faker::Cannabis.cannabinoid.match(/[\w]+/) } + 10.times { assert Faker::Cannabis.cannabinoid.match(/\w+/) } end def test_terpene - 10.times { assert Faker::Cannabis.terpene.match(/[\w]+/) } + 10.times { assert Faker::Cannabis.terpene.match(/\w+/) } end def test_medical_use - 10.times { assert Faker::Cannabis.medical_use.match(/[\w]+/) } + 10.times { assert Faker::Cannabis.medical_use.match(/\w+/) } end def test_health_benefit - 10.times { assert Faker::Cannabis.health_benefit.match(/[\w]+/) } + 10.times { assert Faker::Cannabis.health_benefit.match(/\w+/) } end def test_category - 10.times { assert Faker::Cannabis.category.match(/[\w]+/) } + 10.times { assert Faker::Cannabis.category.match(/\w+/) } end def test_type - 10.times { assert Faker::Cannabis.type.match(/[\w]+/) } + 10.times { assert Faker::Cannabis.type.match(/\w+/) } end def test_buzzword - 10.times { assert Faker::Cannabis.buzzword.match(/[\w]+/) } + 10.times { assert Faker::Cannabis.buzzword.match(/\w+/) } end def test_brand - 10.times { assert Faker::Cannabis.brand.match(/[\w]+/) } + 10.times { assert Faker::Cannabis.brand.match(/\w+/) } end def test_locales diff --git a/test/faker/default/test_faker_code.rb b/test/faker/default/test_faker_code.rb index 95ed7494a5..6d0a8b59c5 100644 --- a/test/faker/default/test_faker_code.rb +++ b/test/faker/default/test_faker_code.rb @@ -48,7 +48,7 @@ def test_nric end def test_imei_regexp - assert @tester.imei.match(/\A[\d\.\:\-\s]+\z/i) + assert @tester.imei.match(/\A[\d.:\-\s]+\z/i) end def test_imei_luhn_value diff --git a/test/faker/default/test_faker_coffee.rb b/test/faker/default/test_faker_coffee.rb index 65fcca10e2..2433ec4ab7 100644 --- a/test/faker/default/test_faker_coffee.rb +++ b/test/faker/default/test_faker_coffee.rb @@ -16,7 +16,7 @@ def setup end def test_origin - assert origin = @tester.origin.match(/\A(?([[:alnum:]]+'?-?.?,?\s?){1,5}), (?([[:alnum:]]+\s?){1,5})\z/) + assert origin = @tester.origin.match(/\A(?(?:[[:alnum:]]+'?-?.?,?\s?){1,5}), (?(?:[[:alnum:]]+\s?){1,5})\z/) region = origin[:region] country = origin[:country] diff --git a/test/faker/default/test_faker_compass.rb b/test/faker/default/test_faker_compass.rb index 514c2fc39c..c918db7809 100644 --- a/test/faker/default/test_faker_compass.rb +++ b/test/faker/default/test_faker_compass.rb @@ -8,7 +8,7 @@ def setup @word_pattern = /\w+/ @multiword_pattern = /^\w+ by \w+$/ @combined_pattern = /^(?:\w+|\w+ by \w+|[\w\-]+)$/ - @number_pattern = /^[\d]+(?:.\d\d?)?$/ + @number_pattern = /^\d+(?:.\d\d?)?$/ @letter_pattern = /^[NEWS]?[NEWS](?:b?[NEWS])?$/ end diff --git a/test/faker/default/test_faker_computer.rb b/test/faker/default/test_faker_computer.rb index a1a9501f9c..5dc9ef7ce5 100644 --- a/test/faker/default/test_faker_computer.rb +++ b/test/faker/default/test_faker_computer.rb @@ -19,7 +19,7 @@ def test_platform def test_stack # puts @tester.stack assert stack = @tester.stack - .match(/\A(?([[:alnum:]]+\s?){1,5}), (?([[:alnum:]]+-?.?\)?\(?\s?){1,5})\z/) + .match(/\A(?(?:[[:alnum:]]+\s?){1,5}), (?(?:[[:alnum:]]+-?.?\)?\(?\s?){1,5})\z/) platform = stack[:platform] search_format_platform = platform.downcase diff --git a/test/faker/default/test_faker_construction.rb b/test/faker/default/test_faker_construction.rb index faadcdf702..8442a2c6f6 100644 --- a/test/faker/default/test_faker_construction.rb +++ b/test/faker/default/test_faker_construction.rb @@ -8,27 +8,27 @@ def setup end def test_material - assert Faker::Construction.material.match(/[\w]+/) + assert Faker::Construction.material.match(/\w+/) end def test_heavy_equipment - assert Faker::Construction.heavy_equipment.match(/[\w]+/) + assert Faker::Construction.heavy_equipment.match(/\w+/) end def test_trade - assert Faker::Construction.trade.match(/[\w]+/) + assert Faker::Construction.trade.match(/\w+/) end def test_subcontract_category - assert Faker::Construction.subcontract_category.match(/[\w]+/) + assert Faker::Construction.subcontract_category.match(/\w+/) end def test_standard_cost_code - assert Faker::Construction.standard_cost_code.match(/[\w]+/) + assert Faker::Construction.standard_cost_code.match(/\w+/) end def test_role - assert Faker::Construction.role.match(/[\w]+/) + assert Faker::Construction.role.match(/\w+/) end def test_locales diff --git a/test/faker/default/test_faker_crypto_coin.rb b/test/faker/default/test_faker_crypto_coin.rb index 5d57b35079..4ec7508a8c 100644 --- a/test/faker/default/test_faker_crypto_coin.rb +++ b/test/faker/default/test_faker_crypto_coin.rb @@ -7,7 +7,7 @@ class TestFakerCryptoCoin < Test::Unit::TestCase ACRONYM = 1 URL_LOGO = 2 - REGEX_COIN_NAME = /[a-zA-Z \.]{3,}/.freeze + REGEX_COIN_NAME = /[a-zA-Z .]{3,}/.freeze REGEX_ACRONYM = /\w+{3,}/.freeze REGEX_URL_LOGO = /^https:\/\/i.imgur.com\/.......\./.freeze diff --git a/test/faker/default/test_faker_currency.rb b/test/faker/default/test_faker_currency.rb index d964d514cf..2f97362961 100644 --- a/test/faker/default/test_faker_currency.rb +++ b/test/faker/default/test_faker_currency.rb @@ -8,7 +8,7 @@ def setup end def test_name - assert @tester.name.match(/[\w\' ]+/) + assert @tester.name.match(/[\w' ]+/) end def test_code diff --git a/test/faker/default/test_faker_drone.rb b/test/faker/default/test_faker_drone.rb index 568187bb92..aa89d9f59a 100644 --- a/test/faker/default/test_faker_drone.rb +++ b/test/faker/default/test_faker_drone.rb @@ -52,7 +52,7 @@ def test_max_tilt_angle end def test_operating_temperature - assert @tester.operating_temperature.match(/[0-9]{2}\W\-[0-9]{3}\WF/) + assert @tester.operating_temperature.match(/[0-9]{2}\W-[0-9]{3}\WF/) end def test_battery_capacity @@ -72,7 +72,7 @@ def test_battery_voltage end def test_charging_temperature - assert @tester.charging_temperature.match(/[0-9]{2}\W\-[0-9]{3}\WF/) + assert @tester.charging_temperature.match(/[0-9]{2}\W-[0-9]{3}\WF/) end def test_max_charging_power @@ -96,7 +96,7 @@ def video_format end def test_max_shutter_speed_range - assert @tester.shutter_speed_range.match(/[0-9]{1,2}\-1\/[0-9]{1,4}s/) + assert @tester.shutter_speed_range.match(/[0-9]{1,2}-1\/[0-9]{1,4}s/) end def test_max_shutter_speed diff --git a/test/faker/default/test_faker_file.rb b/test/faker/default/test_faker_file.rb index 2850e02eff..9f4627250e 100644 --- a/test/faker/default/test_faker_file.rb +++ b/test/faker/default/test_faker_file.rb @@ -12,17 +12,17 @@ def test_extension end def test_mime_type_format - assert @tester.mime_type.match(%r{(.*)\/(.*)+}) + assert @tester.mime_type.match(%r{(.*)/(.*)+}) end def test_file_name assert @tester .file_name - .match(%r{^([a-z\-_.]+)(\\|\/)([a-z\-_]+)\.([a-z]+)$}) + .match(%r{^([a-z\-_.]+)(\\|/)([a-z\-_]+)\.([a-z]+)$}) end def test_dir - assert @tester.dir.match(%r{^(([a-z\-_.]+)(\\|\/)){2}([a-z\-_.]+)$}) + assert @tester.dir.match(%r{^(([a-z\-_.]+)(\\|/)){2}([a-z\-_.]+)$}) end def test_dir_with_args diff --git a/test/faker/default/test_faker_fillmurray.rb b/test/faker/default/test_faker_fillmurray.rb index fc09f42058..a053d73e6e 100644 --- a/test/faker/default/test_faker_fillmurray.rb +++ b/test/faker/default/test_faker_fillmurray.rb @@ -8,11 +8,11 @@ def setup end def test_fillmurray - assert !@tester.image(grayscale: false, width: '300', height: '300').match(%r{https:\/\/www\.fillmurray\.com\/(\d+)\/(\d+)}).nil? + assert !@tester.image(grayscale: false, width: '300', height: '300').match(%r{https://www\.fillmurray\.com/(\d+)/(\d+)}).nil? end def test_fillmurray_with_grayscale - assert @tester.image(grayscale: true, width: '300', height: '300').match(%r{https:\/\/www\.fillmurray\.com\/(g?\/?)(\d+)\/(\d+)})[1] == 'g/' + assert @tester.image(grayscale: true, width: '300', height: '300').match(%r{https://www\.fillmurray\.com/(g?/?)(\d+)/(\d+)})[1] == 'g/' end def test_fillmurray_with_incorrect_height_format diff --git a/test/faker/default/test_faker_id_number.rb b/test/faker/default/test_faker_id_number.rb index cf372ef46f..7c27f1ea4c 100644 --- a/test/faker/default/test_faker_id_number.rb +++ b/test/faker/default/test_faker_id_number.rb @@ -117,9 +117,9 @@ def test_brazilian_document_checksum 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, true) - id_digit11 = Faker::IDNumber.send(:brazilian_document_digit, 0, true) - id_digit_other = Faker::IDNumber.send(:brazilian_document_digit, 2, true) + 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 citizen_number_digit10, '0' assert_equal citizen_number_digit_other, '9' assert_equal id_digit10, 'X' diff --git a/test/faker/default/test_faker_internet.rb b/test/faker/default/test_faker_internet.rb index f56c74a936..b3d32822ab 100644 --- a/test/faker/default/test_faker_internet.rb +++ b/test/faker/default/test_faker_internet.rb @@ -164,11 +164,11 @@ def test_password_without_mixed_case end def test_password_with_special_chars - assert @tester.password(min_length: 8, max_length: 12, mix_case: true, special_characters: true).match(/[!@#\$%\^&\*]+/) + assert @tester.password(min_length: 8, max_length: 12, mix_case: true, special_characters: true).match(/[!@#$%\^&*]+/) end def test_password_without_special_chars - assert @tester.password(min_length: 8, max_length: 12, mix_case: true).match(/[^!@#\$%\^&\*]+/) + assert @tester.password(min_length: 8, max_length: 12, mix_case: true).match(/[^!@#$%\^&*]+/) end def test_domain_name_without_subdomain @@ -253,7 +253,7 @@ def test_public_ip_v4_address end def test_ip_v4_cidr - assert @tester.ip_v4_cidr.match(%r(\/\d{1,2}$)) + assert @tester.ip_v4_cidr.match(%r(/\d{1,2}$)) 1000.times do assert((1..32).cover?(@tester.ip_v4_cidr.split('/').last.to_i)) @@ -281,7 +281,7 @@ def test_ip_v6_address end def test_ip_v6_cidr - assert @tester.ip_v6_cidr.match(%r{\/\d{1,3}$}) + assert @tester.ip_v6_cidr.match(%r{/\d{1,3}$}) 1000.times do assert((1..128).cover?(@tester.ip_v6_cidr.split('/').last.to_i)) @@ -289,15 +289,15 @@ def test_ip_v6_cidr end def test_slug - assert @tester.slug.match(/^[a-z]+(_|\-)[a-z]+$/) + assert @tester.slug.match(/^[a-z]+(_|-)[a-z]+$/) end def test_slug_with_content_arg - assert @tester.slug(words: 'Foo bAr baZ').match(/^foo(_|\.|\-)bar(_|\.|\-)baz$/) + assert @tester.slug(words: 'Foo bAr baZ').match(/^foo(_|\.|-)bar(_|\.|-)baz$/) end def test_slug_with_unwanted_content_arg - assert @tester.slug(words: 'Foo.. bAr., baZ,,').match(/^foo(_|\.|\-)bar(_|\.|\-)baz$/) + assert @tester.slug(words: 'Foo.. bAr., baZ,,').match(/^foo(_|\.|-)bar(_|\.|-)baz$/) end def test_slug_with_glue_arg @@ -305,7 +305,7 @@ def test_slug_with_glue_arg end def test_url - assert @tester.url(host: 'domain.com', path: '/username', scheme: 'https').match(%r{^https:\/\/domain\.com\/username$}) + assert @tester.url(host: 'domain.com', path: '/username', scheme: 'https').match(%r{^https://domain\.com/username$}) end def test_device_token @@ -334,9 +334,9 @@ def test_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)) + 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 end diff --git a/test/faker/default/test_faker_lorem.rb b/test/faker/default/test_faker_lorem.rb index 3f765bf3d8..407fa3d3d2 100644 --- a/test/faker/default/test_faker_lorem.rb +++ b/test/faker/default/test_faker_lorem.rb @@ -15,7 +15,7 @@ def test_character end def test_character_type - assert @tester.character.class == String + assert @tester.character.instance_of?(String) end def test_characters diff --git a/test/faker/default/test_faker_measurement.rb b/test/faker/default/test_faker_measurement.rb index 2b700788e2..924a399478 100644 --- a/test/faker/default/test_faker_measurement.rb +++ b/test/faker/default/test_faker_measurement.rb @@ -22,10 +22,10 @@ def volume custom_amount_integer = @tester.volume(276) assert singular_unit.match(/\A\D+[^s]\z/) - assert plural_unit.match(/\A\D+[s]\z/) + assert plural_unit.match(/\A\D+s\z/) assert @tester.volume.match(/\d\s[a-z]/) - assert custom_amount_float.match(/\d\s[a-z]+[s]\z/) - assert custom_amount_integer.match(/\d\s[a-z]+[s]\z/) + assert custom_amount_float.match(/\d\s[a-z]+s\z/) + assert custom_amount_integer.match(/\d\s[a-z]+s\z/) end def weight diff --git a/test/faker/default/test_faker_phone_number.rb b/test/faker/default/test_faker_phone_number.rb index 72f491f1b2..dc144c3211 100644 --- a/test/faker/default/test_faker_phone_number.rb +++ b/test/faker/default/test_faker_phone_number.rb @@ -5,7 +5,7 @@ class TestFakerPhone < Test::Unit::TestCase def setup @tester = Faker::PhoneNumber - @phone_with_country_code_regex = /\A\+(\s|\d|\-|\(|\)|x|\.)*\z/ + @phone_with_country_code_regex = /\A\+(\s|\d|-|\(|\)|x|\.)*\z/ end def test_country_code diff --git a/test/faker/default/test_faker_street.rb b/test/faker/default/test_faker_street.rb index 04a33e78d1..7c61975604 100644 --- a/test/faker/default/test_faker_street.rb +++ b/test/faker/default/test_faker_street.rb @@ -70,7 +70,7 @@ def test_timezone_support def test_full_address I18n.with_locale('en') do - assert_match(/^(.+\s)?\d+ [\w'\s]+\, [\w'\s]+\, [\w']+ \d+/, @tester.full_address) + assert_match(/^(.+\s)?\d+ [\w'\s]+, [\w'\s]+, [\w']+ \d+/, @tester.full_address) end end end diff --git a/test/faker/default/test_faker_types.rb b/test/faker/default/test_faker_types.rb index 1246a53448..9e57ad1e68 100644 --- a/test/faker/default/test_faker_types.rb +++ b/test/faker/default/test_faker_types.rb @@ -11,7 +11,7 @@ def setup end def test_rb_string_is_or_correct_type - assert @tester.rb_string.class == String + assert @tester.rb_string.instance_of?(String) end def test_string_returns_correct_number_of_words @@ -25,7 +25,7 @@ def test_character end def test_integer - assert @tester.rb_integer.class == Integer + assert @tester.rb_integer.instance_of?(Integer) end def test_rb_integer_between @@ -36,7 +36,7 @@ def test_rb_integer_between end def test_rb_hash_returns_a_hash - assert @tester.rb_hash.class == Hash + assert @tester.rb_hash.instance_of?(Hash) end def test_hash_returns_the_correct_number_of_keys @@ -46,7 +46,7 @@ def test_hash_returns_the_correct_number_of_keys end def test_complex_rb_hash_returns_a_hash - assert @tester.complex_rb_hash.class == Hash + assert @tester.complex_rb_hash.instance_of?(Hash) end def test_complex_hash_returns_the_correct_number_of_keys @@ -56,7 +56,7 @@ def test_complex_hash_returns_the_correct_number_of_keys end def test_rb_array_returns_array - assert @tester.rb_array.class == Array + assert @tester.rb_array.instance_of?(Array) end def test_array_has_the_right_array diff --git a/test/faker/default/test_lorem_pixel.rb b/test/faker/default/test_lorem_pixel.rb index bc871fd261..5266596167 100644 --- a/test/faker/default/test_lorem_pixel.rb +++ b/test/faker/default/test_lorem_pixel.rb @@ -8,15 +8,15 @@ def setup end def test_lorempixel - assert !@tester.image.match(%r{https:\/\/lorempixel\.com\/(\d+\/\d+)})[1].nil? + assert !@tester.image.match(%r{https://lorempixel\.com/(\d+/\d+)})[1].nil? end def test_lorempixel_insecure - assert !@tester.image(size: '300x300', is_gray: nil, category: nil, number: nil, text: nil, secure: false).match(%r{http:\/\/lorempixel\.com\/(\d+\/\d+)})[1].nil? + assert !@tester.image(size: '300x300', is_gray: nil, category: nil, number: nil, text: nil, secure: false).match(%r{http://lorempixel\.com/(\d+/\d+)})[1].nil? end def test_image_with_custom_size - assert @tester.image(size: '3x3').match(%r{https:\/\/lorempixel\.com\/(\d+\/\d+)})[1] == '3/3' + assert @tester.image(size: '3x3').match(%r{https://lorempixel\.com/(\d+/\d+)})[1] == '3/3' end def test_image_with_incorrect_size @@ -26,11 +26,11 @@ def test_image_with_incorrect_size end def test_image_gray - assert @tester.image(size: '300x300', is_gray: true).match(%r{https:\/\/lorempixel\.com\/g\/\d+\/\d+}) + assert @tester.image(size: '300x300', is_gray: true).match(%r{https://lorempixel\.com/g/\d+/\d+}) end def test_image_with_supported_category - assert @tester.image(size: '300x300', is_gray: false, category: 'animals').match(%r{https:\/\/lorempixel\.com\/\d+\/\d+\/(.*)})[1] == 'animals' + assert @tester.image(size: '300x300', is_gray: false, category: 'animals').match(%r{https://lorempixel\.com/\d+/\d+/(.*)})[1] == 'animals' end def test_image_with_incorrect_category @@ -40,7 +40,7 @@ def test_image_with_incorrect_category end def test_image_with_supported_category_and_correct_number - assert @tester.image(size: '300x300', is_gray: false, category: 'animals', number: 3).match(%r{https:\/\/lorempixel\.com\/\d+\/\d+\/.+\/(\d+)})[1] == '3' + assert @tester.image(size: '300x300', is_gray: false, category: 'animals', number: 3).match(%r{https://lorempixel\.com/\d+/\d+/.+/(\d+)})[1] == '3' end def test_image_with_supported_category_and_incorrect_number @@ -56,11 +56,11 @@ def test_image_with_correct_number_and_without_category end def test_image_with_text_correct_number_and_supported_category - assert @tester.image(size: '300x300', is_gray: false, category: 'animals', number: 3, text: 'Dummy-text').match(%r{https:\/\/lorempixel\.com\/\d+\/\d+\/.+\/3\/(.+)})[1] == 'Dummy-text' + assert @tester.image(size: '300x300', is_gray: false, category: 'animals', number: 3, text: 'Dummy-text').match(%r{https://lorempixel\.com/\d+/\d+/.+/3/(.+)})[1] == 'Dummy-text' end def test_image_with_text_supported_category_and_text_without_number - assert @tester.image(size: '300x300', is_gray: false, category: 'animals', number: nil, text: 'Dummy-text').match(%r{https:\/\/lorempixel\.com\/\d+\/\d+\/.+\/(.+)})[1] == 'Dummy-text' + assert @tester.image(size: '300x300', is_gray: false, category: 'animals', number: nil, text: 'Dummy-text').match(%r{https://lorempixel\.com/\d+/\d+/.+/(.+)})[1] == 'Dummy-text' end def test_image_with_text_without_number_and_category diff --git a/test/faker/default/test_michael_scott.rb b/test/faker/default/test_michael_scott.rb deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/faker/default/test_placeholdit.rb b/test/faker/default/test_placeholdit.rb index cf36811477..d4cfd025a5 100644 --- a/test/faker/default/test_placeholdit.rb +++ b/test/faker/default/test_placeholdit.rb @@ -8,11 +8,11 @@ def setup end def test_placeholdit - assert !@tester.image.match(%r{https:\/\/placehold\.it\/(.+)(png?)})[1].nil? + assert !@tester.image.match(%r{https://placehold\.it/(.+)(png?)})[1].nil? end def test_avatar_with_custom_size - assert @tester.image(size: '3x3').match(%r{https:\/\/placehold\.it\/+(\d+x\d+)})[1] == '3x3' + assert @tester.image(size: '3x3').match(%r{https://placehold\.it/+(\d+x\d+)})[1] == '3x3' end def test_avatar_with_incorrect_size @@ -22,7 +22,7 @@ def test_avatar_with_incorrect_size end def test_avatar_with_supported_format - assert @tester.image(size: '300x300', format: 'jpg').match(%r{https:\/\/placehold\.it\/(.+)(jpg?)}) + assert @tester.image(size: '300x300', format: 'jpg').match(%r{https://placehold\.it/(.+)(jpg?)}) end def test_avatar_with_incorrect_format @@ -32,15 +32,15 @@ def test_avatar_with_incorrect_format end def test_avatar_background_with_correct_six_char_hex - assert @tester.image(size: '300x300', format: 'jpg', background_color: 'ffffff').match(%r{https:\/\/placehold\.it\/(.+)(jpg?)\/ffffff}) + assert @tester.image(size: '300x300', format: 'jpg', background_color: 'ffffff').match(%r{https://placehold\.it/(.+)(jpg?)/ffffff}) end def test_avatar_background_with_correct_three_char_hex - assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff').match(%r{https:\/\/placehold\.it\/(.+)(jpg?)\/fff}) + assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff').match(%r{https://placehold\.it/(.+)(jpg?)/fff}) end def test_avatar_background_with_random_color - assert @tester.image(size: '300x300', format: 'jpg', background_color: :random).match(%r{https:\/\/placehold\.it\/(.+)(jpg?)\/[a-f0-9]{6}}) + assert @tester.image(size: '300x300', format: 'jpg', background_color: :random).match(%r{https://placehold\.it/(.+)(jpg?)/[a-f0-9]{6}}) end def test_avatar_background_with_wrong_six_char_hex @@ -62,15 +62,15 @@ def test_avatar_background_with_wrong_three_char_hex end def test_avatar_font_color_with_correct_six_char_hex - assert @tester.image(size: '300x300', format: 'jpg', background_color: 'ffffff', text_color: '000000').match(%r{https:\/\/placehold\.it\/(.+)(jpg?)\/ffffff\/000000}) + assert @tester.image(size: '300x300', format: 'jpg', background_color: 'ffffff', text_color: '000000').match(%r{https://placehold\.it/(.+)(jpg?)/ffffff/000000}) end def test_avatar_font_color_with_correct_three_char_hex - assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000').match(%r{https:\/\/placehold\.it\/(.+)(jpg?)\/fff}) + assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000').match(%r{https://placehold\.it/(.+)(jpg?)/fff}) end def test_avatar_font_color_with_random_color - assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: :random).match(%r{https:\/\/placehold\.it\/(.+)(jpg?)\/fff\/[a-f0-9]{6}}) + assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: :random).match(%r{https://placehold\.it/(.+)(jpg?)/fff/[a-f0-9]{6}}) end def test_avatar_font_color_with_wrong_six_char_hex @@ -92,10 +92,10 @@ def test_avatar_font_color_with_wrong_three_char_hex end def test_text_not_present - assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000').match(%r{https:\/\/placehold\.it\/[^\\?]+$}) + assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000').match(%r{https://placehold\.it/[^\\?]+$}) end def test_text_present - assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000', text: 'hello').match(%r{https:\/\/placehold\.it\/(.+)\?text=hello}) + assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000', text: 'hello').match(%r{https://placehold\.it/(.+)\?text=hello}) end end diff --git a/test/faker/music/test_faker_music.rb b/test/faker/music/test_faker_music.rb index 4a2729142f..baa5516239 100644 --- a/test/faker/music/test_faker_music.rb +++ b/test/faker/music/test_faker_music.rb @@ -8,10 +8,12 @@ def setup end def test_keys + # rubocop:disable Style/HashEachMethods assert @tester.keys.size == 7 @tester.keys.each do |key| refute key.to_s.empty? end + # rubocop:enable Style/HashEachMethods end def test_key_variants diff --git a/test/faker/tv_shows/test_breaking_bad.rb b/test/faker/tv_shows/test_breaking_bad.rb index 5cb110d416..f00ee93959 100644 --- a/test/faker/tv_shows/test_breaking_bad.rb +++ b/test/faker/tv_shows/test_breaking_bad.rb @@ -8,10 +8,10 @@ def setup end def test_character - 10.times { assert @tester.character.match(/[\w]+/) } + 10.times { assert @tester.character.match(/\w+/) } end def test_episode - 10.times { assert @tester.episode.match(/[\w]+/) } + 10.times { assert @tester.episode.match(/\w+/) } end end diff --git a/test/faker/tv_shows/test_dr_who.rb b/test/faker/tv_shows/test_dr_who.rb index d402f33ebe..e4544ae7e7 100644 --- a/test/faker/tv_shows/test_dr_who.rb +++ b/test/faker/tv_shows/test_dr_who.rb @@ -9,48 +9,48 @@ def setup end def test_character - 10.times { assert @tester.character.match(/[\w]+/) } + 10.times { assert @tester.character.match(/\w+/) } end def test_the_doctor - 10.times { assert @tester.the_doctor.match(/[\w]+/) } + 10.times { assert @tester.the_doctor.match(/\w+/) } end def test_actor - 10.times { assert @tester.actor.match(/[\w]+/) } + 10.times { assert @tester.actor.match(/\w+/) } end def test_catch_phrase - 10.times { assert @tester.catch_phrase.match(/[\w]+/) } + 10.times { assert @tester.catch_phrase.match(/\w+/) } end def test_quote - 10.times { assert @tester.quote.match(/[\w]+/) } + 10.times { assert @tester.quote.match(/\w+/) } end # deprecated def test_villian - 10.times { assert @tester.villian.match(/[\w]+/) } + 10.times { assert @tester.villian.match(/\w+/) } end def test_villain - 10.times { assert @tester.villain.match(/[\w]+/) } + 10.times { assert @tester.villain.match(/\w+/) } end def test_specie - 10.times { assert @tester.specie.match(/[\w]+/) } + 10.times { assert @tester.specie.match(/\w+/) } end def test_locales [nil, 'en', 'de'].each do |_locale_name| Faker::Config.locale = 'de' - assert @tester.character .is_a? String - assert @tester.the_doctor .is_a? String + assert @tester.character.is_a? String + assert @tester.the_doctor.is_a? String assert @tester.catch_phrase.is_a? String - assert @tester.quote .is_a? String - assert @tester.villian .is_a? String # deprecated - assert @tester.villain .is_a? String - assert @tester.specie .is_a? String + assert @tester.quote.is_a? String + assert @tester.villian.is_a? String # deprecated + assert @tester.villain.is_a? String + assert @tester.specie.is_a? String end end end diff --git a/test/faker/tv_shows/test_futurama.rb b/test/faker/tv_shows/test_futurama.rb index 4e481425e0..436b8afc7a 100644 --- a/test/faker/tv_shows/test_futurama.rb +++ b/test/faker/tv_shows/test_futurama.rb @@ -8,18 +8,18 @@ def setup end def test_characters - 10.times { assert @tester.character.match(/[\w]+/) } + 10.times { assert @tester.character.match(/\w+/) } end def test_locations - 10.times { assert @tester.location.match(/[\w]+/) } + 10.times { assert @tester.location.match(/\w+/) } end def test_quote - 10.times { assert @tester.quote.match(/[\w]+/) } + 10.times { assert @tester.quote.match(/\w+/) } end def test_hermes_catchphrases - 10.times { assert @tester.hermes_catchphrase.match(/[\w]+/) } + 10.times { assert @tester.hermes_catchphrase.match(/\w+/) } end end diff --git a/test/faker/tv_shows/test_simpsons.rb b/test/faker/tv_shows/test_simpsons.rb index 54c6ae23ff..db5da5299e 100644 --- a/test/faker/tv_shows/test_simpsons.rb +++ b/test/faker/tv_shows/test_simpsons.rb @@ -9,27 +9,27 @@ def setup end def test_characters - 10.times { assert @tester.character.match(/[\w]+/) } + 10.times { assert @tester.character.match(/\w+/) } end def test_locations - 10.times { assert @tester.location.match(/[\w]+/) } + 10.times { assert @tester.location.match(/\w+/) } end def test_quote - 10.times { assert @tester.quote.match(/[\w]+/) } + 10.times { assert @tester.quote.match(/\w+/) } end def test_episode_titles - 10.times { assert @tester.episode_title.match(/[\w]+/) } + 10.times { assert @tester.episode_title.match(/\w+/) } end def test_locales [nil, 'en', 'de'].each do |_locale_name| Faker::Config.locale = 'de' assert @tester.character.is_a? String - assert @tester.location .is_a? String - assert @tester.quote .is_a? String + assert @tester.location.is_a? String + assert @tester.quote.is_a? String end end end diff --git a/test/test_da_dk_locale.rb b/test/test_da_dk_locale.rb index 0fa9d53fed..2483e22b27 100644 --- a/test/test_da_dk_locale.rb +++ b/test/test_da_dk_locale.rb @@ -21,8 +21,8 @@ def test_da_dk_address_methods assert Faker::Address.state.is_a? String assert Faker::Address.secondary_address.is_a? String assert Faker::Address.street_address.is_a? String - assert_match(/[\d]{4}$/, Faker::Address.postcode) - assert_match(/[\d]{1,3}$/, Faker::Address.building_number) + assert_match(/\d{4}$/, Faker::Address.postcode) + assert_match(/\d{1,3}$/, Faker::Address.building_number) assert_equal 'Danmark', Faker::Address.default_country end diff --git a/test/test_en_ind_locale.rb b/test/test_en_ind_locale.rb index 2643a98906..577b6afdb1 100644 --- a/test/test_en_ind_locale.rb +++ b/test/test_en_ind_locale.rb @@ -16,7 +16,7 @@ def test_en_ind_address_methods assert Faker::Address.state.is_a? String assert Faker::Address.state_abbr.is_a? String assert Faker::Address.default_country.is_a? String - assert_match(/[\d]{6}$/, Faker::Address.postcode) + assert_match(/\d{6}$/, Faker::Address.postcode) assert_match(/(\w+\.? ?){2,3}/, Faker::Address.city) end diff --git a/test/test_en_locale.rb b/test/test_en_locale.rb index c001e64ed3..cf48076ef0 100644 --- a/test/test_en_locale.rb +++ b/test/test_en_locale.rb @@ -17,7 +17,7 @@ def test_us_states_only_include_states end def test_us_zip_codes - expected = /\d{5}(\-\d{4})?/ + expected = /\d{5}(-\d{4})?/ assert_match(expected, Faker::Address.zip_code) end diff --git a/test/test_fi_locale.rb b/test/test_fi_locale.rb index a72b0a3287..5f03f304fe 100644 --- a/test/test_fi_locale.rb +++ b/test/test_fi_locale.rb @@ -20,8 +20,8 @@ def test_fi_address_methods assert Faker::Address.street_name.is_a? String assert Faker::Address.street_address.is_a? String assert Faker::Address.state.is_a? String - assert_match(/^[\d]{1,3}$/, Faker::Address.building_number) - assert_match(/^[\d]{5}$/, Faker::Address.postcode) + assert_match(/^\d{1,3}$/, Faker::Address.building_number) + assert_match(/^\d{5}$/, Faker::Address.postcode) assert_equal('Suomi', Faker::Address.default_country) end diff --git a/test/test_fr_locale.rb b/test/test_fr_locale.rb index e4de74289d..dbcb6341a1 100644 --- a/test/test_fr_locale.rb +++ b/test/test_fr_locale.rb @@ -25,9 +25,9 @@ def test_fr_address_methods assert Faker::Address.street_address.is_a? String assert Faker::Address.default_country.is_a? String assert Faker::Address.full_address.is_a? String - assert_match(/^[\d]{5}$/, Faker::Address.postcode) + assert_match(/^\d{5}$/, Faker::Address.postcode) assert_match(/^\d+$/, Faker::Address.building_number) - full_address_regex = /(([-a-zA-ZéÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ'.]*\s)\d*(\s[-a-zA-ZéÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ']*)*,)*\d*(\s[-a-zA-ZéÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ']*)+,\s([\d]{5})\s[-a-zA-ZéÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ']+/ + full_address_regex = /(([-a-zA-ZéÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ'.]*\s)\d*(\s[-a-zA-ZéÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ']*)*,)*\d*(\s[-a-zA-ZéÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ']*)+,\s(\d{5})\s[-a-zA-ZéÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ']+/ assert_match(full_address_regex, Faker::Address.full_address) assert_equal('France', Faker::Address.default_country) end @@ -48,10 +48,10 @@ def test_fr_color_methods end def test_fr_compass_methods - direction_pattern = /^\w+(\-\w+){0,2}$/ + direction_pattern = /^\w+(-\w+){0,2}$/ cardinal_pattern = /^\w+$/ - ordinal_pattern = /^\w+(\-\w+){1}$/ - half_wind_patern = /^\w+(\-\w+){2}$/ + ordinal_pattern = /^\w+(-\w+){1}$/ + half_wind_patern = /^\w+(-\w+){2}$/ letter_pattern = /^[NEOS]{1,3}$/ assert_match(direction_pattern, Faker::Compass.direction) diff --git a/test/test_helper.rb b/test/test_helper.rb index 39bd65ce9d..f5caace13a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -14,7 +14,7 @@ require 'yaml' YAML::ENGINE.yamler = 'psych' if defined? YAML::ENGINE -require File.expand_path(File.dirname(__FILE__) + '/../lib/faker') +require File.expand_path("#{File.dirname(__FILE__)}/../lib/faker") # deterministically_verify executes the test provided in the block successive # times with the same deterministic_random seed. @@ -28,13 +28,13 @@ # assert subject.match(/(bo(_|\.)peep|peep(_|\.)bo)/) # end # -def deterministically_verify(subject_proc, depth: 2, random: nil) +def deterministically_verify(subject_proc, depth: 2, random: nil, &block) raise 'need block' unless block_given? # rubocop:disable Style/MultilineBlockChain depth.times.inject([]) do |results, _index| Faker::Config.random = random || Random.new(42) - results << subject_proc.call.freeze.tap { |s| yield(s) } + results << subject_proc.call.freeze.tap(&block) end.repeated_combination(2) { |(first, second)| assert_equal first, second } # rubocop:enable Style/MultilineBlockChain end diff --git a/test/test_locale.rb b/test/test_locale.rb index a55de7649b..102f7d7f02 100644 --- a/test/test_locale.rb +++ b/test/test_locale.rb @@ -17,7 +17,7 @@ def test_locale_separate_from_i18n assert Faker::PhoneNumber.phone_number.match(/\(0\d+\) \d+|\d+-\d+/) assert Faker::Address.street_name.match(//) Faker::Config.locale = :ru - assert Faker::Internet.domain_name.match(/([\da-z\.-]+)\.([a-z\.]{2,6})/) + assert Faker::Internet.domain_name.match(/([\da-z.-]+)\.([a-z.]{2,6})/) end def test_configured_locale_translation diff --git a/test/test_no_no_locale.rb b/test/test_no_no_locale.rb index b41ca68171..4400977d37 100644 --- a/test/test_no_no_locale.rb +++ b/test/test_no_no_locale.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb') +require File.expand_path("#{File.dirname(__FILE__)}/test_helper.rb") class TestNoNOLocale < Test::Unit::TestCase def setup diff --git a/test/test_pt_br_locale.rb b/test/test_pt_br_locale.rb index 29544374ea..6c999134c6 100644 --- a/test/test_pt_br_locale.rb +++ b/test/test_pt_br_locale.rb @@ -25,10 +25,10 @@ def test_pt_br_address_methods assert Faker::Address.street_suffix.is_a? String assert Faker::Address.secondary_address.is_a? String - assert Faker::Address.secondary_address.match(/^[a-zA-Z\.]+\s[0-9]+$/) + assert Faker::Address.secondary_address.match(/^[a-zA-Z.]+\s[0-9]+$/) assert Faker::Address.postcode.is_a? String - assert Faker::Address.postcode.match(/^[0-9]{5}\-[0-9]{3}$/) + assert Faker::Address.postcode.match(/^[0-9]{5}-[0-9]{3}$/) assert Faker::Address.state.is_a? String assert Faker::Address.city.is_a? String @@ -129,10 +129,10 @@ def test_pt_br_university_methods def test_pt_br_vehicle_methods assert Faker::Vehicle.license_plate.is_a? String - assert Faker::Vehicle.license_plate.match(/(^[A-Z]{3}\-[0-9]{4})|([A-Z]{3}[0-9]{1}[A-Z][0-9]{2})|([A-Z]{3}[0-9]{2}[A-Z][0-9])/) + assert Faker::Vehicle.license_plate.match(/(^[A-Z]{3}-[0-9]{4})|([A-Z]{3}[0-9]{1}[A-Z][0-9]{2})|([A-Z]{3}[0-9]{2}[A-Z][0-9])/) assert Faker::Vehicle.license_plate(state_abbreviation: 'RJ').is_a? String - assert Faker::Vehicle.license_plate(state_abbreviation: 'RJ').match(/^[A-Z]{3}\-[0-9]{4}/) + assert Faker::Vehicle.license_plate(state_abbreviation: 'RJ').match(/^[A-Z]{3}-[0-9]{4}/) end def test_pt_br_gender_methods diff --git a/test/test_pt_locale.rb b/test/test_pt_locale.rb index 80a05ab6fb..65b8614d93 100644 --- a/test/test_pt_locale.rb +++ b/test/test_pt_locale.rb @@ -12,9 +12,9 @@ def teardown end def test_pt_address_methods - assert_match(/^[[:word:]]+[\.]? \d{1,3}$/, Faker::Address.secondary_address) - assert_match(/^[\d]{3,5}$/, Faker::Address.building_number) - assert_match(/^[\d]{4}$/, Faker::Address.postcode) + assert_match(/^[[:word:]]+[.]? \d{1,3}$/, Faker::Address.secondary_address) + assert_match(/^\d{3,5}$/, Faker::Address.building_number) + assert_match(/^\d{4}$/, Faker::Address.postcode) assert Faker::Address.country_code.is_a? String assert Faker::Address.street_suffix.is_a? String @@ -39,6 +39,6 @@ def test_pt_name_methods end def test_pt_phone_number - assert_match(/^(\+351)?[\(\)\d\s\-]+$/, Faker::PhoneNumber.phone_number) + assert_match(/^(\+351)?[()\d\s\-]+$/, Faker::PhoneNumber.phone_number) end end diff --git a/test/test_sv_locale.rb b/test/test_sv_locale.rb index 5eeb7764a6..5d03a6ee9b 100644 --- a/test/test_sv_locale.rb +++ b/test/test_sv_locale.rb @@ -12,7 +12,7 @@ def teardown end def test_address_methods - assert Faker::Address.postcode.match(/^[\d]{5}$/) + assert Faker::Address.postcode.match(/^\d{5}$/) assert Faker::Address.city_suffix.is_a? String assert Faker::Address.city_prefix.is_a? String assert Faker::Address.country.is_a? String