diff --git a/CHANGELOG.md b/CHANGELOG.md index 004db35384..39c31ec287 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log + +## v2.0.0 + +- [PR #1349](https://github.com/stympy/faker/pull/1349) Add Namespace for Lorem - Faker::Lorem::Ipsum; Faker::Lorem::Flickr; Faker::Lorem::Pixel [@vbrazo](https://github.com/vbrazo) +- [PR #510](https://github.com/stympy/faker/pull/510) Make Faker::Number return integers and floats instead of strings [@tejasbubane](https://github.com/tejasbubane) + +------------------------------------------------------------------------------ + ## HEAD Unreleased ### Bug/Fixes @@ -912,4 +920,4 @@ * Initial release -\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* +\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* \ No newline at end of file diff --git a/doc/v2.0/lorem/flickr.md b/doc/v2.0/lorem/flickr.md new file mode 100644 index 0000000000..4b95dff660 --- /dev/null +++ b/doc/v2.0/lorem/flickr.md @@ -0,0 +1,47 @@ +# Faker::Lorem::Flickr + +Available since version 1.9.0. + +```ruby +Faker::Lorem::Flickr.image #=> "http://loremflickr.com/300/300" + +Faker::Lorem::Flickr.image("50x60") #=> "http://loremflickr.com/50/60" + +Faker::Lorem::Flickr.image("50x60", ['sports']) #=> "http://loremflickr.com/50/60/sports" + +Faker::Lorem::Flickr.image("50x60", ['sports', 'fitness']) #=> "http://loremflickr.com/50/60/sports,fitness" + +Faker::Lorem::Flickr.image("50x60", ['sports', 'fitness'], true) #=> "http://loremflickr.com/50/60/sports,fitness/all" + +Faker::Lorem::Flickr.grayscale_image #=> "http://loremflickr.com/g/300/300/all" + +Faker::Lorem::Flickr.grayscale_image("50x60") #=> "http://loremflickr.com/g/50/60/all" + +Faker::Lorem::Flickr.grayscale_image("50x60", ['sports']) #=> "http://loremflickr.com/g/50/60/sports" + +Faker::Lorem::Flickr.grayscale_image("50x60", ['sports', 'fitness']) #=> "http://loremflickr.com/g/50/60/sports,fitness" + +Faker::Lorem::Flickr.grayscale_image("50x60", ['sports', 'fitness'], true) #=> "http://loremflickr.com/g/50/60/sports,fitness/all" + +Faker::Lorem::Flickr.pixelated_image #=> "http://loremflickr.com/p/300/300/all" + +Faker::Lorem::Flickr.pixelated_image("50x60") #=> "http://loremflickr.com/p/50/60/all" + +Faker::Lorem::Flickr.pixelated_image("50x60", ['sports']) #=> "http://loremflickr.com/p/50/60/sports" + +Faker::Lorem::Flickr.pixelated_image("50x60", ['sports', 'fitness']) #=> "http://loremflickr.com/p/50/60/sports,fitness" + +Faker::Lorem::Flickr.pixelated_image("50x60", ['sports', 'fitness'], true) #=> "http://loremflickr.com/p/50/60/sports,fitness/all" + +Faker::Lorem::Flickr.colorized_image #=> "http://loremflickr.com/red/300/300/all" + +Faker::Lorem::Flickr.colorized_image("50x60") #=> "http://loremflickr.com/red/50/60/all" + +Faker::Lorem::Flickr.colorized_image("50x60", 'red') #=> "http://loremflickr.com/red/50/60/all" + +Faker::Lorem::Flickr.colorized_image("50x60", 'red', ['sports']) #=> "http://loremflickr.com/red/50/60/sports" + +Faker::Lorem::Flickr.colorized_image("50x60", 'red', ['sports', 'fitness']) #=> "http://loremflickr.com/red/50/60/sports,fitness" + +Faker::Lorem::Flickr.colorized_image("50x60", 'red', ['sports', 'fitness'], true) #=> "http://loremflickr.com/red/50/60/sports,fitness/all" +``` diff --git a/doc/v2.0/lorem/hipster.md b/doc/v2.0/lorem/hipster.md new file mode 100644 index 0000000000..a182d9dfa5 --- /dev/null +++ b/doc/v2.0/lorem/hipster.md @@ -0,0 +1,41 @@ +# Faker::Lorem::Hipster + +Adapted from [Lorem::Hipster Ipsum](http://hipsum.co/) + +```ruby +Faker::Lorem::Hipster.word #=> "irony" + +# Optional arguments: num=3, supplemental=false, spaces_allowed = false +Faker::Lorem::Hipster.words #=> ["pug", "pitchfork", "chia"] +Faker::Lorem::Hipster.words(4) #=> ["ugh", "cardigan", "poutine", "stumptown"] +Faker::Lorem::Hipster.words(4, true) #=> ["iste", "seitan", "normcore", "provident"] +Faker::Lorem::Hipster.words(4, true, true) #=> ["qui", "magni", "craft beer", "est"] + +# Optional arguments: word_count=4, supplemental=false, random_words_to_add=6 +Faker::Lorem::Hipster.sentence #=> "Park iphone leggings put a bird on it." +Faker::Lorem::Hipster.sentence(3) #=> "Pour-over swag godard." +Faker::Lorem::Hipster.sentence(3, true) #=> "Beard laboriosam sequi celiac." +Faker::Lorem::Hipster.sentence(3, false, 4) #=> "Bitters retro mustache aesthetic biodiesel 8-bit." +Faker::Lorem::Hipster.sentence(3, true, 4) #=> "Occaecati deleniti messenger bag meh crucifix autem." + +# Optional arguments: sentence_count=3, supplemental=false +Faker::Lorem::Hipster.sentences #=> ["Godard pitchfork vinegar chillwave everyday 90's whatever.", "Pour-over artisan distillery street waistcoat.", "Salvia yr leggings franzen blue bottle."] +Faker::Lorem::Hipster.sentences(1) #=> ["Before they sold out pinterest venmo umami try-hard ugh hoodie artisan."] +Faker::Lorem::Hipster.sentences(1, true) #=> ["Et sustainable optio aesthetic et."] + +# Optional arguments: sentence_count=3, supplemental=false, random_sentences_to_add=3 +Faker::Lorem::Hipster.paragraph #=> "Migas fingerstache pbr&b tofu. Polaroid distillery typewriter echo tofu actually. Slow-carb fanny pack pickled direct trade scenester mlkshk plaid. Banjo venmo chambray cold-pressed typewriter. Fap skateboard intelligentsia." +Faker::Lorem::Hipster.paragraph(2) #=> "Yolo tilde farm-to-table hashtag. Lomo kitsch disrupt forage +1." +Faker::Lorem::Hipster.paragraph(2, true) #=> "Typewriter iste ut viral kombucha voluptatem. Sint voluptates saepe. Direct trade irony chia excepturi yuccie. Biodiesel esse listicle et quam suscipit." +Faker::Lorem::Hipster.paragraph(2, false, 4) #=> "Selvage vhs chartreuse narwhal vinegar. Authentic vinyl truffaut carry vhs pop-up. Hammock everyday iphone locavore thundercats bitters vegan goth. Fashion axe banh mi shoreditch whatever artisan." +Faker::Hipster.paragraph(2, true, 4) #=> "Deep v gluten-free unde waistcoat aperiam migas voluptas dolorum. Aut drinking illo sustainable sapiente. Direct trade fanny pack kale chips ennui semiotics." + +# Optional arguments: paragraph_count=3, supplemental=false +Faker::Lorem::Hipster.paragraphs #=> ["Tilde microdosing blog cliche meggings. Intelligentsia five dollar toast forage yuccie. Master kitsch knausgaard. Try-hard everyday trust fund mumblecore.", "Normcore viral pickled. Listicle humblebrag swag tote bag. Taxidermy street hammock neutra butcher cred kale chips. Blog portland humblebrag trust fund irony.", "Single-origin coffee fixie cleanse tofu xoxo. Post-ironic tote bag ramps gluten-free locavore mumblecore hammock. Umami loko twee. Ugh kitsch before they sold out."] +Faker::Lorem::Hipster.paragraphs(1) #=> ["Skateboard cronut synth +1 fashion axe. Pop-up polaroid skateboard asymmetrical. Ennui fingerstache shoreditch before they sold out. Tattooed pitchfork ramps. Photo booth yr messenger bag raw denim bespoke locavore lomo synth."] +Faker::Lorem::Hipster.paragraphs(1, true) #=> ["Quae direct trade pbr&b quo taxidermy autem loko. Umami quas ratione migas cardigan sriracha minima. Tenetur perspiciatis pickled sed eum doloribus truffaut. Excepturi dreamcatcher meditation."] + +# Optional arguments: chars=3, supplemental=false +Faker::Lorem::Hipster.paragraph_by_chars #=> "Truffaut stumptown trust fund 8-bit messenger bag portland. Meh kombucha selvage swag biodiesel. Lomo kinfolk jean shorts asymmetrical diy. Wayfarers portland twee stumptown. Wes anderson biodiesel retro 90's pabst. Diy echo 90's mixtape semiotics. Cornho." +Faker::Lorem::Hipster.paragraph_by_chars(256, false) #=> "Hella kogi blog narwhal sartorial selfies mustache schlitz. Bespoke normcore kitsch cred hella fixie. Park aesthetic fixie migas twee. Cliche mustache brunch tumblr fixie godard. Drinking pop-up synth hoodie dreamcatcher typewriter. Kitsch biodiesel green." +``` diff --git a/doc/v2.0/lorem/ipsum.md b/doc/v2.0/lorem/ipsum.md new file mode 100644 index 0000000000..26063d6a41 --- /dev/null +++ b/doc/v2.0/lorem/ipsum.md @@ -0,0 +1,54 @@ +# Faker::Lorem::Ipsum + +```ruby +Faker::Lorem::Ipsum.word #=> "repellendus" + +# Optional arguments: num=3, supplemental=false (words from a supplementary list of Lorem-like words) +Faker::Lorem::Ipsum.words #=> ["dolores", "adipisci", "nesciunt"] +Faker::Lorem::Ipsum.words(4) #=> ["culpa", "recusandae", "aut", "omnis"] +Faker::Lorem::Ipsum.words(4, true) #=> ["colloco", "qui", "vergo", "deporto"] + +Faker::Lorem::Ipsum.multibyte #=> 😀 + +# Optional arguments: char_count=255 +Faker::Lorem::Ipsum.characters #=> "uw1ep04lhs0c4d931n1jmrspprf5wrj85fefue0y7y6m56b6omquh7br7dhqijwlawejpl765nb1716idmp3xnfo85v349pzy2o9rir23y2qhflwr71c1585fnynguiphkjm8p0vktwitcsm16lny7jzp9t4drwav3qmhz4yjq4k04x14gl6p148hulyqioo72tf8nwrxxcclfypz2lc58lsibgfe5w5p0xv95peafjjmm2frkhdc6duoky0aha" +Faker::Lorem::Ipsum.characters(10) #=> "ang9cbhoa8" + +# Optional arguments: word_count=4, supplemental=false, random_words_to_add=6 +# The 'random_words_to_add' argument increases the sentence's word count by a random value within (0..random_words_to_add). +# To specify an exact word count for a sentence, set word_count to the number you want and random_words_to_add equal to 0. +# By default, sentences will have a random number of words within the range (4..10). +Faker::Lorem::Ipsum.sentence #=> "Dolore illum animi et neque accusantium." +Faker::Lorem::Ipsum.sentence(3) #=> "Commodi qui minus deserunt sed vero quia." +Faker::Lorem::Ipsum.sentence(3, true) #=> "Inflammatio denego necessitatibus caelestis autus illum." +Faker::Lorem::Ipsum.sentence(3, false, 4) #=> "Aut voluptatem illum fugit ut sit." +Faker::Lorem::Ipsum.sentence(3, true, 4) #=> "Accusantium tantillus dolorem timor." + +# Optional arguments: sentence_count=3, supplemental=false +Faker::Lorem::Ipsum.sentences #=> ["Vero earum commodi soluta.", "Quaerat fuga cumque et vero eveniet omnis ut.", "Cumque sit dolor ut est consequuntur."] +Faker::Lorem::Ipsum.sentences(1) #=> ["Ut perspiciatis explicabo possimus doloribus enim quia."] +Faker::Lorem::Ipsum.sentences(1, true) #=> ["Quis capillus curo ager veritatis voro et ipsum."] + +# Optional arguments: sentence_count=3, supplemental=false, random_sentences_to_add=3 +# The 'random_sentences_to_add' argument increases the paragraph's sentence count by a random value within (0..random_sentences_to_add). +# To specify an exact sentence count for a paragraph, set sentence_count to the number you want and random_sentences_to_add equal to 0. +# By default, sentences will have a random number of words within the range (3..6). +Faker::Lorem::Ipsum.paragraph #=> "Neque dicta enim quasi. Qui corrupti est quisquam. Facere animi quod aut. Qui nulla consequuntur consectetur sapiente." +Faker::Lorem::Ipsum.paragraph(2) #=> "Illo qui voluptas. Id sit quaerat enim aut cupiditate voluptates dolorum. Porro necessitatibus numquam dolor quia earum." +Faker::Lorem::Ipsum.paragraph(2, true) #=> "Cedo vero adipisci. Theatrum crustulum coaegresco tonsor crastinus stabilis. Aliqua crur consequatur amor una tolero sum." +Faker::Lorem::Ipsum.paragraph(2, false, 4) #=> "Neque aut et nemo aut incidunt voluptates. Dolore cum est sint est. Vitae assumenda porro odio dolores fugiat. Est voluptatum quia rerum." +Faker::Lorem::Ipsum.paragraph(2, true, 4) #=> "Vomito unde uxor annus. Et patior utilis sursum." + +# Optional arguments: paragraph_count=3, supplemental=false +Faker::Lorem::Ipsum.paragraphs #=> ["Dolores quis quia ad quo voluptates. Maxime delectus totam numquam. Necessitatibus vel atque qui dolore.", "Id neque nemo. Dolores iusto facere est ad. Accusamus ipsa dolor ut.", "Et officiis ut hic. Sunt asperiores minus distinctio debitis ipsa dolor. Minima eos deleniti."] +Faker::Lorem::Ipsum.paragraphs(1) #=> ["Labore voluptas sequi. Ratione nulla eaque quia molestiae fugit. At quam laboriosam aut ut dignissimos."] +Faker::Lorem::Ipsum.paragraphs(1, true) #=> ["Depulso animi cunctatio amicitia adficio. Vester viduo qui despirmatio voluptas. Validus laudantium adopto ut agnitio venustas. Aer arcus odio esse."] + +# Optional arguments: question_count = 3, supplemental = false +Faker::Lorem::Ipsum.question #=> "Aliquid culpa aut ipsam unde ullam labore?" +Faker::Lorem::Ipsum.questions(3) #=> ["Necessitatibus deserunt animi?", "At hic dolores autem consequatur ut?", "Aliquam velit ex adipisci voluptatem placeat?"] + +# Optional arguments: chars=3, supplemental=false +Faker::Lorem::Ipsum.paragraph_by_chars #=> "Truffaut stumptown trust fund 8-bit messenger bag portland. Meh kombucha selvage swag biodiesel. Lomo kinfolk jean shorts asymmetrical diy. Wayfarers portland twee stumptown. Wes anderson biodiesel retro 90's pabst. Diy echo 90's mixtape semiotics. Cornho." +Faker::Lorem::Ipsum.paragraph_by_chars(256, false) #=> "Hella kogi blog narwhal sartorial selfies mustache schlitz. Bespoke normcore kitsch cred hella fixie. Park aesthetic fixie migas twee. Cliche mustache brunch tumblr fixie godard. Drinking pop-up synth hoodie dreamcatcher typewriter. Kitsch biodiesel green." +``` diff --git a/doc/v2.0/lorem/pixel.md b/doc/v2.0/lorem/pixel.md new file mode 100644 index 0000000000..172325a48b --- /dev/null +++ b/doc/v2.0/lorem/pixel.md @@ -0,0 +1,21 @@ +# Faker::Lorem::Pixel + +Available since version 1.7.0. + +```ruby +Faker::Lorem::Pixel.image #=> "https://lorempixel.com/300/300" + +Faker::Lorem::Pixel.image("50x60") #=> "https://lorempixel.com/50/60" + +Faker::Lorem::Pixel.image("50x60", true) #=> "https://lorempixel.com/g/50/60" + +Faker::Lorem::Pixel.image("50x60", false, 'sports') #=> "https://lorempixel.com/50/60/sports" + +Faker::Lorem::Pixel.image("50x60", false, 'sports', 3) #=> "https://lorempixel.com/50/60/sports/3" + +Faker::Lorem::Pixel.image("50x60", false, 'sports', 3, 'Dummy-text') #=> "https://lorempixel.com/50/60/sports/3/Dummy-text" + +Faker::Lorem::Pixel.image("50x60", false, 'sports', nil, 'Dummy-text') #=> "https://lorempixel.com/50/60/sports/Dummy-text" + +Faker::Lorem::Pixel.image(secure: false) #=> "http://lorempixel.com/300/300" +``` diff --git a/lib/faker/default/hipster.rb b/lib/faker/default/hipster.rb deleted file mode 100644 index dc86e1a510..0000000000 --- a/lib/faker/default/hipster.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -module Faker - class Hipster < Base - class << self - def word - random_word = sample(translate('faker.hipster.words')) - random_word =~ /\s/ ? word : random_word - end - - def words(num = 3, supplemental = false, spaces_allowed = false) - resolved_num = resolve(num) - word_list = ( - translate('faker.hipster.words') + - (supplemental ? translate('faker.lorem.words') : []) - ) - word_list *= ((resolved_num / word_list.length) + 1) - - return shuffle(word_list)[0, resolved_num] if spaces_allowed - - words = shuffle(word_list)[0, resolved_num] - words.each_with_index { |w, i| words[i] = word if w =~ /\s/ } - end - - def sentence(word_count = 4, supplemental = false, random_words_to_add = 6) - words(word_count + rand(random_words_to_add.to_i).to_i, supplemental, true).join(' ').capitalize + '.' - end - - def sentences(sentence_count = 3, supplemental = false) - [].tap do |sentences| - 1.upto(resolve(sentence_count)) do - sentences << sentence(3, supplemental) - end - end - end - - def paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 3) - sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i, supplemental).join(' ') - end - - def paragraphs(paragraph_count = 3, supplemental = false) - [].tap do |paragraphs| - 1.upto(resolve(paragraph_count)) do - paragraphs << paragraph(3, supplemental) - end - end - end - - def paragraph_by_chars(chars = 256, supplemental = false) - paragraph = paragraph(3, supplemental) - - paragraph += ' ' + paragraph(3, supplemental) while paragraph.length < chars - - paragraph[0...chars - 1] + '.' - end - end - end -end diff --git a/lib/faker/default/lorem.rb b/lib/faker/default/lorem.rb deleted file mode 100644 index 097f3a739c..0000000000 --- a/lib/faker/default/lorem.rb +++ /dev/null @@ -1,80 +0,0 @@ -# frozen_string_literal: true - -module Faker - # Based on Perl's Text::Lorem - class Lorem < Base - class << self - def word - sample(translate('faker.lorem.words')) - end - - def words(num = 3, supplemental = false) - resolved_num = resolve(num) - word_list = ( - translate('faker.lorem.words') + - (supplemental ? translate('faker.lorem.supplemental') : []) - ) - word_list *= ((resolved_num / word_list.length) + 1) - shuffle(word_list)[0, resolved_num] - end - - def character - sample(Types::CHARACTERS) - end - - def characters(char_count = 255) - Alphanumeric.alphanumeric(char_count) - end - - def multibyte - sample(translate('faker.lorem.multibyte')).pack('C*').force_encoding('utf-8') - end - - def sentence(word_count = 4, supplemental = false, random_words_to_add = 0) - words(word_count + rand(random_words_to_add.to_i), supplemental).join(' ').capitalize + locale_period - end - - def sentences(sentence_count = 3, supplemental = false) - 1.upto(resolve(sentence_count)).collect { sentence(3, supplemental) } - end - - def paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 0) - sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i), supplemental).join(locale_space) - end - - def paragraphs(paragraph_count = 3, supplemental = false) - 1.upto(resolve(paragraph_count)).collect { paragraph(3, supplemental) } - end - - def paragraph_by_chars(chars = 256, supplemental = false) - paragraph = paragraph(3, supplemental) - - paragraph += ' ' + paragraph(3, supplemental) while paragraph.length < chars - - paragraph[0...chars - 1] + '.' - end - - def question(word_count = 4, supplemental = false, random_words_to_add = 0) - words(word_count + rand(random_words_to_add), supplemental).join(' ').capitalize + locale_question_mark - end - - def questions(question_count = 3, supplemental = false) - 1.upto(resolve(question_count)).collect { question(3, supplemental) } - end - - private - - def locale_period - translate('faker.lorem.punctuation.period') || '.' - end - - def locale_space - translate('faker.lorem.punctuation.space') || ' ' - end - - def locale_question_mark - translate('faker.lorem.punctuation.question_mark') || '?' - end - end - end -end diff --git a/lib/faker/default/lorem_pixel.rb b/lib/faker/default/lorem_pixel.rb deleted file mode 100644 index 9fbf007528..0000000000 --- a/lib/faker/default/lorem_pixel.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -module Faker - class LoremPixel < Base - class << self - SUPPORTED_CATEGORIES = %w[abstract - animals - business - cats - city - food - nightlife - fashion - people - nature - sports - technics - transport].freeze - - # rubocop:disable Metrics/ParameterLists - 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 - # rubocop:enable Metrics/ParameterLists - end - end -end diff --git a/lib/faker/deprecate/hipster.rb b/lib/faker/deprecate/hipster.rb new file mode 100644 index 0000000000..ad3d70de85 --- /dev/null +++ b/lib/faker/deprecate/hipster.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +module Faker + module Hipster + class << self + extend Gem::Deprecate + + def word + Faker::Lorem::Hipster.word + end + + def words(num = 3, supplemental = false, spaces_allowed = false) + Faker::Lorem::Hipster.words(num, supplemental, spaces_allowed) + end + + def sentence(word_count = 4, supplemental = false, random_words_to_add = 6) + Faker::Lorem::Hipster.sentence(word_count, supplemental, random_words_to_add) + end + + def sentences(sentence_count = 3, supplemental = false) + Faker::Lorem::Hipster.sentences(sentence_count, supplemental) + end + + def paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 3) + Faker::Lorem::Hipster.paragraph(sentence_count, supplemental, random_sentences_to_add) + end + + def paragraphs(paragraph_count = 3, supplemental = false) + Faker::Lorem::Hipster.paragraphs(paragraph_count, supplemental) + end + + def paragraph_by_chars(chars = 256, supplemental = false) + Faker::Lorem::Hipster.paragraph_by_chars(chars, supplemental) + end + + deprecate :word, 'Faker::Lorem::Hipster.word', 2018, 10 + deprecate :words, 'Faker::Lorem::Hipster.words', 2018, 10 + deprecate :sentence, 'Faker::Lorem::Hipster.sentence', 2018, 10 + deprecate :sentences, 'Faker::Lorem::Hipster.sentences', 2018, 10 + deprecate :paragraph, 'Faker::Lorem::Hipster.paragraph', 2018, 10 + deprecate :paragraphs, 'Faker::Lorem::Hipster.paragraphs', 2018, 10 + deprecate :paragraph_by_chars, 'Faker::Lorem::Hipster.paragraph_by_chars', 2018, 10 + end + end +end diff --git a/lib/faker/deprecate/lorem.rb b/lib/faker/deprecate/lorem.rb new file mode 100644 index 0000000000..e48f55eaa2 --- /dev/null +++ b/lib/faker/deprecate/lorem.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +module Faker + module Lorem + class << self + extend Gem::Deprecate + + def word + Faker::Lorem::Ipsum.word + end + + def words(num = 3, supplemental = false) + Faker::Lorem::Ipsum.words(num, supplemental) + end + + def character + Faker::Lorem::Ipsum.character + end + + def characters(char_count = 255) + Alphanumeric.alphanumeric(char_count) + end + + def multibyte + Faker::Lorem::Ipsum.multibyte + end + + def sentence(word_count = 4, supplemental = false, random_words_to_add = 0) + Faker::Lorem::Ipsum.sentence(word_count, supplemental, random_words_to_add) + end + + def sentences(sentence_count = 3, supplemental = false) + Faker::Lorem::Ipsum.sentences(sentence_count, supplemental) + end + + def paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 0) + Faker::Lorem::Ipsum.paragraph(sentence_count, supplemental, random_sentences_to_add) + end + + def paragraphs(paragraph_count = 3, supplemental = false) + Faker::Lorem::Ipsum.paragraphs(paragraph_count, supplemental) + end + + def paragraph_by_chars(chars = 256, supplemental = false) + Faker::Lorem::Ipsum.paragraph_by_chars(chars, supplemental) + end + + def question(word_count = 4, supplemental = false, random_words_to_add = 0) + Faker::Lorem::Ipsum.question(word_count, supplemental, random_words_to_add) + end + + def questions(question_count = 3, supplemental = false) + Faker::Lorem::Ipsum.questions(question_count, supplemental) + end + + deprecate :word, 'Faker::Lorem::Ipsum.word', 2018, 10 + deprecate :words, 'Faker::Lorem::Ipsum.words', 2018, 10 + deprecate :character, 'Faker::Lorem::Ipsum.character', 2018, 10 + deprecate :multibyte, 'Faker::Lorem::Ipsum.multibyte', 2018, 10 + deprecate :sentence, 'Faker::Lorem::Ipsum.sentence', 2018, 10 + deprecate :sentences, 'Faker::Lorem::Ipsum.sentences', 2018, 10 + deprecate :paragraph, 'Faker::Lorem::Ipsum.paragraph', 2018, 10 + deprecate :paragraphs, 'Faker::Lorem::Ipsum.paragraphs', 2018, 10 + deprecate :paragraph_by_chars, 'Faker::Lorem::Ipsum.paragraph_by_chars', 2018, 10 + deprecate :question, 'Faker::Lorem::Ipsum.question', 2018, 10 + deprecate :questions, 'Faker::Lorem::Ipsum.questions', 2018, 10 + end + end +end diff --git a/lib/faker/default/lorem_flickr.rb b/lib/faker/deprecate/lorem_flickr.rb similarity index 54% rename from lib/faker/default/lorem_flickr.rb rename to lib/faker/deprecate/lorem_flickr.rb index c4658012fe..cc4ccdeca4 100644 --- a/lib/faker/default/lorem_flickr.rb +++ b/lib/faker/deprecate/lorem_flickr.rb @@ -1,31 +1,24 @@ # frozen_string_literal: true module Faker - class LoremFlickr < Base + module LoremFlickr class << self - SUPPORTED_COLORIZATIONS = %w[red green blue].freeze + extend Gem::Deprecate def image(size = '300x300', search_terms = [], match_all = false) - build_url(size, nil, search_terms, match_all) + Faker::Lorem::Flickr.image(size, search_terms, match_all) end def grayscale_image(size = '300x300', search_terms = ['all'], match_all = false) - raise ArgumentError, 'Search terms must be specified for grayscale images' unless search_terms.any? - - build_url(size, 'g', search_terms, match_all) + Faker::Lorem::Flickr.grayscale_image(size, search_terms, match_all) end def pixelated_image(size = '300x300', search_terms = ['all'], match_all = false) - raise ArgumentError, 'Search terms must be specified for pixelated images' unless search_terms.any? - - build_url(size, 'p', search_terms, match_all) + Faker::Lorem::Flickr.pixelated_image(size, search_terms, match_all) end def colorized_image(size = '300x300', color = 'red', search_terms = ['all'], match_all = false) - raise ArgumentError, 'Search terms must be specified for colorized images' unless search_terms.any? - raise ArgumentError, "Supported colorizations are #{SUPPORTED_COLORIZATIONS.join(', ')}" unless SUPPORTED_COLORIZATIONS.include?(color) - - build_url(size, color, search_terms, match_all) + Faker::Lorem::Flickr.colorized_image(size, color, search_terms, match_all) end private @@ -40,6 +33,11 @@ def build_url(size, format, search_terms, match_all) url_parts << 'all' if match_all url_parts.compact.join('/') end + + deprecate :image, 'Faker::Lorem::Flickr.image', 2018, 10 + deprecate :grayscale_image, 'Faker::Lorem::Flickr.grayscale_image', 2018, 10 + deprecate :pixelated_image, 'Faker::Lorem::Flickr.pixelated_image', 2018, 10 + deprecate :colorized_image, 'Faker::Lorem::Flickr.colorized_image', 2018, 10 end end end diff --git a/lib/faker/deprecate/lorem_pixel.rb b/lib/faker/deprecate/lorem_pixel.rb new file mode 100644 index 0000000000..a47e97c7a0 --- /dev/null +++ b/lib/faker/deprecate/lorem_pixel.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module Faker + module LoremPixel + 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 + def image(size = '300x300', is_gray = false, category = nil, number = nil, text = nil, secure: true) + Faker::Lorem::Pixel.image(size, is_gray, category, number, text, secure: secure) + end + # rubocop:enable Metrics/ParameterLists + + deprecate :image, 'Faker::Lorem::Pixel.image', 2018, 10 + end + end +end diff --git a/lib/faker/lorem/flickr.rb b/lib/faker/lorem/flickr.rb new file mode 100644 index 0000000000..c2d0da8171 --- /dev/null +++ b/lib/faker/lorem/flickr.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module Faker + module Lorem + class Flickr < Base + SUPPORTED_COLORIZATIONS = %w[red green blue].freeze + + class << self + def image(size = '300x300', search_terms = [], match_all = false) + build_url(size, nil, search_terms, match_all) + end + + def grayscale_image(size = '300x300', search_terms = ['all'], match_all = false) + raise ArgumentError, 'Search terms must be specified for grayscale images' unless search_terms.any? + + build_url(size, 'g', search_terms, match_all) + end + + def pixelated_image(size = '300x300', search_terms = ['all'], match_all = false) + raise ArgumentError, 'Search terms must be specified for pixelated images' unless search_terms.any? + + build_url(size, 'p', search_terms, match_all) + end + + def colorized_image(size = '300x300', color = 'red', search_terms = ['all'], match_all = false) + raise ArgumentError, 'Search terms must be specified for colorized images' unless search_terms.any? + raise ArgumentError, "Supported colorizations are #{SUPPORTED_COLORIZATIONS.join(', ')}" unless SUPPORTED_COLORIZATIONS.include?(color) + + build_url(size, color, search_terms, match_all) + end + + private + + def build_url(size, format, search_terms, match_all) + raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /^[0-9]+x[0-9]+$/ + + url_parts = ['http://loremflickr.com'] + url_parts << format + url_parts += size.split('x') + url_parts << search_terms.compact.join(',') if search_terms.any? + url_parts << 'all' if match_all + url_parts.compact.join('/') + end + end + end + end +end diff --git a/lib/faker/lorem/hipster.rb b/lib/faker/lorem/hipster.rb new file mode 100644 index 0000000000..791e1a3a29 --- /dev/null +++ b/lib/faker/lorem/hipster.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +module Faker + module Lorem + class Hipster < Base + class << self + def word + random_word = sample(translate('faker.hipster.words')) + random_word =~ /\s/ ? word : random_word + end + + def words(num = 3, supplemental = false, spaces_allowed = false) + resolved_num = resolve(num) + word_list = ( + translate('faker.hipster.words') + + (supplemental ? translate('faker.lorem.words') : []) + ) + word_list *= ((resolved_num / word_list.length) + 1) + + return shuffle(word_list)[0, resolved_num] if spaces_allowed + + words = shuffle(word_list)[0, resolved_num] + words.each_with_index { |w, i| words[i] = word if w =~ /\s/ } + end + + def sentence(word_count = 4, supplemental = false, random_words_to_add = 6) + words(word_count + rand(random_words_to_add.to_i).to_i, supplemental, true).join(' ').capitalize + '.' + end + + def sentences(sentence_count = 3, supplemental = false) + [].tap do |sentences| + 1.upto(resolve(sentence_count)) do + sentences << sentence(3, supplemental) + end + end + end + + def paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 3) + sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i, supplemental).join(' ') + end + + def paragraphs(paragraph_count = 3, supplemental = false) + [].tap do |paragraphs| + 1.upto(resolve(paragraph_count)) do + paragraphs << paragraph(3, supplemental) + end + end + end + + def paragraph_by_chars(chars = 256, supplemental = false) + paragraph = paragraph(3, supplemental) + + paragraph += ' ' + paragraph(3, supplemental) while paragraph.length < chars + + paragraph[0...chars - 1] + '.' + end + end + end + end +end diff --git a/lib/faker/lorem/ipsum.rb b/lib/faker/lorem/ipsum.rb new file mode 100644 index 0000000000..a72eeb8154 --- /dev/null +++ b/lib/faker/lorem/ipsum.rb @@ -0,0 +1,86 @@ +# frozen_string_literal: true + +module Faker + module Lorem + class Ipsum < Base + CHARACTERS = ('0'..'9').to_a + ('a'..'z').to_a + + class << self + def word + sample(translate('faker.lorem.words')) + end + + def words(num = 3, supplemental = false) + resolved_num = resolve(num) + word_list = ( + translate('faker.lorem.words') + + (supplemental ? translate('faker.lorem.supplemental') : []) + ) + word_list *= ((resolved_num / word_list.length) + 1) + shuffle(word_list)[0, resolved_num] + end + + def character + sample(CHARACTERS) + end + + def characters(char_count = 255) + char_count = resolve(char_count) + return '' if char_count.to_i < 1 + + Array.new(char_count) { sample(CHARACTERS) }.join + end + + def multibyte + sample(translate('faker.lorem.multibyte')).pack('C*').force_encoding('utf-8') + end + + def sentence(word_count = 4, supplemental = false, random_words_to_add = 0) + words(word_count + rand(random_words_to_add.to_i), supplemental).join(' ').capitalize + locale_period + end + + def sentences(sentence_count = 3, supplemental = false) + 1.upto(resolve(sentence_count)).collect { sentence(3, supplemental) } + end + + def paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 0) + sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i), supplemental).join(locale_space) + end + + def paragraphs(paragraph_count = 3, supplemental = false) + 1.upto(resolve(paragraph_count)).collect { paragraph(3, supplemental) } + end + + def paragraph_by_chars(chars = 256, supplemental = false) + paragraph = paragraph(3, supplemental) + + paragraph += ' ' + paragraph(3, supplemental) while paragraph.length < chars + + paragraph[0...chars - 1] + '.' + end + + def question(word_count = 4, supplemental = false, random_words_to_add = 0) + words(word_count + rand(random_words_to_add), supplemental).join(' ').capitalize + locale_question_mark + end + + def questions(question_count = 3, supplemental = false) + 1.upto(resolve(question_count)).collect { question(3, supplemental) } + end + + private + + def locale_period + translate('faker.lorem.punctuation.period') || '.' + end + + def locale_space + translate('faker.lorem.punctuation.space') || ' ' + end + + def locale_question_mark + translate('faker.lorem.punctuation.question_mark') || '?' + end + end + end + end +end diff --git a/lib/faker/lorem/pixel.rb b/lib/faker/lorem/pixel.rb new file mode 100644 index 0000000000..9e5e5f98fe --- /dev/null +++ b/lib/faker/lorem/pixel.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +module Faker + module Lorem + class Pixel < Base + class << self + SUPPORTED_CATEGORIES = %w[abstract + animals + business + cats + city + food + nightlife + fashion + people + nature + sports + technics + transport].freeze + + # rubocop:disable Metrics/ParameterLists + 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 + # rubocop:enable Metrics/ParameterLists + end + end + end +end diff --git a/test/deprecate/test_deprecate_lorem.rb b/test/deprecate/test_deprecate_lorem.rb new file mode 100644 index 0000000000..d11ad96f6b --- /dev/null +++ b/test/deprecate/test_deprecate_lorem.rb @@ -0,0 +1,120 @@ +# frozen_string_literal: true + +require_relative '../test_helper' + +class TestDeprecateLorem < Test::Unit::TestCase + def setup + @tester = Faker::Lorem + @standard_wordlist = I18n.translate('faker.lorem.words') + @complete_wordlist = + @standard_wordlist + I18n.translate('faker.lorem.supplemental') + end + + def test_character + assert @tester.character.length == 1 + end + + def test_character_type + assert @tester.character.class == String + end + + def test_characters + assert @tester.characters.length == 255 + end + + def test_characters_negatives + assert_equal '', @tester.characters(-1) + assert_equal '', @tester.characters((-2..-1)) + assert_equal '', @tester.characters([-1, -2]) + end + + def test_characters_with_args + 100.times { assert @tester.characters(500).length == 500 } + end + + # Words delivered by a standard request should be on the standard wordlist. + def test_standard_words + @words = @tester.words(1000) + @words.each { |w| assert @standard_wordlist.include?(w) } + end + + # Words requested from the supplemental list should all be in that list. + def test_supplemental_words + @words = @tester.words(10_000, true) + @words.each { |w| assert @complete_wordlist.include?(w) } + end + + # Faker::Lorem.word generates random word from standart wordlist + def test_word + @tester = Faker::Lorem + @standard_wordlist = I18n.translate('faker.lorem.words') + 100.times { assert @standard_wordlist.include?(@tester.word) } + end + + def test_exact_sentence_word_count + assert_equal 2, @tester.sentence(2, false, 0).split(' ').length + end + + def test_exact_count_param + assert(@tester.characters(2).length == 2) + assert(@tester.words(2).length == 2) + assert(@tester.sentences(2).length == 2) + assert(@tester.paragraphs(2).length == 2) + end + + def test_range_count_param + cs = @tester.characters(2..5) + ws = @tester.words(2..5) + ss = @tester.sentences(2..5) + ps = @tester.paragraphs(2..5) + + assert(cs.length >= 2 && cs.length <= 5) + assert(ws.length >= 2 && ws.length <= 5) + assert(ss.length >= 2 && ss.length <= 5) + assert(ps.length >= 2 && ps.length <= 5) + end + + def test_exclusive_range_count_param + cs = @tester.characters(2...3) + ws = @tester.words(2...3) + ss = @tester.sentences(2...3) + ps = @tester.paragraphs(2...3) + + assert_equal(2, cs.length) + assert_equal(2, ws.length) + assert_equal(2, ss.length) + assert_equal(2, ps.length) + end + + def test_array_count_param + cs = @tester.characters([1, 4]) + ws = @tester.words([1, 4]) + ss = @tester.sentences([1, 4]) + ps = @tester.paragraphs([1, 4]) + + assert(cs.length == 1 || cs.length == 4) + assert(ws.length == 1 || ws.length == 4) + assert(ss.length == 1 || ss.length == 4) + assert(ps.length == 1 || ps.length == 4) + end + + def test_words_with_large_count_params + exact = @tester.words(500) + range = @tester.words(250..500) + array = @tester.words([250, 500]) + + assert(exact.length == 500) + assert(range.length >= 250 && range.length <= 500) + assert(array.length == 250 || array.length == 500) + end + + def test_multibyte + assert @tester.multibyte.is_a? String + assert %w[😀 ❤ 😡].include?(@tester.multibyte) + end + + def test_paragraph_char_count + paragraph = @tester.paragraph_by_chars(256) + assert(paragraph.length == 256) + end +end diff --git a/test/deprecate/test_deprecate_lorem_flickr.rb b/test/deprecate/test_deprecate_lorem_flickr.rb new file mode 100644 index 0000000000..4cde5695a4 --- /dev/null +++ b/test/deprecate/test_deprecate_lorem_flickr.rb @@ -0,0 +1,126 @@ +# frozen_string_literal: true + +require_relative '../test_helper' + +class TestDeprecateLoremFlickr < Test::Unit::TestCase + def setup + @tester = Faker::LoremFlickr + @colorizations = %w[red green blue] + end + + def test_image + assert @tester.image == 'http://loremflickr.com/300/300' + end + + def test_image_with_size + assert @tester.image('50x60') == 'http://loremflickr.com/50/60' + end + + def test_image_with_incorrect_size + assert_raise ArgumentError do + @tester.image('300x300s') + end + end + + def test_image_with_single_search_term + assert @tester.image('50x60', %w[faker]) == 'http://loremflickr.com/50/60/faker' + end + + def test_image_with_multiple_search_terms + assert @tester.image('50x60', %w[dog cat]) == 'http://loremflickr.com/50/60/dog,cat' + end + + def test_image_with_search_terms_and_match_all + assert @tester.image('50x60', %w[dog cat], true) == 'http://loremflickr.com/50/60/dog,cat/all' + end + + def test_grayscale_image + @tester.grayscale_image == 'http://loremflickr.com/g/300/300/all' + end + + def test_grayscale_image_with_incorrect_size + assert_raise ArgumentError do + @tester.grayscale_image('300x300s') + end + end + + def test_grayscale_image_without_search_terms + @tester.grayscale_image('50x60') == 'http://loremflickr.com/g/50/60/all' + end + + def test_grayscale_image_with_single_search_term + assert @tester.grayscale_image('50x60', %w[faker]) == 'http://loremflickr.com/g/50/60/faker' + end + + def test_grayscale_image_with_multiple_search_terms + assert @tester.grayscale_image('50x60', %w[dog cat]) == 'http://loremflickr.com/g/50/60/dog,cat' + end + + def test_grayscale_image_with_search_terms_and_match_all + assert @tester.grayscale_image('50x60', %w[dog cat], true) == 'http://loremflickr.com/g/50/60/dog,cat/all' + end + + def test_pixelated_image + @tester.pixelated_image == 'http://loremflickr.com/p/300/300/all' + end + + def test_pixelated_image_with_incorrect_size + assert_raise ArgumentError do + @tester.pixelated_image('300x300s') + end + end + + def test_pixelated_image_without_search_terms + @tester.pixelated_image('50x60') == 'http://loremflickr.com/p/50/60/all' + end + + def test_pixelated_image_with_single_search_term + assert @tester.pixelated_image('50x60', %w[faker]) == 'http://loremflickr.com/p/50/60/faker' + end + + def test_pixelated_image_with_multiple_search_terms + assert @tester.pixelated_image('50x60', %w[dog cat]) == 'http://loremflickr.com/p/50/60/dog,cat' + end + + def test_pixelated_image_with_search_terms_and_match_all + assert @tester.pixelated_image('50x60', %w[dog cat], true) == 'http://loremflickr.com/p/50/60/dog,cat/all' + end + + def test_colorized_image + @tester.colorized_image == 'http://loremflickr.com/red/300/300/all' + end + + def test_colorized_image_with_incorrect_size + assert_raise ArgumentError do + @tester.colorized_image('300x300s') + end + end + + def test_colorized_image_without_search_terms + @tester.colorized_image('50x60', 'red') == 'http://loremflickr.com/red/50/60/all' + end + + def test_colorized_image_with_unsupported_colorization + assert_raise ArgumentError do + @tester.colorized_image('50x60', 'yellow') + end + end + + def test_colorized_image_with_single_search_term + @colorizations.each do |colorization| + assert @tester.colorized_image('50x60', colorization, %w[faker]) == "http://loremflickr.com/#{colorization}/50/60/faker" + end + end + + def test_colorized_image_with_multiple_search_terms + @colorizations.each do |colorization| + assert @tester.colorized_image('50x60', colorization, %w[dog cat]) == "http://loremflickr.com/#{colorization}/50/60/dog,cat" + end + end + + def test_colorized_image_with_search_terms_and_match_all + @colorizations.each do |colorization| + assert @tester.colorized_image('50x60', colorization, %w[dog cat], true) == "http://loremflickr.com/#{colorization}/50/60/dog,cat/all" + end + end +end diff --git a/test/deprecate/test_deprecate_lorem_hipster.rb b/test/deprecate/test_deprecate_lorem_hipster.rb new file mode 100644 index 0000000000..98f03ed846 --- /dev/null +++ b/test/deprecate/test_deprecate_lorem_hipster.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +require_relative '../test_helper' + +class TestDeprecateHipster < Test::Unit::TestCase + def setup + @tester = Faker::Hipster + @standard_wordlist = I18n.translate('faker.hipster.words') + @complete_wordlist = + @standard_wordlist + I18n.translate('faker.lorem.words') + end + + # Words delivered by a standard request should be on the standard wordlist. + def test_words + @words = @tester.words(1000) + @words.each { |w| assert @standard_wordlist.include?(w) } + end + + # Words should not return any word with spaces + def test_words_without_spaces + @words = @tester.words(1000) + @words.each { |w| assert !w.match(/\s/) } + end + + # Words requested from the supplemental list should all be in that list. + def test_supplemental_words + @words = @tester.words(10_000, true) + @words.each { |w| assert @complete_wordlist.include?(w) } + end + + # Faker::Hipster.word generates random word from standart wordlist + def test_word + @tester = Faker::Hipster + @standard_wordlist = I18n.translate('faker.hipster.words') + 1000.times { assert @standard_wordlist.include?(@tester.word) } + end + + # Word should not return any word with spaces + def test_word_without_spaces + @tester = Faker::Hipster + 1000.times { assert !@tester.word.match(/\s/) } + end + + def test_exact_count_param + assert(@tester.words(2).length == 2) + assert(@tester.sentences(2).length == 2) + assert(@tester.paragraphs(2).length == 2) + end + + def test_range_count_param + ws = @tester.words(2..5) + ss = @tester.sentences(2..5) + ps = @tester.paragraphs(2..5) + + assert(ws.length >= 2 && ws.length <= 5) + assert(ss.length >= 2 && ss.length <= 5) + assert(ps.length >= 2 && ps.length <= 5) + end + + def test_array_count_param + ws = @tester.words([1, 4]) + ss = @tester.sentences([1, 4]) + ps = @tester.paragraphs([1, 4]) + + assert(ws.length == 1 || ws.length == 4) + assert(ss.length == 1 || ss.length == 4) + assert(ps.length == 1 || ps.length == 4) + end + + def test_words_with_large_count_params + exact = @tester.words(500) + range = @tester.words(250..500) + array = @tester.words([250, 500]) + + assert(exact.length == 500) + assert(range.length >= 250 && range.length <= 500) + assert(array.length == 250 || array.length == 500) + end + + def test_paragraph_char_count + paragraph = @tester.paragraph_by_chars(256) + assert(paragraph.length == 256) + end +end diff --git a/test/deprecate/test_deprecate_lorem_pixel.rb b/test/deprecate/test_deprecate_lorem_pixel.rb new file mode 100644 index 0000000000..c45f6f0ec6 --- /dev/null +++ b/test/deprecate/test_deprecate_lorem_pixel.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +require_relative '../test_helper' + +class TestDeprecateLoremPixel < Test::Unit::TestCase + def setup + @tester = Faker::LoremPixel + end + + def test_lorempixel + assert !@tester.image.match(%r{https:\/\/lorempixel\.com\/(\d+\/\d+)})[1].nil? + end + + def test_lorempixel_insecure + assert !@tester.image('300x300', nil, nil, nil, nil, secure: false).match(%r{http:\/\/lorempixel\.com\/(\d+\/\d+)})[1].nil? + end + + def test_image_with_custom_size + assert @tester.image('3x3').match(%r{https:\/\/lorempixel\.com\/(\d+\/\d+)})[1] == '3/3' + end + + def test_image_with_incorrect_size + assert_raise ArgumentError do + @tester.image('300x300s') + end + end + + def test_image_gray + assert @tester.image('300x300', true).match(%r{https:\/\/lorempixel\.com\/g\/\d+\/\d+}) + end + + def test_image_with_supported_category + assert @tester.image('300x300', false, 'animals').match(%r{https:\/\/lorempixel\.com\/\d+\/\d+\/(.*)})[1] == 'animals' + end + + def test_image_with_incorrect_category + assert_raise ArgumentError do + @tester.image('300x300', false, 'wrong_category') + end + end + + def test_image_with_supported_category_and_correct_number + assert @tester.image('300x300', false, 'animals', 3).match(%r{https:\/\/lorempixel\.com\/\d+\/\d+\/.+\/(\d+)})[1] == '3' + end + + def test_image_with_supported_category_and_incorrect_number + assert_raise ArgumentError do + @tester.image('300x300', false, 'animals', 11) + end + end + + def test_image_with_correct_number_and_without_category + assert_raise ArgumentError do + @tester.image('300x300', false, 'wrong_category', 3) + end + end + + def test_image_with_text_correct_number_and_supported_category + assert @tester.image('300x300', false, 'animals', 3, 'Dummy-text').match(%r{https:\/\/lorempixel\.com\/\d+\/\d+\/.+\/3\/(.+)})[1] == 'Dummy-text' + end + + def test_image_with_text_supported_category_and_text_without_number + assert @tester.image('300x300', false, 'animals', nil, 'Dummy-text').match(%r{https:\/\/lorempixel\.com\/\d+\/\d+\/.+\/(.+)})[1] == 'Dummy-text' + end + + def test_image_with_text_without_number_and_category + assert_raise ArgumentError do + @tester.image('300x300', false, nil, nil, 'Dummy-text') + end + end +end diff --git a/test/faker/default/test_faker_hipster.rb b/test/faker/lorem/test_hipster.rb similarity index 98% rename from test/faker/default/test_faker_hipster.rb rename to test/faker/lorem/test_hipster.rb index 830fedd7dc..bc48d86f5b 100644 --- a/test/faker/default/test_faker_hipster.rb +++ b/test/faker/lorem/test_hipster.rb @@ -4,7 +4,7 @@ class TestFakerHipster < Test::Unit::TestCase def setup - @tester = Faker::Hipster + @tester = Faker::Lorem::Hipster @standard_wordlist = I18n.translate('faker.hipster.words') @complete_wordlist = @standard_wordlist + I18n.translate('faker.lorem.words') diff --git a/test/faker/default/test_faker_lorem.rb b/test/faker/lorem/test_lorem.rb similarity index 93% rename from test/faker/default/test_faker_lorem.rb rename to test/faker/lorem/test_lorem.rb index 3b2d96b7da..9a4c1502f4 100644 --- a/test/faker/default/test_faker_lorem.rb +++ b/test/faker/lorem/test_lorem.rb @@ -117,10 +117,4 @@ def test_paragraph_char_count paragraph = @tester.paragraph_by_chars(256) assert(paragraph.length == 256) end - - def test_unique_with_already_set_values - values = ('a'..'z').to_a + ('0'..'9').to_a - @tester.unique.exclude(:character, [], values) - assert_raise(Faker::UniqueGenerator::RetryLimitExceeded) { @tester.unique.character } - end end diff --git a/test/faker/default/test_faker_lorem_flickr.rb b/test/faker/lorem/test_lorem_flickr.rb similarity index 99% rename from test/faker/default/test_faker_lorem_flickr.rb rename to test/faker/lorem/test_lorem_flickr.rb index 283589ef71..3e4cb31a26 100644 --- a/test/faker/default/test_faker_lorem_flickr.rb +++ b/test/faker/lorem/test_lorem_flickr.rb @@ -4,7 +4,7 @@ class TestFakerLoremFlickr < Test::Unit::TestCase def setup - @tester = Faker::LoremFlickr + @tester = Faker::Lorem::Flickr @colorizations = %w[red green blue] end diff --git a/test/faker/default/test_lorem_pixel.rb b/test/faker/lorem/test_lorem_pixel.rb similarity index 96% rename from test/faker/default/test_lorem_pixel.rb rename to test/faker/lorem/test_lorem_pixel.rb index 32b9b62c6f..b142aaed3b 100644 --- a/test/faker/default/test_lorem_pixel.rb +++ b/test/faker/lorem/test_lorem_pixel.rb @@ -2,9 +2,9 @@ require_relative '../../test_helper' -class TestLoremPixel < Test::Unit::TestCase +class TestFakerLoremPixel < Test::Unit::TestCase def setup - @tester = Faker::LoremPixel + @tester = Faker::Lorem::Pixel end def test_lorempixel diff --git a/test/test_determinism.rb b/test/test_determinism.rb index ff6fa92609..2d2ce64b30 100644 --- a/test/test_determinism.rb +++ b/test/test_determinism.rb @@ -45,7 +45,7 @@ def all_methods def subclasses Faker.constants.delete_if do |subclass| - %i[Base Bank Books Cat Char Base58 ChileRut Config Creature Date Dog DragonBall Dota ElderScrolls Fallout Games GamesHalfLife HeroesOfTheStorm Internet JapaneseMedia LeagueOfLegends Movies Myst Overwatch OnePiece Pokemon SwordArtOnline TvShows Time VERSION Witcher WorldOfWarcraft Zelda].include?(subclass) + %i[Base Bank Books Cat Char Base58 ChileRut Config Creature Date Dog DragonBall Dota ElderScrolls Fallout Games GamesHalfLife HeroesOfTheStorm Lorem LoremFlickr LoremPixel Hipster Internet JapaneseMedia LeagueOfLegends Movies Myst Overwatch OnePiece Pokemon SwordArtOnline TvShows Time VERSION Witcher WorldOfWarcraft Zelda].include?(subclass) end.sort end diff --git a/unreleased_README.md b/unreleased_README.md index 6df1a10e14..3cbf201aa2 100644 --- a/unreleased_README.md +++ b/unreleased_README.md @@ -27,6 +27,7 @@ development. - [Creature](#creature) - [Games](#games) - [Japanese Media](#japanese-media) + - [Lorem](#lorem) - [Movies](#movies) - [Music](#music) - [Quotes](#quotes) @@ -159,7 +160,6 @@ gem 'faker', :git => 'https://github.com/stympy/faker.git', :branch => 'master' - [Faker::Gender](doc/unreleased/default/gender.md) - [Faker::GreekPhilosophers](doc/unreleased/default/greek_philosophers.md) - [Faker::Hacker](doc/unreleased/default/hacker.md) - - [Faker::Hipster](doc/unreleased/default/hipster.md) - [Faker::House](doc/unreleased/default/house.md) - [Faker::IDNumber](doc/unreleased/default/id_number.md) - [Faker::IndustrySegments](doc/unreleased/default/industry_segments.md) @@ -168,9 +168,6 @@ gem 'faker', :git => 'https://github.com/stympy/faker.git', :branch => 'master' - [Faker::Job](doc/unreleased/default/job.md) - [Faker::Json](doc/unreleased/default/json.md) - [Faker::Kpop](doc/unreleased/default/kpop.md) - - [Faker::Lorem](doc/unreleased/default/lorem.md) - - [Faker::LoremFlickr](doc/unreleased/default/lorem_flickr.md) - - [Faker::LoremPixel](doc/unreleased/default/lorem_pixel.md) - [Faker::Markdown](doc/unreleased/default/markdown.md) - [Faker::Marketing](doc/unreleased/default/marketing.md) - [Faker::Measurement](doc/unreleased/default/measurement.md) @@ -242,6 +239,12 @@ gem 'faker', :git => 'https://github.com/stympy/faker.git', :branch => 'master' - [Faker::JapaneseMedia::OnePiece](doc/unreleased/japanese_media/one_piece.md) - [Faker::JapaneseMedia::SwordArtOnline](doc/unreleased/japanese_media/sword_art_online.md) +### Lorem + - [Faker::Lorem::Flickr](doc/v2.0/lorem/flickr.md) + - [Faker::Lorem::Hipster](doc/v2.0/lorem/hipster.md) + - [Faker::Lorem::Ipsum](doc/v2.0/lorem/ipsum.md) + - [Faker::Lorem::Pixel](doc/v2.0/lorem/pixel.md) + ### Movies - [Faker::Movie](doc/unreleased/movies/movie.md) - [Faker::Movies::BackToTheFuture](doc/unreleased/movies/back_to_the_future.md)