diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml
index 110f681399..cb9c0114d7 100644
--- a/.github/workflows/ruby.yml
+++ b/.github/workflows/ruby.yml
@@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
- ruby-version: '2.7'
+ ruby-version: '3.0'
- name: Install dependencies
run: bundle install
@@ -38,7 +38,6 @@ jobs:
fail-fast: false # don't fail all matrix builds if one fails
matrix:
ruby:
- - '2.7'
- '3.0'
- '3.1'
- '3.2'
@@ -55,18 +54,5 @@ jobs:
- name: Install dependencies
run: bundle install
- - name: Setup Code Climate test-reporter
- run: |
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
-
- name: Run tests
run: bundle exec rake test
-
- - name: Publish code coverage
- env:
- CC_TEST_REPORTER_ID: c9b8356df2031a5a72462555fe898245cf24d83c7bb82c40ddb5c6c6976c4319
- run: |
- export GIT_BRANCH="${GITHUB_REF/refs\/heads\//}"
- ./cc-test-reporter after-build -r $CC_TEST_REPORTER_ID
diff --git a/.rubocop.yml b/.rubocop.yml
index 2973cfe4cb..20059e21bb 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -3,7 +3,7 @@ require:
- rubocop-rake
AllCops:
- TargetRubyVersion: 2.7
+ TargetRubyVersion: 3.0
NewCops: enable
# Suppress noise for obvious operator precedence.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 43a4b1eec9..2903f7b12c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,62 @@
# Changelog
+## [v3.5.1](https://github.com/faker-ruby/faker/tree/v3.5.1) (2024-10-18)
+
+Happy October! 🎃
+
+This version **drops support for Ruby < 3.0**. We only support one EOL Ruby version at a time. Please upgrade to Ruby 3.0 to update to this and future versions of faker-ruby.
+
+Besides that, this version removes deprecated generators, fixes some bugs, and adds a Security Policy.
+
+Thanks to all contributors!
+
+## Breaking Changes
+* Drop support for Ruby 2.7 by @tatheerf02 in https://github.com/faker-ruby/faker/pull/3006
+* Removes deprecated generators by @stefannibrasil in https://github.com/faker-ruby/faker/pull/3014
+
+The following deprecated generators are being removed. Please use the new generators:
+
+
+| Deprecated | New |
+| -------- | ------- |
+| Faker::TvShows::TheFreshPrinceOfBelAir.celebrity | Faker::TvShows::TheFreshPrinceOfBelAir.actor |
+| Faker::TvShows::Buffy.celebrity | Faker::TvShows::Buffy.actor |
+| Faker::TvShows::DrWho.villian | Faker::TvShows::DrWho.villain |
+| Faker::Games::HeroesOfTheStorm.class | Faker::Games::HeroesOfTheStorm.class_name |
+| Faker::JapaneseMedia::FmaBrotherhood | Faker::JapaneseMedia::FullmetalAlchemistBrotherhood |
+| Faker::Show | Faker::Theater |
+| Faker::Australia | Faker::Locations::Australia |
+| Faker::IDNumber | Faker::IdNumber |
+
+### Improvements & Bug fixes
+* Fix typos by @tagliala in https://github.com/faker-ruby/faker/pull/2982
+* Fix benchmark:all_methods task by excluding Faker::Deprecator module from benchmark target by @amatsuda in https://github.com/faker-ruby/faker/pull/2988
+* Add Brazilian Portuguese translations for `Faker::Subscription` by @murichristopher in https://github.com/faker-ruby/faker/pull/2960
+* Deprecator improvements by @stefannibrasil in https://github.com/faker-ruby/faker/pull/2997
+* Faker::Alphanumeric.alphanumeric determinism fix by @admtnnr in https://github.com/faker-ruby/faker/pull/2996
+* Remove CodeClimate badges by @tagliala in https://github.com/faker-ruby/faker/pull/3003
+* Update Company.logo example url by @dirschn in https://github.com/faker-ruby/faker/pull/3007
+* fix(music.band): removes leading whitespace by @JeremasPosta in https://github.com/faker-ruby/faker/pull/3015
+* Create SECURITY.md by @stefannibrasil in https://github.com/faker-ruby/faker/pull/3016
+
+### Update local dependencies
+* Bump i18n from 1.14.5 to 1.14.6 by @dependabot in https://github.com/faker-ruby/faker/pull/3005
+* Bump minitest from 5.24.1 to 5.25.0 by @dependabot in https://github.com/faker-ruby/faker/pull/2991
+* Bump rubocop-minitest from 0.35.1 to 0.36.0 by @dependabot in https://github.com/faker-ruby/faker/pull/2999
+* Bump yard from 0.9.36 to 0.9.37 by @dependabot in https://github.com/faker-ruby/faker/pull/3000
+* Bump rubocop from 1.65.1 to 1.66.1 by @dependabot in https://github.com/faker-ruby/faker/pull/3001
+
+## New Contributors
+* @murichristopher made their first contribution in https://github.com/faker-ruby/faker/pull/2960
+* @admtnnr made their first contribution in https://github.com/faker-ruby/faker/pull/2996
+* @dirschn made their first contribution in https://github.com/faker-ruby/faker/pull/3007
+* @tatheerf02 made their first contribution in https://github.com/faker-ruby/faker/pull/3006
+* @JeremasPosta made their first contribution in https://github.com/faker-ruby/faker/pull/3015
+
+**Full Changelog**: https://github.com/faker-ruby/faker/compare/v3.4.2...v3.5.1
+
+--------------------------------------
+
## [v3.4.2](https://github.com/faker-ruby/faker/tree/v3.4.2) (2024-07-16)
Happy July with a new faker-ruby release.
@@ -2549,7 +2606,7 @@ Fix lib/faker/version.rb
- Fixed typo in dutch translation [\#679](https://github.com/stympy/faker/pull/679) ([nschmoller](https://github.com/nschmoller))
- Add pokemon [\#677](https://github.com/stympy/faker/pull/677) ([bakunyo](https://github.com/bakunyo))
- Food [\#672](https://github.com/stympy/faker/pull/672) ([martymclaugh](https://github.com/martymclaugh))
-- Added charcaters and houses data for game of thrones in en.yml [\#670](https://github.com/stympy/faker/pull/670) ([vamsipavanmahesh](https://github.com/vamsipavanmahesh))
+- Added characters and houses data for game of thrones in en.yml [\#670](https://github.com/stympy/faker/pull/670) ([vamsipavanmahesh](https://github.com/vamsipavanmahesh))
- add Faker::Commerce.promotion\_code [\#669](https://github.com/stympy/faker/pull/669) ([jGRUBBS](https://github.com/jGRUBBS))
- Eliminate and prevent leading and trailing white space [\#665](https://github.com/stympy/faker/pull/665) ([retroGiant89](https://github.com/retroGiant89))
- Fix for memory overflow error Issue: \#478 [\#664](https://github.com/stympy/faker/pull/664) ([anuj-verma](https://github.com/anuj-verma))
diff --git a/Gemfile b/Gemfile
index 1dc8f5ac5e..9dc1045789 100644
--- a/Gemfile
+++ b/Gemfile
@@ -6,13 +6,13 @@ source 'https://rubygems.org'
gemspec
gem 'benchmark'
-gem 'minitest', '5.24.1'
+gem 'minitest', '5.25.1'
gem 'pry', '0.14.2'
gem 'rake', '13.2.1'
-gem 'rubocop', '1.65.0'
-gem 'rubocop-minitest', '0.35.1'
+gem 'rubocop', '1.67.0'
+gem 'rubocop-minitest', '0.36.0'
gem 'rubocop-rake', '0.6.0'
gem 'simplecov', '0.22.0'
gem 'test-unit', '3.6.2'
gem 'timecop', '0.9.10'
-gem 'yard', '0.9.36'
+gem 'yard', '0.9.37'
diff --git a/Gemfile.lock b/Gemfile.lock
index 6b69c581d5..6eb3c97d69 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- faker (3.4.2)
+ faker (3.5.1)
i18n (>= 1.8.11, < 2)
GEM
@@ -10,42 +10,39 @@ GEM
ast (2.4.2)
benchmark (0.3.0)
coderay (1.1.3)
- concurrent-ruby (1.2.3)
+ concurrent-ruby (1.3.4)
docile (1.4.0)
- i18n (1.14.5)
+ i18n (1.14.6)
concurrent-ruby (~> 1.0)
json (2.7.2)
language_server-protocol (3.17.0.3)
method_source (1.0.0)
- minitest (5.24.1)
- parallel (1.25.1)
- parser (3.3.4.0)
+ minitest (5.25.1)
+ parallel (1.26.3)
+ parser (3.3.5.0)
ast (~> 2.4.1)
racc
power_assert (2.0.3)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
- racc (1.8.0)
+ racc (1.8.1)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.9.2)
- rexml (3.3.1)
- strscan
- rubocop (1.65.0)
+ rubocop (1.67.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
- rexml (>= 3.2.5, < 4.0)
- rubocop-ast (>= 1.31.1, < 2.0)
+ rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
- rubocop-ast (1.31.3)
+ rubocop-ast (1.32.3)
parser (>= 3.3.1.0)
- rubocop-minitest (0.35.1)
+ rubocop-minitest (0.36.0)
rubocop (>= 1.61, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rake (0.6.0)
@@ -57,12 +54,11 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
- strscan (3.1.0)
test-unit (3.6.2)
power_assert
timecop (0.9.10)
- unicode-display_width (2.5.0)
- yard (0.9.36)
+ unicode-display_width (2.6.0)
+ yard (0.9.37)
PLATFORMS
arm64-darwin-22
@@ -71,16 +67,16 @@ PLATFORMS
DEPENDENCIES
benchmark
faker!
- minitest (= 5.24.1)
+ minitest (= 5.25.1)
pry (= 0.14.2)
rake (= 13.2.1)
- rubocop (= 1.65.0)
- rubocop-minitest (= 0.35.1)
+ rubocop (= 1.67.0)
+ rubocop-minitest (= 0.36.0)
rubocop-rake (= 0.6.0)
simplecov (= 0.22.0)
test-unit (= 3.6.2)
timecop (= 0.9.10)
- yard (= 0.9.36)
+ yard (= 0.9.37)
BUNDLED WITH
2.4.22
diff --git a/MAINTAINING.md b/MAINTAINING.md
index f0c5504e6c..23672914f9 100644
--- a/MAINTAINING.md
+++ b/MAINTAINING.md
@@ -13,7 +13,7 @@ If you're reviewing a PR, ask yourself:
## Managing libraries dependencies EOL
As a guideline for Ruby's End of Life (EOL) versions, a good heuristic (that's not too hard on maintainers) is to keep support for 1 EOL version.
-In other words, once Ruby 3.0 is EOL, drop support for 2.7.
+In other words, once Ruby 3.1 is EOL, drop support for 3.0.
## Security
diff --git a/README.md b/README.md
index e6356c0b2a..c0cb756e40 100644
--- a/README.md
+++ b/README.md
@@ -4,8 +4,6 @@
[](https://github.com/faker-ruby/faker/actions?query=workflow%3ATests)
[](https://badge.fury.io/rb/faker)
[](https://inch-ci.org/github/faker-ruby/faker)
-[](https://codeclimate.com/github/stympy/faker/test_coverage)
-[](https://codeclimate.com/github/stympy/faker/maintainability)
Faker is a port of [Perl's Data::Faker library](https://metacpan.org/pod/Data::Faker).
It's a library for generating fake data such as names, addresses, and phone numbers.
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 0000000000..ffee60031a
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,17 @@
+## Security Policy
+
+### Supported Versions
+
+Only the the latest version of this project is supported at a given time. If you find a security issue with an older version, please try updating to the latest version first.
+
+If for some reason you can't update to the latest version, please let us know your reasons so that we can have a better understanding of your situation.
+
+## Reporting a Vulnerability
+
+The faker-ruby core contributors take security very seriously and investigate all reported vulnerabilities.
+
+If you would like to report a vulnerablity or have a security concern regarding faker-ruby, please report it by contacting the current security coordinators (Stefanni Brasil stefanni@hexdevs.com and Thiago Araujo thiago@hexdevs.com).
+
+The information you share with the faker-ruby core contributors as part of this process will be kept confidential within the team, unless or until we need to share information upstream with our dependent libraries' core teams, at which point we will notify you.
+
+If a vulnerability is first reported by you, we will credit you with the discovery in the public disclosure.
diff --git a/doc/default/company.md b/doc/default/company.md
index 5e0774c65d..3cf92b16e4 100644
--- a/doc/default/company.md
+++ b/doc/default/company.md
@@ -22,7 +22,7 @@ Faker::Company.ein #=> "34-8488813"
Faker::Company.duns_number #=> "08-341-3736"
# Get a random company logo url in PNG format.
-Faker::Company.logo #=> "https://pigment.github.com/fake-logos/logos/medium/color/5.png"
+Faker::Company.logo #=> "https://pigment.github.io/fake-logos/logos/medium/color/5.png"
Faker::Company.type #=> "Privately Held"
diff --git a/faker.gemspec b/faker.gemspec
index 8f7b324918..b13fed9e55 100644
--- a/faker.gemspec
+++ b/faker.gemspec
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
spec.bindir = 'bin'
spec.executables = ['faker']
spec.require_paths = ['lib']
- spec.required_ruby_version = '>= 2.7'
+ spec.required_ruby_version = '>= 3.0'
spec.metadata['changelog_uri'] = 'https://github.com/faker-ruby/faker/blob/main/CHANGELOG.md'
spec.metadata['source_code_uri'] = 'https://github.com/faker-ruby/faker'
diff --git a/lib/faker.rb b/lib/faker.rb
index ad286e67f0..5e5bb5924e 100644
--- a/lib/faker.rb
+++ b/lib/faker.rb
@@ -5,7 +5,7 @@
require 'psych'
require 'i18n'
-Dir.glob(File.join(mydir, 'helpers', '*.rb')).sort.each { |file| require file }
+Dir.glob(File.join(mydir, 'helpers', '*.rb')).each { |file| require file }
I18n.load_path += Dir[File.join(mydir, 'locales', '**/*.yml')]
@@ -107,7 +107,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
@@ -249,6 +249,10 @@ def shuffle(list)
list.shuffle(random: Faker::Config.random)
end
+ def shuffle!(list)
+ list.shuffle!(random: Faker::Config.random)
+ end
+
def rand(max = nil)
if max.nil?
Faker::Config.random.rand
@@ -271,4 +275,4 @@ def disable_enforce_available_locales
end
# require faker objects
-Dir.glob(File.join(mydir, 'faker', '/**/*.rb')).sort.each { |file| require file }
+Dir.glob(File.join(mydir, 'faker', '/**/*.rb')).each { |file| require file }
diff --git a/lib/faker/default/alphanumeric.rb b/lib/faker/default/alphanumeric.rb
index 83caf4ec23..7ddaa5ff62 100644
--- a/lib/faker/default/alphanumeric.rb
+++ b/lib/faker/default/alphanumeric.rb
@@ -60,7 +60,7 @@ def alphanumeric(number: 32, min_alpha: 0, min_numeric: 0)
randoms = Array.new(random_count) { sample(ALPHANUMS) }
combined = alphas + numbers + randoms
- combined.shuffle.join
+ shuffle!(combined).join
end
end
end
diff --git a/lib/faker/default/id_number.rb b/lib/faker/default/id_number.rb
index b02c17b77e..6fc2248f01 100644
--- a/lib/faker/default/id_number.rb
+++ b/lib/faker/default/id_number.rb
@@ -12,7 +12,7 @@ class IdNumber < Base
].freeze
ZA_RACE_DIGIT = '8'
ZA_CITIZENSHIP_DIGITS = %w[0 1].freeze
- BRAZILIAN_ID_FORMAT = /(\d{1,2})(\d{3})(\d{3})([\dX])/.freeze
+ BRAZILIAN_ID_FORMAT = /(\d{1,2})(\d{3})(\d{3})([\dX])/
BRAZILIAN_ID_FROM = 10_000_000
BRAZILIAN_ID_TO = 99_999_999
@@ -421,7 +421,4 @@ def _translate(key)
end
end
end
-
- include Faker::Deprecator
- deprecate_generator('IDNumber', IdNumber)
end
diff --git a/lib/faker/default/invoice.rb b/lib/faker/default/invoice.rb
index 46d47c897f..2913ce767b 100644
--- a/lib/faker/default/invoice.rb
+++ b/lib/faker/default/invoice.rb
@@ -22,7 +22,7 @@ def amount_between(from: 0, to: 0)
end
##
- # Produces a random valid reference accoring to the International bank slip reference https://en.wikipedia.org/wiki/Creditor_Reference
+ # Produces a random valid reference according to the International bank slip reference https://en.wikipedia.org/wiki/Creditor_Reference
#
# @param ref [String] Specifies reference base.
# @return [String]
diff --git a/lib/faker/default/theater.rb b/lib/faker/default/theater.rb
index b9e8af3db5..03cd237cba 100644
--- a/lib/faker/default/theater.rb
+++ b/lib/faker/default/theater.rb
@@ -46,7 +46,4 @@ def play
end
end
end
-
- include Faker::Deprecator
- deprecate_generator('Show', Theater)
end
diff --git a/lib/faker/games/heroes_of_the_storm.rb b/lib/faker/games/heroes_of_the_storm.rb
index 2557b3e9bc..89e7955664 100644
--- a/lib/faker/games/heroes_of_the_storm.rb
+++ b/lib/faker/games/heroes_of_the_storm.rb
@@ -17,17 +17,6 @@ def battleground
fetch('heroes_of_the_storm.battlegrounds')
end
- ##
- # This method is deprecated. The implementation will be removed in a near future release.
- # Use `HeroesOfTheStorm.class_name` instead.
- #
- # @deprecated Use {#class_name} instead.
- def class
- warn '`HeroesOfTheStorm.class` is deprecated. Use `HeroesOfTheStorm.class_name` instead.'
-
- super
- end
-
##
# Produces a class name from Heroes of the Storm.
#
diff --git a/lib/faker/japanese_media/fullmetal_alchemist_brotherhood.rb b/lib/faker/japanese_media/fullmetal_alchemist_brotherhood.rb
index 493cdf51a0..c112eb7255 100644
--- a/lib/faker/japanese_media/fullmetal_alchemist_brotherhood.rb
+++ b/lib/faker/japanese_media/fullmetal_alchemist_brotherhood.rb
@@ -44,8 +44,5 @@ def country
end
end
end
-
- include Faker::Deprecator
- deprecate_generator('FmaBrotherhood', FullmetalAlchemistBrotherhood)
end
end
diff --git a/lib/faker/locations/australia.rb b/lib/faker/locations/australia.rb
index e3696d5fa6..a0358b93a5 100644
--- a/lib/faker/locations/australia.rb
+++ b/lib/faker/locations/australia.rb
@@ -46,7 +46,4 @@ def state
end
end
end
-
- include Deprecator
- deprecate_generator('Australia', Locations::Australia)
end
diff --git a/lib/faker/movies/star_wars.rb b/lib/faker/movies/star_wars.rb
index 279870eb58..a5e26f7695 100644
--- a/lib/faker/movies/star_wars.rb
+++ b/lib/faker/movies/star_wars.rb
@@ -204,7 +204,7 @@ def characters
# @example
# Faker::Movies::StarWars.droids
#
- # @faker.versionn 1.6.2
+ # @faker.version 1.6.2
def droids
fetch_all('star_wars.droids')
end
diff --git a/lib/faker/tv_shows/buffy.rb b/lib/faker/tv_shows/buffy.rb
index 80d21e6568..1848f18194 100644
--- a/lib/faker/tv_shows/buffy.rb
+++ b/lib/faker/tv_shows/buffy.rb
@@ -45,19 +45,6 @@ def actor
fetch('buffy.actors')
end
- ##
- # Produces a actor from Buffy the Vampire Slayer.
- #
- # @return [String]
- #
- # @example
- # Faker::TvShows::Buffy.celebrity #=> "John Ritter"
- #
- # @deprecated Use the `actor` method instead.
- #
- # @faker.version 1.9.2
- alias celebrity actor
-
##
# Produces a big bad from Buffy the Vampire Slayer.
#
diff --git a/lib/faker/tv_shows/dr_who.rb b/lib/faker/tv_shows/dr_who.rb
index 9951ff3106..b1b9c34bb0 100644
--- a/lib/faker/tv_shows/dr_who.rb
+++ b/lib/faker/tv_shows/dr_who.rb
@@ -84,19 +84,6 @@ def villain
fetch('dr_who.villains')
end
- ##
- # Produces a villain from Doctor Who.
- #
- # @return [String]
- #
- # @example
- # Faker::TvShows::DrWho.villian #=> "The Master"
- #
- # @deprecated Use the correctly-spelled `villain` method instead.
- #
- # @faker.version 1.8.0
- alias villian villain
-
##
# Produces a species from Doctor Who.
#
diff --git a/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb b/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb
index bead810c33..cf13bf7f51 100644
--- a/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb
+++ b/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb
@@ -32,19 +32,6 @@ def actor
fetch('the_fresh_prince_of_bel_air.actors')
end
- ##
- # Produces a actor from The Fresh Prince of Bel-Air.
- #
- # @return [String]
- #
- # @example
- # Faker::TvShows::TheFreshPrinceOfBelAir.celebrity #=> "Quincy Jones"
- #
- # @deprecated Use the `actor` method instead.
- #
- # @faker.version 1.8.3
- alias celebrity actor
-
##
# Produces a quote from The Fresh Prince of Bel-Air.
#
diff --git a/lib/faker/version.rb b/lib/faker/version.rb
index c172af5b45..6676ee0e12 100644
--- a/lib/faker/version.rb
+++ b/lib/faker/version.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
module Faker # :nodoc:
- VERSION = '3.4.2'
+ VERSION = '3.5.1'
end
diff --git a/lib/helpers/deprecator.rb b/lib/helpers/deprecator.rb
index 8cf7532ba8..fd46ac5849 100644
--- a/lib/helpers/deprecator.rb
+++ b/lib/helpers/deprecator.rb
@@ -1,17 +1,70 @@
# frozen_string_literal: true
# Based on Rails ActiveSupport Deprecator
-# https://github.com/rails/rails/blob/6f0d1ad14b92b9f5906e44740fce8b4f1c7075dc/activesupport/lib/active_support/deprecation/constant_accessor.rb
+# https://github.com/rails/rails/blob/main/activesupport/lib/active_support/deprecation/constant_accessor.rb
# rubocop:disable Style/ClassVars
module Faker
+ # Provides a way to rename generators, including their namespaces, with a deprecation cycle in which
+ # both the old and new names work, but using the old one prints a deprecation message.
+ #
+ # Deprecator provides a deprecate_generator method to be used when
+ # renaming a generator. For example, let's say we want to change the following Generator's
+ # name to Faker::NewGenerator:
+ #
+ # module Faker
+ # class Generator
+ # def self.generate
+ # "be kind"
+ # end
+ # end
+ # end
+ #
+ # To rename it, you need to do the update the name and declare the deprecation by
+ # including the Deprecator module and using the deprecate_generator method:
+ #
+ # module Faker
+ # class NewGenerator
+ # def self.generate
+ # "be kind"
+ # end
+ # end
+ #
+ # include Deprecator
+ # deprecate_generator('DeprecatedGenerator', NewGenerator)
+ # end
+ #
+ # The first argument is a constant name (no colons) as a string. It is the name of
+ # the constant you want to deprecate.
+ #
+ # The second argument is the constant path of the replacement (no colons) as a constant.
+ #
+ # For this to work, a +const_missing+ hook is installed. When users
+ # reference the deprecated constant, the callback prints the
+ # message and constantizes the replacement.
+ #
+ # With that in place, references to Faker::Deprecator still work, they
+ # evaluate to Faker::NewGenerator now, and trigger a deprecation warning:
+ #
+ # Faker::Generator.generate
+ # # DEPRECATION WARNING: Faker::Generator is deprecated. Use Faker::NewGenerator instead
+ # # "be kind"
+ #
+ # For testing the deprecations, we provide assert_deprecated
+ # and assert_not_deprecated matchers.
+ #
+ # There's also a Faker::Deprecator.skip_warning helper to silence
+ # the deprecation messages in the *test* output. Use it for generators that have lots of tests
+ # to avoid too many noise when running the tests.
module Deprecator
def self.included(base)
extension = Module.new do
def const_missing(missing_const_name)
if class_variable_defined?(:@@_deprecated_constants) && (replacement = class_variable_get(:@@_deprecated_constants)[missing_const_name.to_s])
unless Faker::Deprecator.skip_warning?
- $stdout.puts("DEPRECATION WARNING: #{name}::#{replacement[:old_generator]} is deprecated. Use #{replacement[:new_constant]} instead.")
+ deprecated_message = "#{name}::#{replacement[:old_generator]} is deprecated."
+ replacement_message = "Use #{replacement[:new_constant]} instead."
+ $stdout.puts("DEPRECATION WARNING: #{deprecated_message} #{replacement_message}")
end
return replacement[:new_constant]
@@ -22,13 +75,25 @@ def const_missing(missing_const_name)
def deprecate_generator(old_generator_name, new_generator_constant)
class_variable_set(:@@_deprecated_constants, {}) unless class_variable_defined?(:@@_deprecated_constants)
- class_variable_get(:@@_deprecated_constants)[old_generator_name] = { new_constant: new_generator_constant, old_generator: old_generator_name }
+ class_variable_get(:@@_deprecated_constants)[old_generator_name] = {
+ new_constant: new_generator_constant,
+ old_generator: old_generator_name
+ }
end
end
base.singleton_class.prepend extension
end
+ # Silence deprecation warnings within the block.
+ #
+ # Faker::Generator.generate
+ # # => DEPRECATION WARNING: Faker::Generator is deprecated. Use Faker::NewGenerator instead.
+ #
+ # Faker::Deprecator.skip_warning do
+ # Faker::Generator.generate
+ # end
+ # # => nil
def self.skip_warning
original = Faker::Deprecator.skip
Faker::Deprecator.skip = true
diff --git a/lib/locales/en/music.yml b/lib/locales/en/music.yml
index cf47228581..58cc6ac2fd 100644
--- a/lib/locales/en/music.yml
+++ b/lib/locales/en/music.yml
@@ -32,10 +32,8 @@ en:
- Arctic Monkeys
- B.B. King
- Bauhaus
- - The Beatles
- Beck
- Billy Idol
- - The Birthday Party
- Björk
- Blinker The Star
- Blondie
@@ -54,16 +52,11 @@ en:
- Chris Isaak
- Chrissie Hynde
- Chuck Berry
- - The Clash
- Cliff Richard (and the Shadows)
- Coldplay
- Cootie Williams
- Cortinas
- - " The"
- - The Cramps
- - The Cranberries
- Cream
- - The Cure
- David Bowie
- David Gilmour
- Deepest Blue
@@ -77,7 +70,6 @@ en:
- Elvis Costello
- Elvis Presley
- Eric Clapton
- - The Faces
- Fats Domino
- Flaming Lips
- Florence and the Machine
@@ -94,7 +86,6 @@ en:
- Hugh Masekela
- Ian Dury
- Iggy Pop
- - The Jam
- James Brown
- Jeff Beck
- Jeff Buckley
@@ -111,14 +102,11 @@ en:
- Kate Bush
- Keith Moon
- Keith Richards
- - The Kinks
- Kiss
- - The La's
- Led Zeppelin
- Lenny Kravitz
- Leonard Cohen
- Liam Gallagher
- - The Libertines
- Madness
- Madonna
- Manic Street Preachers
@@ -126,7 +114,6 @@ en:
- Marianne Faithfull
- Marilyn Manson
- Maroon 5
- - The Mars Volta
- Max Roach
- Michael Jackson
- Miles Davis
@@ -145,6 +132,7 @@ en:
- Oasis
- Offspring
- Ozzy Osbourne
+ - PJ Harvey
- Paramore
- Pat Metheny
- Patti Smith
@@ -154,21 +142,16 @@ en:
- Phil Collins
- Phish
- Pink Floyd
- - PJ Harvey
- - The Police
- - The Pretenders
- Primal Scream
- Prince
- Program The Dead
- Pulp
- Queen
+ - R.E.M.
- Radiohead
- - The Ramones
- Red Hot Chili Peppers
- - R.E.M.
- Rick Wright
- Rod Stewart
- - The Rolling Stones
- Rory Gallagher
- Roxy Music
- Roy Hargrove
@@ -179,15 +162,35 @@ en:
- Simply Red
- Sinead O'connor
- Siouxsie and The Banshees
- - The Slits
- - The Smiths
- Sonic Youth
- - The Specials
- Squeeze
- Status Quo
- Stereophonics
- Stone Roses
- Syd Barrett
+ - The Beatles
+ - The Birthday Party
+ - The Clash
+ - The Cramps
+ - The Cranberries
+ - The Cure
+ - The Faces
+ - The Jam
+ - The Killers
+ - The Kinks
+ - The La's
+ - The Libertines
+ - The Mars Volta
+ - The Police
+ - The Pretenders
+ - The Ramones
+ - The Rolling Stones
+ - The Slits
+ - The Smiths
+ - The Specials
+ - The Undertones
+ - The Who
+ - The Yardbirds
- Thelonius Monk
- Thin Lizzy
- Thornley
@@ -196,12 +199,9 @@ en:
- Tom Robinson
- Tom Waits
- U2
- - The Undertones
- Van Morrison
- Velvet Revolver
- White Stripes
- - The Who
- - The Yardbirds
- Yumi Matsutoya
albums:
- Thriller
diff --git a/lib/locales/pt-BR.yml b/lib/locales/pt-BR.yml
index b27b16d45d..d143dcc976 100644
--- a/lib/locales/pt-BR.yml
+++ b/lib/locales/pt-BR.yml
@@ -6873,6 +6873,56 @@ pt-BR:
- "(#{PhoneNumber.area_code}) #{PhoneNumber.subscriber_number}-#{PhoneNumber.subscriber_number}"
subscriber_number:
- "####"
+ subscription:
+ plans:
+ - Teste gratuito
+ - Básico
+ - Starter
+ - Essencial
+ - Estudante
+ - Bronze
+ - Standard
+ - Prata
+ - Ouro
+ - Platinum
+ - Profissional
+ - Business
+ - Diamante
+ - Premium
+ statuses:
+ - Ativo
+ - Inativo
+ - Bloqueado
+ - Pendente
+ payment_methods:
+ - Cartão de crédito
+ - Cartão de débito
+ - Paypal
+ - Dinheiro
+ - Transferência de dinheiro
+ - Bitcoins
+ - Cheque
+ - Apple Pay
+ - Google Pay
+ - WeChat Pay
+ - Alipay
+ - Visa Checkout
+ - Pix
+ - Boleto
+ subscription_terms:
+ - Diária
+ - Semanal
+ - Mensal
+ - Anual
+ - Bienal
+ - Trienal
+ - Quinquenal
+ - VitalÃcia
+ payment_terms:
+ - Pagamento antecipado
+ - Mensal
+ - Anual
+ - Assinatura completa
cell_phone:
formats:
- "(#{PhoneNumber.area_code}) 9#{PhoneNumber.subscriber_number}-#{PhoneNumber.subscriber_number}"
diff --git a/tasks/benchmark.rake b/tasks/benchmark.rake
index ed0bea4cc4..501224402b 100644
--- a/tasks/benchmark.rake
+++ b/tasks/benchmark.rake
@@ -48,7 +48,7 @@ class BenchmarkHelper
def subclasses
Faker.constants.delete_if do |subclass|
- %i[Base Bank Books Cat Char Base58 ChileRut CLI Config Creature Date Dog DragonBall Dota ElderScrolls Fallout Games GamesHalfLife HeroesOfTheStorm Internet JapaneseMedia LeagueOfLegends Movies Myst Overwatch OnePiece Pokemon Religion Sports SwordArtOnline TvShows Time VERSION Witcher WorldOfWarcraft Zelda].include?(subclass)
+ %i[Base Bank Books Cat Char Base58 ChileRut CLI Config Creature Date Deprecator Dog DragonBall Dota ElderScrolls Fallout Games GamesHalfLife HeroesOfTheStorm Internet JapaneseMedia LeagueOfLegends Movies Myst Overwatch OnePiece Pokemon Religion Sports SwordArtOnline TvShows Time VERSION Witcher WorldOfWarcraft Zelda].include?(subclass)
end.sort
end
diff --git a/tasks/website.rake b/tasks/website.rake
deleted file mode 100644
index f7281bb5d3..0000000000
--- a/tasks/website.rake
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-desc 'Generate website files'
-task :website_generate do
- (Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
- sh %( ./script/txt2html #{txt} > #{txt.gsub(/txt$/, 'html')} )
- end
-end
-
-desc 'Upload website files to rubyforge'
-task :website_upload do
- remote_dir = '/var/www/gforge-projects/faker/'
- local_dir = 'website'
- sh %(rsync -acCv #{local_dir}/ #{ENV.fetch('USER', nil)}@rubyforge.org:#{remote_dir})
-end
-
-desc 'Generate and upload website files'
-task website: %i[website_generate website_upload publish_docs]
diff --git a/test/faker/default/test_alphanum.rb b/test/faker/default/test_alphanum.rb
index 7b4ed11fdb..bcaf856054 100644
--- a/test/faker/default/test_alphanum.rb
+++ b/test/faker/default/test_alphanum.rb
@@ -48,4 +48,12 @@ def test_alphanumeric_with_min_numeric
assert_operator numbers.compact.size, :>=, 4
end
+
+ def test_alphanumeric_with_min_alpha_and_min_numeric
+ deterministically_verify -> { @tester.alphanumeric(number: 10, min_alpha: 5, min_numeric: 5) } do |alphanum|
+ assert_equal 10, alphanum.size
+ assert_equal 5, alphanum.scan(/[[:alpha:]]/).size
+ assert_equal 5, alphanum.scan(/[[:digit:]]/).size
+ end
+ end
end
diff --git a/test/faker/default/test_faker_crypto_coin.rb b/test/faker/default/test_faker_crypto_coin.rb
index feafa6e958..aecb23621a 100644
--- a/test/faker/default/test_faker_crypto_coin.rb
+++ b/test/faker/default/test_faker_crypto_coin.rb
@@ -7,9 +7,9 @@ class TestFakerCryptoCoin < Test::Unit::TestCase
ACRONYM = 1
URL_LOGO = 2
- REGEX_COIN_NAME = /[a-zA-Z .]{3,}/.freeze
- REGEX_ACRONYM = /\w+{3,}/.freeze
- REGEX_URL_LOGO = /^https:\/\/i.imgur.com\/.......\./.freeze
+ REGEX_COIN_NAME = /[a-zA-Z .]{3,}/
+ REGEX_ACRONYM = /\w+{3,}/
+ REGEX_URL_LOGO = /^https:\/\/i.imgur.com\/.......\./
def setup
@tester = Faker::CryptoCoin
diff --git a/test/faker/default/test_faker_id_number.rb b/test/faker/default/test_faker_id_number.rb
index 6f3aecd84d..12ceff83c7 100644
--- a/test/faker/default/test_faker_id_number.rb
+++ b/test/faker/default/test_faker_id_number.rb
@@ -288,292 +288,3 @@ def assert_valid_south_african_id_number(sample)
assert Date.parse(south_african_id_number_to_date_of_birth_string(sample))
end
end
-
-class TestFakerIDNumber < Test::Unit::TestCase
- def setup
- Faker::Deprecator.skip_warning do
- @tester = Faker::IDNumber
- end
- end
-
- def test_valid_ssn
- sample = @tester.valid
-
- assert_equal(11, sample.length)
- assert_equal '-', sample[3]
- assert_equal '-', sample[6]
- assert sample[0..2].split.map { :to_i }.all? { :is_digit? }
- assert sample[4..5].split.map { :to_i }.all? { :is_digit? }
- assert sample[7..9].split.map { :to_i }.all? { :is_digit? }
- end
-
- def test_invalid_ssn
- sample = @tester.invalid
-
- assert_equal(11, sample.length)
- assert_equal '-', sample[3]
- assert_equal '-', sample[6]
- assert sample[0..2].split.map { :to_i }.all? { :is_digit? }
- assert sample[4..5].split.map { :to_i }.all? { :is_digit? }
- assert sample[7..9].split.map { :to_i }.all? { :is_digit? }
- end
-
- def test_spanish_dni
- sample = @tester.spanish_citizen_number
-
- assert_equal 10, sample.length
- assert sample[0..7].split.map { :to_i }.all? { :is_digit? }
- assert_equal('-', sample[8])
- mod = sample[0..7].to_i % 23
-
- assert_equal Faker::IdNumber::CHECKS[mod], sample[9]
- end
-
- def test_spanish_nie
- sample = @tester.spanish_foreign_citizen_number
-
- assert_equal 11, sample.length
- assert_includes 'XYZ', sample[0]
- assert_equal '-', sample[1]
- assert sample[2..8].split.map { :to_i }.all? { :is_digit? }
- assert_equal '-', sample[9]
- prefix = 'XYZ'.index(sample[0]).to_s
- mod = "#{prefix}#{sample[2..8]}".to_i % 23
-
- assert_equal Faker::IdNumber::CHECKS[mod], sample[10]
- end
-
- def test_south_african_id_number
- assert_valid_south_african_id_number(@tester.south_african_id_number)
- end
-
- def test_valid_south_african_id_number
- assert_valid_south_african_id_number(@tester.valid_south_african_id_number)
- end
-
- def test_invalid_south_african_id_number
- sample = @tester.invalid_south_african_id_number
-
- assert_raises Date::Error do
- Date.parse(south_african_id_number_to_date_of_birth_string(sample))
- end
- end
-
- def test_brazilian_citizen_number
- sample = @tester.brazilian_citizen_number
-
- assert_match(/^\d{11}$/, sample)
- assert_match(/(\d)((?!\1)\d)+/, sample)
- end
-
- def test_brazilian_citizen_number_formatted
- sample = @tester.brazilian_citizen_number(formatted: true)
-
- assert_match(/^\d{3}\.\d{3}\.\d{3}-\d{2}$/, sample)
- end
-
- def test_brazilian_id
- sample = @tester.brazilian_id
-
- assert_match(/^\d{8}(X|\d)?$/, sample)
- assert_match(/(\d)((?!\1)\d)+/, sample)
- end
-
- def test_brazilian_id_formatted
- sample = @tester.brazilian_id(formatted: true)
-
- assert_match(/^\d{1,2}.\d{3}.\d{3}-[\dX]$/, sample)
- end
-
- def test_brazilian_citizen_number_checksum_digit
- digits = '128991760'
- checksum_digit = Faker::IdNumber.send(:brazilian_citizen_number_checksum_digit, digits)
-
- assert_equal('4', checksum_digit)
- digits = '1289917604'
- checksum_digit = Faker::IdNumber.send(:brazilian_citizen_number_checksum_digit, digits)
-
- assert_equal('8', checksum_digit)
- end
-
- def test_brazilian_id_checksum_digit
- digits = '41987080'
- checksum_digit = Faker::IdNumber.send(:brazilian_id_checksum_digit, digits)
-
- assert_equal('5', checksum_digit)
- end
-
- def test_brazilian_document_checksum
- digits = '123456789'
- checksum = Faker::IdNumber.send(:brazilian_document_checksum, digits)
-
- assert_equal(2100, checksum)
- end
-
- def test_brazilian_document_digit
- citizen_number_digit10 = Faker::IdNumber.send(:brazilian_document_digit, 10)
- citizen_number_digit_other = Faker::IdNumber.send(:brazilian_document_digit, 9)
- id_digit10 = Faker::IdNumber.send(:brazilian_document_digit, 1, id: true)
- id_digit11 = Faker::IdNumber.send(:brazilian_document_digit, 0, id: true)
- id_digit_other = Faker::IdNumber.send(:brazilian_document_digit, 2, id: true)
-
- assert_equal('0', citizen_number_digit10)
- assert_equal('9', citizen_number_digit_other)
- assert_equal('X', id_digit10)
- assert_equal('0', id_digit11)
- assert_equal('9', id_digit_other)
- end
-
- def test_brazilian_citizen_number_digit
- digit10 = Faker::IdNumber.send(:brazilian_citizen_number_digit, 10)
- digit_other = Faker::IdNumber.send(:brazilian_citizen_number_digit, 9)
-
- assert_equal('0', digit10)
- assert_equal('9', digit_other)
- end
-
- def test_brazilian_id_digit
- digit10 = Faker::IdNumber.send(:brazilian_id_digit, 1)
- digit11 = Faker::IdNumber.send(:brazilian_id_digit, 0)
- digit_other = Faker::IdNumber.send(:brazilian_id_digit, 2)
-
- assert_equal('X', digit10)
- assert_equal('0', digit11)
- assert_equal('9', digit_other)
- end
-
- def test_chilean_id
- sample = @tester.chilean_id
-
- assert_match(/^\d{8}-[K\d]$/, sample)
- end
-
- def test_chilean_verification_code_k
- verification_code = Faker::IdNumber.send(:chilean_verification_code, 20_680_873)
-
- assert_equal('K', verification_code)
- end
-
- def test_chilean_verification_code_0
- verification_code = Faker::IdNumber.send(:chilean_verification_code, 13_196_022)
-
- assert_equal(0, verification_code)
- end
-
- def test_croatian_id
- sample = @tester.croatian_id
-
- assert_match(/^\d{11}$/, sample)
- end
-
- def test_croatian_id_international
- sample = @tester.croatian_id(international: true)
-
- assert_match(/^HR\d{11}$/, sample)
- end
-
- def test_croatian_id_checksum_digit
- digits = '8764670153'
- checksum_digit = Faker::IdNumber.send(:croatian_id_checksum_digit, digits)
-
- assert_equal(5, checksum_digit)
- end
-
- def test_danish_id_number
- sample = @tester.danish_id_number
-
- assert_match(/^\d{10}$/, sample)
- end
-
- def test_french_insee_number
- sample = @tester.french_insee_number
-
- assert_match(/^(?\d{1})(?\d{2})(?\d{2})(?\d{1})(?[0-9AB]{1})(?\d{3})(?\d{3})(?\d{2})$/, sample)
- end
-
- def test_danish_id_number_formatted
- sample = @tester.danish_id_number(formatted: true)
-
- assert_match(/^\d{6}-\d{4}$/, sample)
- end
-
- def test_danish_id_number_birthday
- sample = @tester.danish_id_number(birthday: Date.new(1995, 1, 2))
-
- assert_match(/^020195\d{4}$/, sample)
- end
-
- def test_danish_id_number_birthday_early_1800
- assert_raises ArgumentError do
- @tester.danish_id_number(birthday: Date.new(1815, 1, 2))
- end
- end
-
- def test_danish_id_number_birthday_late_1800
- sample = @tester.danish_id_number(birthday: Date.new(1895, 1, 2))
-
- assert_match(/^020195[5678]\d{3}$/, sample)
- end
-
- def test_danish_id_number_birthday_early_1900
- sample = @tester.danish_id_number(birthday: Date.new(1915, 1, 2))
-
- assert_match(/^020115[0123]\d{3}$/, sample)
- end
-
- def test_danish_id_number_birthday_late_1900
- sample = @tester.danish_id_number(birthday: Date.new(1995, 1, 2))
-
- assert_match(/^020195[012349]\d{3}$/, sample)
- end
-
- def test_danish_id_number_birthday_early_2000
- sample = @tester.danish_id_number(birthday: Date.new(2015, 1, 2))
-
- assert_match(/^020115[456789]\d{3}$/, sample)
- end
-
- def test_danish_id_number_birthday_mid_2000
- sample = @tester.danish_id_number(birthday: Date.new(2055, 1, 2))
-
- assert_match(/^020155[5678]\d{3}$/, sample)
- end
-
- def test_danish_id_number_birthday_late_2000
- assert_raises ArgumentError do
- @tester.danish_id_number(birthday: Date.new(2095, 1, 2))
- end
- end
-
- def test_danish_id_number_gender_female
- sample = @tester.danish_id_number(gender: :female)
-
- assert_predicate sample.chars.last.to_i, :even?
- end
-
- def test_danish_id_number_gender_male
- sample = @tester.danish_id_number(gender: :male)
-
- assert_predicate sample.chars.last.to_i, :odd?
- end
-
- def test_danish_id_number_invalid_gender
- assert_raises ArgumentError do
- @tester.danish_id_number(gender: :invalid)
- end
- end
-
- private
-
- def south_african_id_number_to_date_of_birth_string(sample)
- "19#{sample[0..1]}/#{sample[2..3]}/#{sample[4..5]}}"
- end
-
- def assert_valid_south_african_id_number(sample)
- assert_equal 13, sample.length
- assert_match(/^\d{13}$/, sample)
- assert_include Faker::IdNumber::ZA_CITIZENSHIP_DIGITS, sample[10]
- assert_equal Faker::IdNumber::ZA_RACE_DIGIT, sample[11]
- assert Date.parse(south_african_id_number_to_date_of_birth_string(sample))
- end
-end
diff --git a/test/faker/default/test_faker_theater.rb b/test/faker/default/test_faker_theater.rb
index bded8c8a59..bf0ad2857f 100644
--- a/test/faker/default/test_faker_theater.rb
+++ b/test/faker/default/test_faker_theater.rb
@@ -15,24 +15,3 @@ def test_play
assert_match(/\w+/, Faker::Theater.play)
end
end
-
-# with test_faker_show.rb
-class TestFakerShow < Test::Unit::TestCase
- def setup
- Faker::Deprecator.skip_warning do
- @tester = Faker::Show
- end
- end
-
- def test_adult_musical
- assert_match(/\w+/, @tester.adult_musical)
- end
-
- def test_kids_musical
- assert_match(/\w+/, @tester.kids_musical)
- end
-
- def test_play
- assert_match(/\w+/, @tester.play)
- end
-end
diff --git a/test/faker/default/test_faker_vehicle.rb b/test/faker/default/test_faker_vehicle.rb
index 71a43943f4..8926651d1c 100644
--- a/test/faker/default/test_faker_vehicle.rb
+++ b/test/faker/default/test_faker_vehicle.rb
@@ -3,8 +3,8 @@
require_relative '../../test_helper'
class TestFakerVehicle < Test::Unit::TestCase
- WORD_MATCH = /\w+\.?/.freeze
- VIN_REGEX = /\A[A-HJ-NPR-Z0-9]{17}\z/.freeze
+ WORD_MATCH = /\w+\.?/
+ VIN_REGEX = /\A[A-HJ-NPR-Z0-9]{17}\z/
def setup
@tester = Faker::Vehicle
diff --git a/test/faker/japanese_media/test_faker_fullmetal_alchemist_brotherhood.rb b/test/faker/japanese_media/test_faker_fullmetal_alchemist_brotherhood.rb
index f13ae6dde6..d5ac5ac9d3 100644
--- a/test/faker/japanese_media/test_faker_fullmetal_alchemist_brotherhood.rb
+++ b/test/faker/japanese_media/test_faker_fullmetal_alchemist_brotherhood.rb
@@ -2,26 +2,6 @@
require_relative '../../test_helper'
-class TestFakerFmaBrotherhood < Test::Unit::TestCase
- def setup
- Faker::Deprecator.skip_warning do
- @tester = Faker::JapaneseMedia::FmaBrotherhood
- end
- end
-
- def test_character
- assert_match(/\w+/, @tester.character)
- end
-
- def test_city
- assert_match(/\w+/, @tester.city)
- end
-
- def test_country
- assert_match(/\w+/, @tester.country)
- end
-end
-
class TestFakerFullmetalAlchemistBrotherhood < Test::Unit::TestCase
def setup
@tester = Faker::JapaneseMedia::FullmetalAlchemistBrotherhood
diff --git a/test/faker/locations/test_faker_australia.rb b/test/faker/locations/test_faker_australia.rb
index 4cce00fc6e..f6d0f6912e 100644
--- a/test/faker/locations/test_faker_australia.rb
+++ b/test/faker/locations/test_faker_australia.rb
@@ -15,23 +15,3 @@ def test_state
assert_match(/\w+/, Faker::Locations::Australia.state)
end
end
-
-class TestFakerAustralia < Test::Unit::TestCase
- def setup
- Faker::Deprecator.skip_warning do
- @tester = Faker::Australia
- end
- end
-
- def test_deprecated_location
- assert_match(/\w+/, @tester.location)
- end
-
- def test_deprecated_animal
- assert_match(/\w+/, @tester.animal)
- end
-
- def test_state
- assert_match(/\w+/, @tester.state)
- end
-end
diff --git a/test/faker/tv_shows/test_buffy.rb b/test/faker/tv_shows/test_buffy.rb
index b5128ff00e..d9b5b55880 100644
--- a/test/faker/tv_shows/test_buffy.rb
+++ b/test/faker/tv_shows/test_buffy.rb
@@ -19,11 +19,6 @@ def test_actor
assert_match(/\w+/, @tester.actor)
end
- # deprecated
- def test_celebrity
- assert_match(/\w+/, @tester.celebrity)
- end
-
def test_big_bad
assert_match(/\w+/, @tester.big_bad)
end
diff --git a/test/faker/tv_shows/test_dr_who.rb b/test/faker/tv_shows/test_dr_who.rb
index 57539855bd..7d06713dba 100644
--- a/test/faker/tv_shows/test_dr_who.rb
+++ b/test/faker/tv_shows/test_dr_who.rb
@@ -28,11 +28,6 @@ def test_quote
deterministically_verify(-> { @tester.quote }) { |result| assert_match(/\w+/, result) }
end
- # deprecated
- def test_villian
- deterministically_verify(-> { @tester.villian }) { |result| assert_match(/\w+/, result) }
- end
-
def test_villain
deterministically_verify(-> { @tester.villain }) { |result| assert_match(/\w+/, result) }
end
@@ -49,7 +44,6 @@ def test_locales
assert_kind_of String, @tester.the_doctor
assert_kind_of String, @tester.catch_phrase
assert_kind_of String, @tester.quote
- assert_kind_of String, @tester.villian # deprecated
assert_kind_of String, @tester.villain
assert_kind_of String, @tester.specie
end
diff --git a/test/faker/tv_shows/test_the_fresh_prince_of_bel_air.rb b/test/faker/tv_shows/test_the_fresh_prince_of_bel_air.rb
index 44c067e079..f147c2f791 100644
--- a/test/faker/tv_shows/test_the_fresh_prince_of_bel_air.rb
+++ b/test/faker/tv_shows/test_the_fresh_prince_of_bel_air.rb
@@ -15,11 +15,6 @@ def test_actor
assert_match(/\w+/, @tester.actor)
end
- # deprecated
- def test_celebrity
- assert_match(/\w+/, @tester.celebrity)
- end
-
def test_quote
assert_match(/\w+/, @tester.quote)
end
diff --git a/test/helpers/test_faker_deprecator.rb b/test/helpers/test_faker_deprecator.rb
new file mode 100644
index 0000000000..931bf96e87
--- /dev/null
+++ b/test/helpers/test_faker_deprecator.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+require_relative '../test_helper'
+
+class TestFakerDeprecation < Test::Unit::TestCase
+ def test_using_a_deprecated_generator_returns_a_warning_message
+ assert_deprecated do
+ Faker::Dogs.say
+ end
+
+ assert_equal 'meow', Faker::Dogs.say
+ end
+
+ def test_using_a_non_deprecated_generator_does_not_return_a_warning_message
+ assert_not_deprecated do
+ Faker::Cats.say
+ end
+ assert_equal 'meow', Faker::Cats.say
+ end
+
+ def test_testing_a_deprecated_generator_with_skip_warning_does_not_return_a_warning_message
+ actual_stdout, actual_stderr = capture_output do
+ Faker::Deprecator.skip_warning do
+ Faker::Dogs.say
+ end
+ end
+
+ assert_empty(actual_stdout)
+ assert_empty(actual_stderr)
+ assert_equal 'meow', Faker::Dogs.say
+ end
+
+ def test_deprecated_with_skip_warning_does_not_generate_message
+ Faker::Deprecator.skip_warning do
+ assert_not_deprecated do
+ Faker::Dogs.say
+ end
+ end
+
+ assert_equal 'meow', Faker::Dogs.say
+ end
+end
+
+module Faker
+ class Cats < Base
+ def self.say
+ 'meow'
+ end
+ end
+
+ include Faker::Deprecator
+ deprecate_generator('Dogs', Cats)
+end
diff --git a/test/support/deprecation.rb b/test/support/deprecation.rb
new file mode 100644
index 0000000000..0f98e5a2fe
--- /dev/null
+++ b/test/support/deprecation.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+# Based on Rails Testing Deprecator
+# https://github.com/rails/rails/blob/main/activesupport/lib/active_support/testing/deprecation.rb
+
+# Asserts that a matching deprecation warning was emitted during the execution of the yielded block.
+#
+# assert_deprecated do
+# DeprecatedGenerator.generate
+# end
+#
+def assert_deprecated(&block)
+ warning = with_captured_stdout(&block)
+ result = yield block
+
+ refute_predicate warning, :empty?, 'Expected a deprecation warning within the block but received none'
+
+ result
+end
+
+# Asserts that no deprecation warnings are emitted during the execution of the yielded block.
+#
+# assert_not_deprecated do
+# Faker::Internet.email
+# end
+def assert_not_deprecated(&block)
+ warning = with_captured_stdout(&block)
+ result = yield block
+
+ assert_predicate warning, :empty?, "Expected no deprecation warning within the block but received a deprecation: #{warning}"
+ result
+end
+
+def with_captured_stdout(&block)
+ original_stdout = $stdout
+ $stdout = StringIO.new
+ yield block
+ $stdout.string
+ensure
+ $stdout = original_stdout
+end
diff --git a/test/test_faker_deprecator.rb b/test/test_faker_deprecator.rb
deleted file mode 100644
index 0083a2203c..0000000000
--- a/test/test_faker_deprecator.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-require_relative 'test_helper'
-
-class TestFakerDeprecation < Test::Unit::TestCase
- def test_using_a_deprecated_generator_returns_a_warning_message
- actual_stdout, actual_stderr = capture_output do
- Faker::IDNumber.valid
- end
-
- assert_includes(actual_stdout, 'DEPRECATION WARNING: Faker::IDNumber is deprecated. Use Faker::IdNumber instead')
- assert_empty(actual_stderr)
- end
-
- def test_using_a_non_deprecated_generator_does_not_return_a_warning_message
- actual_stdout, actual_stderr = capture_output do
- Faker::IdNumber.valid
- end
-
- assert_empty(actual_stdout)
- assert_empty(actual_stderr)
- end
-end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 5d615e92e6..53588e9296 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -11,6 +11,7 @@
require_relative 'support/assert_not_english'
require_relative 'support/assert_email_regex'
+require_relative 'support/deprecation'
require 'minitest/autorun'
require 'test/unit'
require 'rubygems'