|
3 | 3 | require_relative 'test_helper'
|
4 | 4 |
|
5 | 5 | class TestFakerDeprecation < Test::Unit::TestCase
|
| 6 | + ## |
| 7 | + # A hash that maps deprecated methods to their new counterparts. |
| 8 | + # |
| 9 | + # @return [Hash{Array<String, String> => Array<String, String>}] |
| 10 | + # |
| 11 | + # @example Add the following into the hash |
| 12 | + # ['Faker::OldKlass', 'old_method'] => ['Faker::NewKlass', 'new_method'] |
| 13 | + DEPRECATION_MAPPINGS = { |
| 14 | + ['Faker::IDNumber', 'valid'] => ['Faker::IdNumber', 'valid'], |
| 15 | + ['Faker::JapaneseMedia::FmaBrotherhood', 'character'] => ['Faker::JapaneseMedia::FullmetalAlchemistBrotherhood', 'character'] |
| 16 | + }.freeze |
| 17 | + |
6 | 18 | def test_using_a_deprecated_generator_returns_a_warning_message
|
7 | 19 | actual_stdout, actual_stderr = capture_output do
|
8 |
| - Faker::IDNumber.valid |
9 |
| - Faker::JapaneseMedia::FmaBrotherhood.character |
| 20 | + DEPRECATION_MAPPINGS.each_key { |klass, method| Object.const_get(klass).send(method) } |
10 | 21 | end
|
11 | 22 |
|
12 |
| - assert_includes(actual_stdout, 'DEPRECATION WARNING: Faker::IDNumber is deprecated. Use Faker::IdNumber instead') |
13 |
| - assert_includes(actual_stdout, 'DEPRECATION WARNING: Faker::JapaneseMedia::FmaBrotherhood is deprecated. Use Faker::JapaneseMedia::FullmetalAlchemistBrotherhood instead') |
| 23 | + DEPRECATION_MAPPINGS.each do |(deprecated_klass, _deprecated_method), (new_klass, _new_method)| |
| 24 | + assert_includes(actual_stdout, "DEPRECATION WARNING: #{deprecated_klass} is deprecated. Use #{new_klass} instead") |
| 25 | + end |
14 | 26 | assert_empty(actual_stderr)
|
15 | 27 | end
|
16 | 28 |
|
17 | 29 | def test_using_a_non_deprecated_generator_does_not_return_a_warning_message
|
18 | 30 | actual_stdout, actual_stderr = capture_output do
|
19 |
| - Faker::IdNumber.valid |
20 |
| - Faker::JapaneseMedia::FullmetalAlchemistBrotherhood.character |
| 31 | + DEPRECATION_MAPPINGS.each_value { |klass, method| Object.const_get(klass).send(method) } |
21 | 32 | end
|
22 | 33 |
|
23 | 34 | assert_empty(actual_stdout)
|
|
0 commit comments