diff --git a/lib/faker/locations/australia.rb b/lib/faker/locations/australia.rb index 56ae93c9d0..e3696d5fa6 100644 --- a/lib/faker/locations/australia.rb +++ b/lib/faker/locations/australia.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true module Faker - extend Deprecator - class Locations class Australia < Base class << self @@ -48,5 +46,7 @@ def state end end end + + include Deprecator deprecate_generator('Australia', Locations::Australia) end diff --git a/lib/helpers/deprecator.rb b/lib/helpers/deprecator.rb index e280cf9423..476d7cffdf 100644 --- a/lib/helpers/deprecator.rb +++ b/lib/helpers/deprecator.rb @@ -6,11 +6,16 @@ # rubocop:disable Style/ClassVars module Faker module Deprecator + @@skip_warning = false + 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]) - $stdout.puts("DEPRECATION WARNING: #{name}::#{replacement[:old_generator]} is deprecated. Use #{replacement[:new_constant]} instead.") + unless Faker::Deprecator.skip_warning? + $stdout.puts("DEPRECATION WARNING: #{name}::#{replacement[:old_generator]} is deprecated. Use #{replacement[:new_constant]} instead.") + end + return replacement[:new_constant] end @@ -25,6 +30,26 @@ def deprecate_generator(old_generator_name, new_generator_constant) base.singleton_class.prepend extension end + + def self.skip_warning + original = Faker::Deprecator.skip + Faker::Deprecator.skip = true + yield + ensure + Faker::Deprecator.skip = original + end + + def self.skip_warning? + skip == true + end + + def self.skip + @skip ||= false + end + + def self.skip=(value) + @skip = value + end end end # rubocop:enable Style/ClassVars diff --git a/test/faker/default/test_faker_id_number.rb b/test/faker/default/test_faker_id_number.rb index 3e66178367..6f3aecd84d 100644 --- a/test/faker/default/test_faker_id_number.rb +++ b/test/faker/default/test_faker_id_number.rb @@ -291,7 +291,9 @@ def assert_valid_south_african_id_number(sample) class TestFakerIDNumber < Test::Unit::TestCase def setup - @tester = Faker::IDNumber + Faker::Deprecator.skip_warning do + @tester = Faker::IDNumber + end end def test_valid_ssn diff --git a/test/faker/default/test_faker_theater.rb b/test/faker/default/test_faker_theater.rb index 360c2fef62..bded8c8a59 100644 --- a/test/faker/default/test_faker_theater.rb +++ b/test/faker/default/test_faker_theater.rb @@ -18,15 +18,21 @@ def test_play # 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+/, Faker::Show.adult_musical) + assert_match(/\w+/, @tester.adult_musical) end def test_kids_musical - assert_match(/\w+/, Faker::Show.kids_musical) + assert_match(/\w+/, @tester.kids_musical) end def test_play - assert_match(/\w+/, Faker::Show.play) + assert_match(/\w+/, @tester.play) end end 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 f651796a6a..f13ae6dde6 100644 --- a/test/faker/japanese_media/test_faker_fullmetal_alchemist_brotherhood.rb +++ b/test/faker/japanese_media/test_faker_fullmetal_alchemist_brotherhood.rb @@ -4,7 +4,9 @@ class TestFakerFmaBrotherhood < Test::Unit::TestCase def setup - @tester = Faker::JapaneseMedia::FmaBrotherhood + Faker::Deprecator.skip_warning do + @tester = Faker::JapaneseMedia::FmaBrotherhood + end end def test_character diff --git a/test/faker/locations/test_faker_australia.rb b/test/faker/locations/test_faker_australia.rb index 4e78113d62..4cce00fc6e 100644 --- a/test/faker/locations/test_faker_australia.rb +++ b/test/faker/locations/test_faker_australia.rb @@ -17,15 +17,21 @@ def test_state 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+/, Faker::Australia.location) + assert_match(/\w+/, @tester.location) end def test_deprecated_animal - assert_match(/\w+/, Faker::Australia.animal) + assert_match(/\w+/, @tester.animal) end def test_state - assert_match(/\w+/, Faker::Australia.state) + assert_match(/\w+/, @tester.state) end end