From ef5417fc45ec2d6067e3e1d44479b6cd6f80f7e3 Mon Sep 17 00:00:00 2001 From: Chibuzor Efedigbue Date: Tue, 20 Dec 2022 10:24:30 +0100 Subject: [PATCH] lorem_pixel test file and class file and documentation with reference to the documentation on readme.md has been removed --- README.md | 1 - doc/default/lorem_pixel.md | 15 ----- lib/faker/default/lorem_pixel.rb | 64 --------------------- test/faker/default/test_lorem_pixel.rb | 79 -------------------------- 4 files changed, 159 deletions(-) delete mode 100644 doc/default/lorem_pixel.md delete mode 100644 lib/faker/default/lorem_pixel.rb delete mode 100644 test/faker/default/test_lorem_pixel.rb diff --git a/README.md b/README.md index 63b47a2c22..3ef7959766 100644 --- a/README.md +++ b/README.md @@ -277,7 +277,6 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'main - [Faker::Kpop](doc/default/kpop.md) - [Faker::Lorem](doc/default/lorem.md) - [Faker::LoremFlickr](doc/default/lorem_flickr.md) - - [Faker::LoremPixel](doc/default/lorem_pixel.md) - [Faker::Markdown](doc/default/markdown.md) - [Faker::Marketing](doc/default/marketing.md) - [Faker::Measurement](doc/default/measurement.md) diff --git a/doc/default/lorem_pixel.md b/doc/default/lorem_pixel.md deleted file mode 100644 index 149db099ca..0000000000 --- a/doc/default/lorem_pixel.md +++ /dev/null @@ -1,15 +0,0 @@ -# Faker::LoremPixel - -Available since version 1.7.0. - -```ruby -# Keyword arguments: size, is_gray, category, number, text, secure -Faker::LoremPixel.image #=> "https://lorempixel.com/300/300" -Faker::LoremPixel.image(size: "50x60") #=> "https://lorempixel.com/50/60" -Faker::LoremPixel.image(size: "50x60", is_gray: true) #=> "https://lorempixel.com/g/50/60" -Faker::LoremPixel.image(size: "50x60", is_gray: false, category: 'sports') #=> "https://lorempixel.com/50/60/sports" -Faker::LoremPixel.image(size: "50x60", is_gray: false, category: 'sports', number: 3) #=> "https://lorempixel.com/50/60/sports/3" -Faker::LoremPixel.image(size: "50x60", is_gray: false, category: 'sports', number: 3, text: 'Dummy-text') #=> "https://lorempixel.com/50/60/sports/3/Dummy-text" -Faker::LoremPixel.image(size: "50x60", is_gray: false, category: 'sports', number: nil, text: 'Dummy-text') #=> "https://lorempixel.com/50/60/sports/Dummy-text" -Faker::LoremPixel.image(secure: false) #=> "http://lorempixel.com/300/300" -``` diff --git a/lib/faker/default/lorem_pixel.rb b/lib/faker/default/lorem_pixel.rb deleted file mode 100644 index 0c1836dfbf..0000000000 --- a/lib/faker/default/lorem_pixel.rb +++ /dev/null @@ -1,64 +0,0 @@ -# frozen_string_literal: true - -module Faker - class LoremPixel < Base - class << self - extend Gem::Deprecate - - SUPPORTED_CATEGORIES = %w[abstract - animals - business - cats - city - food - nightlife - fashion - people - nature - sports - technics - transport].freeze - - # rubocop:disable Metrics/ParameterLists - - ## - # Produces a random image URL from lorempixel.com. - # - # @param size [String] Specifies the size of image to generate. - # @param is_gray [Boolean] Determines if the image is gray. - # @param category [Symbol] Adds the category of the generated image to the URL. - # @param number [Integer] Adds a number as part of the URL. - # @param text [Integer] Adds dummy text as part of the URL. - # @param secure [Boolean] Changes the image URL between http and https. - # @return [String] - # - # @example - # Faker::LoremPixel.image #=> "https://lorempixel.com/300/300" - # Faker::LoremPixel.image(size: "50x60") #=> "https://lorempixel.com/50/60" - # Faker::LoremPixel.image(size: "50x60", is_gray: true) #=> "https://lorempixel.com/g/50/60" - # Faker::LoremPixel.image(size: "50x60", is_gray: false, category: 'sports') #=> "https://lorempixel.com/50/60/sports" - # Faker::LoremPixel.image(size: "50x60", is_gray: false, category: 'sports', number: 3) #=> "https://lorempixel.com/50/60/sports/3" - # Faker::LoremPixel.image(size: "50x60", is_gray: false, category: 'sports', number: 3, text: 'Dummy-text') #=> "https://lorempixel.com/50/60/sports/3/Dummy-text" - # Faker::LoremPixel.image(size: "50x60", is_gray: false, category: 'sports', number: nil, text: 'Dummy-text') #=> "https://lorempixel.com/50/60/sports/Dummy-text" - # Faker::LoremPixel.image(secure: false) #=> "http://lorempixel.com/300/300" - # - # @faker.version 1.7.0 - def image(size: '300x300', is_gray: false, category: nil, number: nil, text: nil, secure: true) - raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /^[0-9]+x[0-9]+$/ - raise ArgumentError, "Supported categories are #{SUPPORTED_CATEGORIES.join(', ')}" unless category.nil? || SUPPORTED_CATEGORIES.include?(category) - raise ArgumentError, 'Category required when number is passed' if !number.nil? && category.nil? - raise ArgumentError, 'Number must be between 1 and 10' unless number.nil? || (1..10).cover?(number) - raise ArgumentError, 'Category and number must be passed when text is passed' if !text.nil? && number.nil? && category.nil? - - url_parts = secure ? ['https:/'] : ['http:/'] - url_parts << ['lorempixel.com'] - url_parts << 'g' if is_gray - url_parts += size.split('x') - url_parts += [category, number, text].compact - url_parts.join('/') - end - deprecate :image, 'Faker::LoremFlickr.image', 2022, 12 - # rubocop:enable Metrics/ParameterLists - end - end -end diff --git a/test/faker/default/test_lorem_pixel.rb b/test/faker/default/test_lorem_pixel.rb deleted file mode 100644 index 63eb31a0ca..0000000000 --- a/test/faker/default/test_lorem_pixel.rb +++ /dev/null @@ -1,79 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../test_helper' - -class TestLoremPixel < Test::Unit::TestCase - 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 - - def test_lorempixel_insecure - refute_nil @tester.image(size: '300x300', is_gray: nil, category: nil, number: nil, text: nil, secure: false).match(%r{http://lorempixel\.com/(\d+/\d+)})[1] - end - - def test_image_with_custom_size - assert_equal('3/3', @tester.image(size: '3x3').match(%r{https://lorempixel\.com/(\d+/\d+)})[1]) - end - - def test_image_with_incorrect_size - assert_raise ArgumentError do - @tester.image(size: '300x300s') - end - end - - def test_image_gray - assert_match %r{https://lorempixel\.com/g/\d+/\d+}, @tester.image(size: '300x300', is_gray: true) - end - - def test_image_with_supported_category - assert_equal('animals', @tester.image(size: '300x300', is_gray: false, category: 'animals').match(%r{https://lorempixel\.com/\d+/\d+/(.*)})[1]) - end - - def test_image_with_incorrect_category - assert_raise ArgumentError do - @tester.image(size: '300x300', is_gray: false, category: 'wrong_category') - end - end - - def test_image_with_supported_category_and_correct_number - assert_equal('3', @tester.image(size: '300x300', is_gray: false, category: 'animals', number: 3).match(%r{https://lorempixel\.com/\d+/\d+/.+/(\d+)})[1]) - end - - def test_image_with_supported_category_and_incorrect_number - assert_raise ArgumentError do - @tester.image(size: '300x300', is_gray: false, category: 'animals', number: 11) - end - end - - def test_image_with_correct_number_and_without_category - assert_raise ArgumentError do - @tester.image(size: '300x300', is_gray: false, category: 'wrong_category', number: 3) - end - end - - def test_image_with_text_correct_number_and_supported_category - assert_equal('Dummy-text', @tester.image(size: '300x300', is_gray: false, category: 'animals', number: 3, text: 'Dummy-text').match(%r{https://lorempixel\.com/\d+/\d+/.+/3/(.+)})[1]) - end - - def test_image_with_text_supported_category_and_text_without_number - assert_equal('Dummy-text', @tester.image(size: '300x300', is_gray: false, category: 'animals', number: nil, text: 'Dummy-text').match(%r{https://lorempixel\.com/\d+/\d+/.+/(.+)})[1]) - end - - def test_image_with_text_without_number_and_category - assert_raise ArgumentError do - @tester.image(size: '300x300', is_gray: false, category: nil, number: nil, text: 'Dummy-text') - end - end -end