From c65641266132868410e80336ede27f87f14829ef Mon Sep 17 00:00:00 2001 From: Chibuzor Efedigbue <32690770+uzorjchibuzor@users.noreply.github.com> Date: Tue, 1 Nov 2022 17:25:09 +0100 Subject: [PATCH] Deprecate LoremPixel (#2590) * added deprecation warning * included serach terms in method call * test for lorem_pixel redirection to loremflickr with options * used Gem::Deprecate to show warning message * deprecation message showing end of year * test for deprecation warning * fix rubocop offences * simplified test for deprecation * fix rubocop offense on the test file --- lib/faker/default/lorem_pixel.rb | 3 +++ test/faker/default/test_lorem_pixel.rb | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/faker/default/lorem_pixel.rb b/lib/faker/default/lorem_pixel.rb index e05266ea12..0c1836dfbf 100644 --- a/lib/faker/default/lorem_pixel.rb +++ b/lib/faker/default/lorem_pixel.rb @@ -3,6 +3,8 @@ module Faker class LoremPixel < Base class << self + extend Gem::Deprecate + SUPPORTED_CATEGORIES = %w[abstract animals business @@ -55,6 +57,7 @@ def image(size: '300x300', is_gray: false, category: nil, number: nil, text: nil url_parts += [category, number, text].compact url_parts.join('/') end + deprecate :image, 'Faker::LoremFlickr.image', 2022, 12 # rubocop:enable Metrics/ParameterLists end end diff --git a/test/faker/default/test_lorem_pixel.rb b/test/faker/default/test_lorem_pixel.rb index 2ef85da22c..63eb31a0ca 100644 --- a/test/faker/default/test_lorem_pixel.rb +++ b/test/faker/default/test_lorem_pixel.rb @@ -7,6 +7,14 @@ def setup @tester = Faker::LoremPixel end + def test_image_deprecation_message + _out, err = capture_output do + @tester.image(size: '3x3') + end + + assert_match(/Faker::LoremPixel.image is deprecated; use Faker::LoremFlickr.image instead\./, err) + end + def test_lorempixel refute_nil @tester.image.match(%r{https://lorempixel\.com/(\d+/\d+)})[1] end