From 5f73c4d36e8406af45905fb58d6348bdce30b8b1 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Tue, 28 Aug 2018 03:52:32 -0300 Subject: [PATCH 01/15] Faker::Lorem => Faker::Lorem::Ipsum --- README.md | 2 +- doc/lorem.md | 54 -------------- doc/lorem_ipsum.md | 54 ++++++++++++++ lib/faker.rb | 2 + lib/faker/lorem.rb | 81 ++++++++------------- lib/faker/lorem/ipsum.rb | 95 +++++++++++++++++++++++++ test/test_determinism.rb | 2 +- test/test_faker_lorem.rb | 6 -- test/test_faker_lorem_ipsum.rb | 126 +++++++++++++++++++++++++++++++++ 9 files changed, 307 insertions(+), 115 deletions(-) delete mode 100644 doc/lorem.md create mode 100644 doc/lorem_ipsum.md create mode 100644 lib/faker/lorem/ipsum.rb create mode 100644 test/test_faker_lorem_ipsum.rb diff --git a/README.md b/README.md index badce951c6..f1571c2bbb 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ Contents - [Faker::LeagueOfLegends](doc/league_of_legends.md) - [Faker::Lebowski](doc/lebowski.md) - [Faker::LordOfTheRings](doc/lord_of_the_rings.md) - - [Faker::Lorem](doc/lorem.md) + - [Faker::Lorem::Ipsum](doc/lorem_ipsum.md) - [Faker::LoremFlickr](doc/lorem_flickr.md) - [Faker::LoremPixel](doc/lorem_pixel.md) - [Faker::Lovecraft](doc/lovecraft.md) diff --git a/doc/lorem.md b/doc/lorem.md deleted file mode 100644 index 73f5f13b6d..0000000000 --- a/doc/lorem.md +++ /dev/null @@ -1,54 +0,0 @@ -# Faker::Lorem - -```ruby -Faker::Lorem.word #=> "repellendus" - -# Optional arguments: num=3, supplemental=false (words from a supplementary list of Lorem-like words) -Faker::Lorem.words #=> ["dolores", "adipisci", "nesciunt"] -Faker::Lorem.words(4) #=> ["culpa", "recusandae", "aut", "omnis"] -Faker::Lorem.words(4, true) #=> ["colloco", "qui", "vergo", "deporto"] - -Faker::Lorem.multibyte #=> 😀 - -# Optional arguments: char_count=255 -Faker::Lorem.characters #=> "uw1ep04lhs0c4d931n1jmrspprf5wrj85fefue0y7y6m56b6omquh7br7dhqijwlawejpl765nb1716idmp3xnfo85v349pzy2o9rir23y2qhflwr71c1585fnynguiphkjm8p0vktwitcsm16lny7jzp9t4drwav3qmhz4yjq4k04x14gl6p148hulyqioo72tf8nwrxxcclfypz2lc58lsibgfe5w5p0xv95peafjjmm2frkhdc6duoky0aha" -Faker::Lorem.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.sentence #=> "Dolore illum animi et neque accusantium." -Faker::Lorem.sentence(3) #=> "Commodi qui minus deserunt sed vero quia." -Faker::Lorem.sentence(3, true) #=> "Inflammatio denego necessitatibus caelestis autus illum." -Faker::Lorem.sentence(3, false, 4) #=> "Aut voluptatem illum fugit ut sit." -Faker::Lorem.sentence(3, true, 4) #=> "Accusantium tantillus dolorem timor." - -# Optional arguments: sentence_count=3, supplemental=false -Faker::Lorem.sentences #=> ["Vero earum commodi soluta.", "Quaerat fuga cumque et vero eveniet omnis ut.", "Cumque sit dolor ut est consequuntur."] -Faker::Lorem.sentences(1) #=> ["Ut perspiciatis explicabo possimus doloribus enim quia."] -Faker::Lorem.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.paragraph #=> "Neque dicta enim quasi. Qui corrupti est quisquam. Facere animi quod aut. Qui nulla consequuntur consectetur sapiente." -Faker::Lorem.paragraph(2) #=> "Illo qui voluptas. Id sit quaerat enim aut cupiditate voluptates dolorum. Porro necessitatibus numquam dolor quia earum." -Faker::Lorem.paragraph(2, true) #=> "Cedo vero adipisci. Theatrum crustulum coaegresco tonsor crastinus stabilis. Aliqua crur consequatur amor una tolero sum." -Faker::Lorem.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.paragraph(2, true, 4) #=> "Vomito unde uxor annus. Et patior utilis sursum." - -# Optional arguments: paragraph_count=3, supplemental=false -Faker::Lorem.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.paragraphs(1) #=> ["Labore voluptas sequi. Ratione nulla eaque quia molestiae fugit. At quam laboriosam aut ut dignissimos."] -Faker::Lorem.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.question #=> "Aliquid culpa aut ipsam unde ullam labore?" -Faker::Lorem.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.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.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/lorem_ipsum.md b/doc/lorem_ipsum.md new file mode 100644 index 0000000000..26063d6a41 --- /dev/null +++ b/doc/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/lib/faker.rb b/lib/faker.rb index bfe7b46eee..057b5634a3 100644 --- a/lib/faker.rb +++ b/lib/faker.rb @@ -228,5 +228,7 @@ def rand(max = nil) Dir.glob(File.join(File.dirname(__FILE__), 'faker', '*.rb')).sort.each { |f| require f } +require 'faker/lorem/ipsum' + require 'helpers/char' require 'helpers/unique_generator' diff --git a/lib/faker/lorem.rb b/lib/faker/lorem.rb index 8379b9e334..003076c209 100644 --- a/lib/faker/lorem.rb +++ b/lib/faker/lorem.rb @@ -1,94 +1,69 @@ # frozen_string_literal: true module Faker - # Based on Perl's Text::Lorem - class Lorem < Base - CHARACTERS = ('0'..'9').to_a + ('a'..'z').to_a - + module Lorem class << self + extend Gem::Deprecate + def word - sample(translate('faker.lorem.words')) + Faker::Lorem::Ipsum.word 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] + Faker::Lorem::Ipsum.words(num, supplemental) end def character - sample(CHARACTERS) + Faker::Lorem::Ipsum.character 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 + Faker::Lorem::Ipsum.characters(char_count) end def multibyte - sample(translate('faker.lorem.multibyte')).pack('C*').force_encoding('utf-8') + Faker::Lorem::Ipsum.multibyte 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 + Faker::Lorem::Ipsum.sentence(word_count, supplemental, random_words_to_add) end def sentences(sentence_count = 3, supplemental = false) - 1.upto(resolve(sentence_count)).collect { sentence(3, supplemental) } + Faker::Lorem::Ipsum.sentences(sentence_count, 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) + Faker::Lorem::Ipsum.paragraph(sentence_count, supplemental, random_sentences_to_add) end def paragraphs(paragraph_count = 3, supplemental = false) - 1.upto(resolve(paragraph_count)).collect { paragraph(3, supplemental) } + Faker::Lorem::Ipsum.paragraphs(paragraph_count, 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] + '.' + Faker::Lorem::Ipsum.paragraph_by_chars(chars, supplemental) 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 + Faker::Lorem::Ipsum.question(word_count, supplemental, random_words_to_add) 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 - - # If an array or range is passed, a random value will be selected. - # All other values are simply returned. - def resolve(value) - case value - when Array then sample(value) - when Range then rand value - else value - end - end + 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/lorem/ipsum.rb b/lib/faker/lorem/ipsum.rb new file mode 100644 index 0000000000..7fd52c9de9 --- /dev/null +++ b/lib/faker/lorem/ipsum.rb @@ -0,0 +1,95 @@ +# 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 + + # If an array or range is passed, a random value will be selected. + # All other values are simply returned. + def resolve(value) + case value + when Array then sample(value) + when Range then rand value + else value + end + end + end + end + end +end diff --git a/test/test_determinism.rb b/test/test_determinism.rb index 6f8c47fa89..7e53323864 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 Char ChileRut Config Date Internet Time VERSION].include?(subclass) + %i[Base Bank Char ChileRut Config Date Internet Lorem Time VERSION].include?(subclass) end.sort end diff --git a/test/test_faker_lorem.rb b/test/test_faker_lorem.rb index 7baa2a1440..a8ddeff48e 100644 --- a/test/test_faker_lorem.rb +++ b/test/test_faker_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/test_faker_lorem_ipsum.rb b/test/test_faker_lorem_ipsum.rb new file mode 100644 index 0000000000..a4d413ee62 --- /dev/null +++ b/test/test_faker_lorem_ipsum.rb @@ -0,0 +1,126 @@ +# frozen_string_literal: true + +require_relative 'test_helper' + +class TestFakerLoremIpsum < Test::Unit::TestCase + def setup + @tester = Faker::Lorem::Ipsum + @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 + + 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 From 9daa4c05fddf7225ba2a5b39cb98c2938829abbc Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Tue, 28 Aug 2018 04:00:23 -0300 Subject: [PATCH 02/15] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e34f169f68..d01586a4c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - [PR #372](https://github.com/stympy/faker/pull/372) Add test_password_could_achieve_max_length [@oleksii-ti](https://github.com/oleksii-ti) ### Deprecation +- [PR #1349](https://github.com/stympy/faker/pull/1349) Add Namespace for Lorem - Faker::Lorem::Ipsum [@vbrazo](https://github.com/vbrazo) - [PR #803](https://github.com/stympy/faker/pull/803) Modify Faker::Educator, Fix #576 [@ghbooth12](https://github.com/ghbooth12) ### Documentation From 2e15483e35934a2f41c745fd20e0e672eab06376 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 26 Sep 2018 21:12:56 -0300 Subject: [PATCH 03/15] Faker::LoremFlickr => Faker::Lorem::Flickr --- lib/faker.rb | 1 + lib/faker/lorem/flickr.rb | 47 +++++++++++++ lib/faker/lorem_flickr.rb | 24 +++---- test/test_determinism.rb | 2 +- test/test_faker_lorem.rb | 120 -------------------------------- test/test_faker_lorem_flickr.rb | 2 +- 6 files changed, 61 insertions(+), 135 deletions(-) create mode 100644 lib/faker/lorem/flickr.rb delete mode 100644 test/test_faker_lorem.rb diff --git a/lib/faker.rb b/lib/faker.rb index 6e5a984cb2..196a224c3d 100644 --- a/lib/faker.rb +++ b/lib/faker.rb @@ -236,6 +236,7 @@ def rand(max = nil) Dir.glob(File.join(File.dirname(__FILE__), 'faker', '*.rb')).sort.each { |f| require f } require 'faker/lorem/ipsum' +require 'faker/lorem/flickr' require 'helpers/char' require 'helpers/unique_generator' 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_flickr.rb b/lib/faker/lorem_flickr.rb index c4658012fe..cc4ccdeca4 100644 --- a/lib/faker/lorem_flickr.rb +++ b/lib/faker/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/test/test_determinism.rb b/test/test_determinism.rb index 38ae799225..1c74793272 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 Char Base58 ChileRut Config Date Internet Lorem Time VERSION].include?(subclass) + %i[Base Bank Char Base58 ChileRut Config Date Internet Lorem LoremFlickr Time VERSION].include?(subclass) end.sort end diff --git a/test/test_faker_lorem.rb b/test/test_faker_lorem.rb deleted file mode 100644 index a8ddeff48e..0000000000 --- a/test/test_faker_lorem.rb +++ /dev/null @@ -1,120 +0,0 @@ -# frozen_string_literal: true - -require_relative 'test_helper' - -class TestFakerLorem < 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/test_faker_lorem_flickr.rb b/test/test_faker_lorem_flickr.rb index aaf28b97c3..a2f07872c1 100644 --- a/test/test_faker_lorem_flickr.rb +++ b/test/test_faker_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 From 2c255f31a55a2c81cfbd78e6eb133d4c2c143d12 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 26 Sep 2018 21:15:36 -0300 Subject: [PATCH 04/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e35323b611..4a9077badd 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ Contents - [Faker::Lebowski](doc/lebowski.md) - [Faker::LordOfTheRings](doc/lord_of_the_rings.md) - [Faker::Lorem::Ipsum](doc/lorem_ipsum.md) - - [Faker::LoremFlickr](doc/lorem_flickr.md) + - [Faker::Lorem::Flickr](doc/lorem_flickr.md) - [Faker::LoremPixel](doc/lorem_pixel.md) - [Faker::Lovecraft](doc/lovecraft.md) - [Faker::Markdown](doc/markdown.md) From 14f5b807c3e65d6a4b9c255c5ba91884aa4c1d64 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 26 Sep 2018 21:20:09 -0300 Subject: [PATCH 05/15] Faker::LoremPixel => Faker::Lorem::Pixel --- README.md | 4 ++-- lib/faker.rb | 1 + lib/faker/lorem/pixel.rb | 40 ++++++++++++++++++++++++++++++++++++++++ lib/faker/lorem_pixel.rb | 15 ++------------- test/test_determinism.rb | 2 +- test/test_lorem_pixel.rb | 2 +- 6 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 lib/faker/lorem/pixel.rb diff --git a/README.md b/README.md index e35323b611..a1ab88a213 100644 --- a/README.md +++ b/README.md @@ -107,8 +107,8 @@ Contents - [Faker::Lebowski](doc/lebowski.md) - [Faker::LordOfTheRings](doc/lord_of_the_rings.md) - [Faker::Lorem::Ipsum](doc/lorem_ipsum.md) - - [Faker::LoremFlickr](doc/lorem_flickr.md) - - [Faker::LoremPixel](doc/lorem_pixel.md) + - [Faker::Lorem::Flickr](doc/lorem_flickr.md) + - [Faker::Lorem::Pixel](doc/lorem_pixel.md) - [Faker::Lovecraft](doc/lovecraft.md) - [Faker::Markdown](doc/markdown.md) - [Faker::Matz](doc/matz.md) diff --git a/lib/faker.rb b/lib/faker.rb index 196a224c3d..d0fc8cc080 100644 --- a/lib/faker.rb +++ b/lib/faker.rb @@ -237,6 +237,7 @@ def rand(max = nil) require 'faker/lorem/ipsum' require 'faker/lorem/flickr' +require 'faker/lorem/pixel' require 'helpers/char' require 'helpers/unique_generator' 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/lib/faker/lorem_pixel.rb b/lib/faker/lorem_pixel.rb index 9fbf007528..bd0615f05f 100644 --- a/lib/faker/lorem_pixel.rb +++ b/lib/faker/lorem_pixel.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Faker - class LoremPixel < Base + module LoremPixel class << self SUPPORTED_CATEGORIES = %w[abstract animals @@ -19,18 +19,7 @@ class << self # 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('/') + Faker::Lorem::Pixel.image(size, is_gray, category, number, text, secure: secure) end # rubocop:enable Metrics/ParameterLists end diff --git a/test/test_determinism.rb b/test/test_determinism.rb index 1c74793272..c266b52ead 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 Char Base58 ChileRut Config Date Internet Lorem LoremFlickr Time VERSION].include?(subclass) + %i[Base Bank Char Base58 ChileRut Config Date Internet Lorem LoremFlickr LoremPixel Time VERSION].include?(subclass) end.sort end diff --git a/test/test_lorem_pixel.rb b/test/test_lorem_pixel.rb index d0137aa3aa..0ddfee3863 100644 --- a/test/test_lorem_pixel.rb +++ b/test/test_lorem_pixel.rb @@ -4,7 +4,7 @@ class TestLoremPixel < Test::Unit::TestCase def setup - @tester = Faker::LoremPixel + @tester = Faker::Lorem::Pixel end def test_lorempixel From 73f5b4f2a739e4ac00781531ef088efaeeac03b0 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 26 Sep 2018 21:22:16 -0300 Subject: [PATCH 06/15] Add deprecation warning for Lorem::Pixel --- lib/faker/lorem_pixel.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/faker/lorem_pixel.rb b/lib/faker/lorem_pixel.rb index bd0615f05f..a47e97c7a0 100644 --- a/lib/faker/lorem_pixel.rb +++ b/lib/faker/lorem_pixel.rb @@ -3,6 +3,8 @@ module Faker module LoremPixel class << self + extend Gem::Deprecate + SUPPORTED_CATEGORIES = %w[abstract animals business @@ -22,6 +24,8 @@ def image(size = '300x300', is_gray = false, category = nil, number = nil, text 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 From 9068323682d0af14b402c62ac56f0e2480674c0e Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 26 Sep 2018 21:26:40 -0300 Subject: [PATCH 07/15] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 864ecc0bdb..2f71912989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ - [PR #372](https://github.com/stympy/faker/pull/372) Add test_password_could_achieve_max_length [@oleksii-ti](https://github.com/oleksii-ti) ### Deprecation -- [PR #1349](https://github.com/stympy/faker/pull/1349) Add Namespace for Lorem - Faker::Lorem::Ipsum [@vbrazo](https://github.com/vbrazo) +- [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 #803](https://github.com/stympy/faker/pull/803) Modify Faker::Educator, Fix #576 [@ghbooth12](https://github.com/ghbooth12) ### Documentation From 47d3050cd82ed6b20f469065ea096d5a725cd04e Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 26 Sep 2018 21:28:33 -0300 Subject: [PATCH 08/15] Remove duplication --- lib/faker/lorem/ipsum.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/faker/lorem/ipsum.rb b/lib/faker/lorem/ipsum.rb index 7fd52c9de9..71d3a7e234 100644 --- a/lib/faker/lorem/ipsum.rb +++ b/lib/faker/lorem/ipsum.rb @@ -79,16 +79,6 @@ def locale_space def locale_question_mark translate('faker.lorem.punctuation.question_mark') || '?' end - - # If an array or range is passed, a random value will be selected. - # All other values are simply returned. - def resolve(value) - case value - when Array then sample(value) - when Range then rand value - else value - end - end end end end From c62f3061a10395c2832620eb9f3308b13f55a986 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 26 Sep 2018 21:42:40 -0300 Subject: [PATCH 09/15] Faker::Hipster => Faker::Lorem::Hipster --- README.md | 2 +- doc/hipster.md | 41 ------------- doc/lorem_hipster.md | 41 +++++++++++++ lib/faker.rb | 1 + lib/faker/hipster.rb | 46 ++++++--------- lib/faker/lorem/hipster.rb | 59 +++++++++++++++++++ test/test_determinism.rb | 2 +- ...hipster.rb => test_faker_lorem_hipster.rb} | 2 +- 8 files changed, 121 insertions(+), 73 deletions(-) delete mode 100644 doc/hipster.md create mode 100644 doc/lorem_hipster.md create mode 100644 lib/faker/lorem/hipster.rb rename test/{test_faker_hipster.rb => test_faker_lorem_hipster.rb} (98%) diff --git a/README.md b/README.md index a1ab88a213..3a7e6aad1d 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,6 @@ Contents - [Faker::Hacker](doc/hacker.md) - [Faker::HarryPotter](doc/harry_potter.md) - [Faker::HeyArnold](doc/hey_arnold.md) - - [Faker::Hipster](doc/hipster.md) - [Faker::HitchhikersGuideToTheGalaxy](doc/hitchhikers_guide_to_the_galaxy.md) - [Faker::Hobbit](doc/hobbit.md) - [Faker::HowIMetYourMother](doc/how_i_met_your_mother.md) @@ -106,6 +105,7 @@ Contents - [Faker::LeagueOfLegends](doc/league_of_legends.md) - [Faker::Lebowski](doc/lebowski.md) - [Faker::LordOfTheRings](doc/lord_of_the_rings.md) + - [Faker::Lorem::Hipster](doc/lorem_hipster.md) - [Faker::Lorem::Ipsum](doc/lorem_ipsum.md) - [Faker::Lorem::Flickr](doc/lorem_flickr.md) - [Faker::Lorem::Pixel](doc/lorem_pixel.md) diff --git a/doc/hipster.md b/doc/hipster.md deleted file mode 100644 index 1ee1e1f48e..0000000000 --- a/doc/hipster.md +++ /dev/null @@ -1,41 +0,0 @@ -# Faker::Hipster - -Adapted from [Hipster Ipsum](http://hipsum.co/) - -```ruby -Faker::Hipster.word #=> "irony" - -# Optional arguments: num=3, supplemental=false, spaces_allowed = false -Faker::Hipster.words #=> ["pug", "pitchfork", "chia"] -Faker::Hipster.words(4) #=> ["ugh", "cardigan", "poutine", "stumptown"] -Faker::Hipster.words(4, true) #=> ["iste", "seitan", "normcore", "provident"] -Faker::Hipster.words(4, true, true) #=> ["qui", "magni", "craft beer", "est"] - -# Optional arguments: word_count=4, supplemental=false, random_words_to_add=6 -Faker::Hipster.sentence #=> "Park iphone leggings put a bird on it." -Faker::Hipster.sentence(3) #=> "Pour-over swag godard." -Faker::Hipster.sentence(3, true) #=> "Beard laboriosam sequi celiac." -Faker::Hipster.sentence(3, false, 4) #=> "Bitters retro mustache aesthetic biodiesel 8-bit." -Faker::Hipster.sentence(3, true, 4) #=> "Occaecati deleniti messenger bag meh crucifix autem." - -# Optional arguments: sentence_count=3, supplemental=false -Faker::Hipster.sentences #=> ["Godard pitchfork vinegar chillwave everyday 90's whatever.", "Pour-over artisan distillery street waistcoat.", "Salvia yr leggings franzen blue bottle."] -Faker::Hipster.sentences(1) #=> ["Before they sold out pinterest venmo umami try-hard ugh hoodie artisan."] -Faker::Hipster.sentences(1, true) #=> ["Et sustainable optio aesthetic et."] - -# Optional arguments: sentence_count=3, supplemental=false, random_sentences_to_add=3 -Faker::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::Hipster.paragraph(2) #=> "Yolo tilde farm-to-table hashtag. Lomo kitsch disrupt forage +1." -Faker::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::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::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::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::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::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::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/lorem_hipster.md b/doc/lorem_hipster.md new file mode 100644 index 0000000000..a182d9dfa5 --- /dev/null +++ b/doc/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/lib/faker.rb b/lib/faker.rb index d0fc8cc080..3813e6da1e 100644 --- a/lib/faker.rb +++ b/lib/faker.rb @@ -235,6 +235,7 @@ def rand(max = nil) Dir.glob(File.join(File.dirname(__FILE__), 'faker', '*.rb')).sort.each { |f| require f } +require 'faker/lorem/hipster' require 'faker/lorem/ipsum' require 'faker/lorem/flickr' require 'faker/lorem/pixel' diff --git a/lib/faker/hipster.rb b/lib/faker/hipster.rb index 8d0bf514bd..4972d9cf81 100644 --- a/lib/faker/hipster.rb +++ b/lib/faker/hipster.rb @@ -3,55 +3,43 @@ module Faker class Hipster < Base class << self + extend Gem::Deprecate + def word - random_word = sample(translate('faker.hipster.words')) - random_word =~ /\s/ ? word : random_word + Faker::Lorem::Hipster.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/ } + Faker::Lorem::Hipster.word(num, supplemental, spaces_allowed) 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 + '.' + Faker::Lorem::Hipster.sentence(word_count, supplemental, random_words_to_add) end def sentences(sentence_count = 3, supplemental = false) - [].tap do |sentences| - 1.upto(resolve(sentence_count)) do - sentences << sentence(3, supplemental) - end - end + Faker::Lorem::Hipster.sentences(sentence_count, supplemental) 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(' ') + Faker::Lorem::Hipster.paragraph(sentence_count, supplemental, random_sentences_to_add) end def paragraphs(paragraph_count = 3, supplemental = false) - [].tap do |paragraphs| - 1.upto(resolve(paragraph_count)) do - paragraphs << paragraph(3, supplemental) - end - end + Faker::Lorem::Hipster.paragraphs(paragraph_count, 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] + '.' + 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/lorem/hipster.rb b/lib/faker/lorem/hipster.rb new file mode 100644 index 0000000000..abe7d559eb --- /dev/null +++ b/lib/faker/lorem/hipster.rb @@ -0,0 +1,59 @@ +# 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/test/test_determinism.rb b/test/test_determinism.rb index c266b52ead..51dc95b071 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 Char Base58 ChileRut Config Date Internet Lorem LoremFlickr LoremPixel Time VERSION].include?(subclass) + %i[Base Bank Char Base58 ChileRut Config Date Internet Lorem LoremFlickr LoremPixel Hipster Time Science VERSION].include?(subclass) end.sort end diff --git a/test/test_faker_hipster.rb b/test/test_faker_lorem_hipster.rb similarity index 98% rename from test/test_faker_hipster.rb rename to test/test_faker_lorem_hipster.rb index b76d2eb706..83d2b5ad05 100644 --- a/test/test_faker_hipster.rb +++ b/test/test_faker_lorem_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') From 02c88da3522417e07ba61707db2b6737ba6934f3 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 26 Sep 2018 23:18:59 -0300 Subject: [PATCH 10/15] Add tests for old lorem modules to make sure that they are working --- lib/faker/hipster.rb | 4 +- tasks/test.rake | 2 +- test/test_deprecate_lorem.rb | 120 +++++++++++++++++ test/test_deprecate_lorem_flickr.rb | 126 ++++++++++++++++++ test/test_deprecate_lorem_hipster.rb | 84 ++++++++++++ test/test_deprecate_lorem_pixel.rb | 71 ++++++++++ test/test_faker_lorem_flickr.rb | 2 +- ...rem_pixel.rb => test_faker_lorem_pixel.rb} | 2 +- 8 files changed, 406 insertions(+), 5 deletions(-) create mode 100644 test/test_deprecate_lorem.rb create mode 100644 test/test_deprecate_lorem_flickr.rb create mode 100644 test/test_deprecate_lorem_hipster.rb create mode 100644 test/test_deprecate_lorem_pixel.rb rename test/{test_lorem_pixel.rb => test_faker_lorem_pixel.rb} (97%) diff --git a/lib/faker/hipster.rb b/lib/faker/hipster.rb index 4972d9cf81..ad3d70de85 100644 --- a/lib/faker/hipster.rb +++ b/lib/faker/hipster.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Faker - class Hipster < Base + module Hipster class << self extend Gem::Deprecate @@ -10,7 +10,7 @@ def word end def words(num = 3, supplemental = false, spaces_allowed = false) - Faker::Lorem::Hipster.word(num, supplemental, spaces_allowed) + Faker::Lorem::Hipster.words(num, supplemental, spaces_allowed) end def sentence(word_count = 4, supplemental = false, random_words_to_add = 6) diff --git a/tasks/test.rake b/tasks/test.rake index 37fca168c3..8bc36ed7aa 100644 --- a/tasks/test.rake +++ b/tasks/test.rake @@ -5,7 +5,7 @@ require 'rake/testtask' Rake::TestTask.new do |t| t.libs << 'test' t.libs << '.' - t.test_files = FileList['test/test*.rb'] + t.pattern = FileList['test/test*.rb'] t.warning = true end diff --git a/test/test_deprecate_lorem.rb b/test/test_deprecate_lorem.rb new file mode 100644 index 0000000000..1ccf0f13fe --- /dev/null +++ b/test/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/test_deprecate_lorem_flickr.rb b/test/test_deprecate_lorem_flickr.rb new file mode 100644 index 0000000000..47bcde9618 --- /dev/null +++ b/test/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/test_deprecate_lorem_hipster.rb b/test/test_deprecate_lorem_hipster.rb new file mode 100644 index 0000000000..d5ec6a964a --- /dev/null +++ b/test/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/test_deprecate_lorem_pixel.rb b/test/test_deprecate_lorem_pixel.rb new file mode 100644 index 0000000000..461ce5031e --- /dev/null +++ b/test/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/test_faker_lorem_flickr.rb b/test/test_faker_lorem_flickr.rb index a2f07872c1..aaf28b97c3 100644 --- a/test/test_faker_lorem_flickr.rb +++ b/test/test_faker_lorem_flickr.rb @@ -4,7 +4,7 @@ class TestFakerLoremFlickr < Test::Unit::TestCase def setup - @tester = Faker::Lorem::Flickr + @tester = Faker::LoremFlickr @colorizations = %w[red green blue] end diff --git a/test/test_lorem_pixel.rb b/test/test_faker_lorem_pixel.rb similarity index 97% rename from test/test_lorem_pixel.rb rename to test/test_faker_lorem_pixel.rb index 0ddfee3863..b61a21117b 100644 --- a/test/test_lorem_pixel.rb +++ b/test/test_faker_lorem_pixel.rb @@ -2,7 +2,7 @@ require_relative 'test_helper' -class TestLoremPixel < Test::Unit::TestCase +class TestFakerLoremPixel < Test::Unit::TestCase def setup @tester = Faker::Lorem::Pixel end From 8a77c526743b37d69893ab35338464d1c51c3cdd Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sun, 27 Jan 2019 13:57:05 -0200 Subject: [PATCH 11/15] Fix structure of files --- lib/faker/{default => deprecate}/hipster.rb | 0 lib/faker/{default => deprecate}/lorem.rb | 0 .../{default => deprecate}/lorem_flickr.rb | 0 .../{default => deprecate}/lorem_pixel.rb | 0 lib/faker/lorem/hipster.rb | 1 + lib/faker/lorem/ipsum.rb | 1 + test/{ => deprecate}/test_deprecate_lorem.rb | 2 +- .../test_deprecate_lorem_flickr.rb | 2 +- .../test_deprecate_lorem_hipster.rb | 2 +- .../test_deprecate_lorem_pixel.rb | 2 +- .../test_hipster.rb} | 2 +- .../test_lorem.rb} | 6 - .../test_lorem_flickr.rb} | 2 +- .../{default => lorem}/test_lorem_pixel.rb | 4 +- test/test_faker_lorem_hipster.rb | 84 ------------ test/test_faker_lorem_ipsum.rb | 126 ------------------ test/test_faker_lorem_pixel.rb | 71 ---------- 17 files changed, 10 insertions(+), 295 deletions(-) rename lib/faker/{default => deprecate}/hipster.rb (100%) rename lib/faker/{default => deprecate}/lorem.rb (100%) rename lib/faker/{default => deprecate}/lorem_flickr.rb (100%) rename lib/faker/{default => deprecate}/lorem_pixel.rb (100%) rename test/{ => deprecate}/test_deprecate_lorem.rb (98%) rename test/{ => deprecate}/test_deprecate_lorem_flickr.rb (99%) rename test/{ => deprecate}/test_deprecate_lorem_hipster.rb (98%) rename test/{ => deprecate}/test_deprecate_lorem_pixel.rb (98%) rename test/faker/{default/test_faker_hipster.rb => lorem/test_hipster.rb} (98%) rename test/faker/{default/test_faker_lorem.rb => lorem/test_lorem.rb} (93%) rename test/faker/{default/test_faker_lorem_flickr.rb => lorem/test_lorem_flickr.rb} (99%) rename test/faker/{default => lorem}/test_lorem_pixel.rb (96%) delete mode 100644 test/test_faker_lorem_hipster.rb delete mode 100644 test/test_faker_lorem_ipsum.rb delete mode 100644 test/test_faker_lorem_pixel.rb diff --git a/lib/faker/default/hipster.rb b/lib/faker/deprecate/hipster.rb similarity index 100% rename from lib/faker/default/hipster.rb rename to lib/faker/deprecate/hipster.rb diff --git a/lib/faker/default/lorem.rb b/lib/faker/deprecate/lorem.rb similarity index 100% rename from lib/faker/default/lorem.rb rename to lib/faker/deprecate/lorem.rb diff --git a/lib/faker/default/lorem_flickr.rb b/lib/faker/deprecate/lorem_flickr.rb similarity index 100% rename from lib/faker/default/lorem_flickr.rb rename to lib/faker/deprecate/lorem_flickr.rb diff --git a/lib/faker/default/lorem_pixel.rb b/lib/faker/deprecate/lorem_pixel.rb similarity index 100% rename from lib/faker/default/lorem_pixel.rb rename to lib/faker/deprecate/lorem_pixel.rb diff --git a/lib/faker/lorem/hipster.rb b/lib/faker/lorem/hipster.rb index abe7d559eb..791e1a3a29 100644 --- a/lib/faker/lorem/hipster.rb +++ b/lib/faker/lorem/hipster.rb @@ -18,6 +18,7 @@ def words(num = 3, supplemental = false, spaces_allowed = false) 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 diff --git a/lib/faker/lorem/ipsum.rb b/lib/faker/lorem/ipsum.rb index 71d3a7e234..a72eeb8154 100644 --- a/lib/faker/lorem/ipsum.rb +++ b/lib/faker/lorem/ipsum.rb @@ -27,6 +27,7 @@ def character 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 diff --git a/test/test_deprecate_lorem.rb b/test/deprecate/test_deprecate_lorem.rb similarity index 98% rename from test/test_deprecate_lorem.rb rename to test/deprecate/test_deprecate_lorem.rb index 1ccf0f13fe..d11ad96f6b 100644 --- a/test/test_deprecate_lorem.rb +++ b/test/deprecate/test_deprecate_lorem.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'test_helper' +require_relative '../test_helper' class TestDeprecateLorem < Test::Unit::TestCase def setup diff --git a/test/test_deprecate_lorem_flickr.rb b/test/deprecate/test_deprecate_lorem_flickr.rb similarity index 99% rename from test/test_deprecate_lorem_flickr.rb rename to test/deprecate/test_deprecate_lorem_flickr.rb index 47bcde9618..4cde5695a4 100644 --- a/test/test_deprecate_lorem_flickr.rb +++ b/test/deprecate/test_deprecate_lorem_flickr.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'test_helper' +require_relative '../test_helper' class TestDeprecateLoremFlickr < Test::Unit::TestCase def setup diff --git a/test/test_deprecate_lorem_hipster.rb b/test/deprecate/test_deprecate_lorem_hipster.rb similarity index 98% rename from test/test_deprecate_lorem_hipster.rb rename to test/deprecate/test_deprecate_lorem_hipster.rb index d5ec6a964a..98f03ed846 100644 --- a/test/test_deprecate_lorem_hipster.rb +++ b/test/deprecate/test_deprecate_lorem_hipster.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'test_helper' +require_relative '../test_helper' class TestDeprecateHipster < Test::Unit::TestCase def setup diff --git a/test/test_deprecate_lorem_pixel.rb b/test/deprecate/test_deprecate_lorem_pixel.rb similarity index 98% rename from test/test_deprecate_lorem_pixel.rb rename to test/deprecate/test_deprecate_lorem_pixel.rb index 461ce5031e..c45f6f0ec6 100644 --- a/test/test_deprecate_lorem_pixel.rb +++ b/test/deprecate/test_deprecate_lorem_pixel.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'test_helper' +require_relative '../test_helper' class TestDeprecateLoremPixel < Test::Unit::TestCase def setup 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_faker_lorem_hipster.rb b/test/test_faker_lorem_hipster.rb deleted file mode 100644 index 83d2b5ad05..0000000000 --- a/test/test_faker_lorem_hipster.rb +++ /dev/null @@ -1,84 +0,0 @@ -# frozen_string_literal: true - -require_relative 'test_helper' - -class TestFakerHipster < Test::Unit::TestCase - def setup - @tester = Faker::Lorem::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/test_faker_lorem_ipsum.rb b/test/test_faker_lorem_ipsum.rb deleted file mode 100644 index a4d413ee62..0000000000 --- a/test/test_faker_lorem_ipsum.rb +++ /dev/null @@ -1,126 +0,0 @@ -# frozen_string_literal: true - -require_relative 'test_helper' - -class TestFakerLoremIpsum < Test::Unit::TestCase - def setup - @tester = Faker::Lorem::Ipsum - @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 - - 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/test_faker_lorem_pixel.rb b/test/test_faker_lorem_pixel.rb deleted file mode 100644 index b61a21117b..0000000000 --- a/test/test_faker_lorem_pixel.rb +++ /dev/null @@ -1,71 +0,0 @@ -# frozen_string_literal: true - -require_relative 'test_helper' - -class TestFakerLoremPixel < Test::Unit::TestCase - def setup - @tester = Faker::Lorem::Pixel - 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 From 62708c173f956561330d9cc78ea567138096adc7 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sun, 27 Jan 2019 14:02:41 -0200 Subject: [PATCH 12/15] Fix docs --- doc/v2.0/lorem/flickr.md | 47 +++++++++++++++++++ .../lorem/hipster.md} | 0 doc/{lorem_ipsum.md => v2.0/lorem/ipsum.md} | 0 doc/v2.0/lorem/pixel.md | 21 +++++++++ 4 files changed, 68 insertions(+) create mode 100644 doc/v2.0/lorem/flickr.md rename doc/{lorem_hipster.md => v2.0/lorem/hipster.md} (100%) rename doc/{lorem_ipsum.md => v2.0/lorem/ipsum.md} (100%) create mode 100644 doc/v2.0/lorem/pixel.md diff --git a/doc/v2.0/lorem/flickr.md b/doc/v2.0/lorem/flickr.md new file mode 100644 index 0000000000..60f4513a14 --- /dev/null +++ b/doc/v2.0/lorem/flickr.md @@ -0,0 +1,47 @@ +# Faker::LoremFlickr + +Available since version 1.9.0. + +```ruby +Faker::LoremFlickr.image #=> "http://loremflickr.com/300/300" + +Faker::LoremFlickr.image("50x60") #=> "http://loremflickr.com/50/60" + +Faker::LoremFlickr.image("50x60", ['sports']) #=> "http://loremflickr.com/50/60/sports" + +Faker::LoremFlickr.image("50x60", ['sports', 'fitness']) #=> "http://loremflickr.com/50/60/sports,fitness" + +Faker::LoremFlickr.image("50x60", ['sports', 'fitness'], true) #=> "http://loremflickr.com/50/60/sports,fitness/all" + +Faker::LoremFlickr.grayscale_image #=> "http://loremflickr.com/g/300/300/all" + +Faker::LoremFlickr.grayscale_image("50x60") #=> "http://loremflickr.com/g/50/60/all" + +Faker::LoremFlickr.grayscale_image("50x60", ['sports']) #=> "http://loremflickr.com/g/50/60/sports" + +Faker::LoremFlickr.grayscale_image("50x60", ['sports', 'fitness']) #=> "http://loremflickr.com/g/50/60/sports,fitness" + +Faker::LoremFlickr.grayscale_image("50x60", ['sports', 'fitness'], true) #=> "http://loremflickr.com/g/50/60/sports,fitness/all" + +Faker::LoremFlickr.pixelated_image #=> "http://loremflickr.com/p/300/300/all" + +Faker::LoremFlickr.pixelated_image("50x60") #=> "http://loremflickr.com/p/50/60/all" + +Faker::LoremFlickr.pixelated_image("50x60", ['sports']) #=> "http://loremflickr.com/p/50/60/sports" + +Faker::LoremFlickr.pixelated_image("50x60", ['sports', 'fitness']) #=> "http://loremflickr.com/p/50/60/sports,fitness" + +Faker::LoremFlickr.pixelated_image("50x60", ['sports', 'fitness'], true) #=> "http://loremflickr.com/p/50/60/sports,fitness/all" + +Faker::LoremFlickr.colorized_image #=> "http://loremflickr.com/red/300/300/all" + +Faker::LoremFlickr.colorized_image("50x60") #=> "http://loremflickr.com/red/50/60/all" + +Faker::LoremFlickr.colorized_image("50x60", 'red') #=> "http://loremflickr.com/red/50/60/all" + +Faker::LoremFlickr.colorized_image("50x60", 'red', ['sports']) #=> "http://loremflickr.com/red/50/60/sports" + +Faker::LoremFlickr.colorized_image("50x60", 'red', ['sports', 'fitness']) #=> "http://loremflickr.com/red/50/60/sports,fitness" + +Faker::LoremFlickr.colorized_image("50x60", 'red', ['sports', 'fitness'], true) #=> "http://loremflickr.com/red/50/60/sports,fitness/all" +``` diff --git a/doc/lorem_hipster.md b/doc/v2.0/lorem/hipster.md similarity index 100% rename from doc/lorem_hipster.md rename to doc/v2.0/lorem/hipster.md diff --git a/doc/lorem_ipsum.md b/doc/v2.0/lorem/ipsum.md similarity index 100% rename from doc/lorem_ipsum.md rename to doc/v2.0/lorem/ipsum.md diff --git a/doc/v2.0/lorem/pixel.md b/doc/v2.0/lorem/pixel.md new file mode 100644 index 0000000000..7951318f87 --- /dev/null +++ b/doc/v2.0/lorem/pixel.md @@ -0,0 +1,21 @@ +# Faker::LoremPixel + +Available since version 1.7.0. + +```ruby +Faker::LoremPixel.image #=> "https://lorempixel.com/300/300" + +Faker::LoremPixel.image("50x60") #=> "https://lorempixel.com/50/60" + +Faker::LoremPixel.image("50x60", true) #=> "https://lorempixel.com/g/50/60" + +Faker::LoremPixel.image("50x60", false, 'sports') #=> "https://lorempixel.com/50/60/sports" + +Faker::LoremPixel.image("50x60", false, 'sports', 3) #=> "https://lorempixel.com/50/60/sports/3" + +Faker::LoremPixel.image("50x60", false, 'sports', 3, 'Dummy-text') #=> "https://lorempixel.com/50/60/sports/3/Dummy-text" + +Faker::LoremPixel.image("50x60", false, 'sports', nil, 'Dummy-text') #=> "https://lorempixel.com/50/60/sports/Dummy-text" + +Faker::LoremPixel.image(secure: false) #=> "http://lorempixel.com/300/300" +``` From 14cfaeaebfb11dee95ad8f6efc2b40e9fb4fb5eb Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sun, 27 Jan 2019 14:04:25 -0200 Subject: [PATCH 13/15] Add namespace to docs --- doc/v2.0/lorem/flickr.md | 44 ++++++++++++++++++++-------------------- doc/v2.0/lorem/pixel.md | 18 ++++++++-------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/doc/v2.0/lorem/flickr.md b/doc/v2.0/lorem/flickr.md index 60f4513a14..4b95dff660 100644 --- a/doc/v2.0/lorem/flickr.md +++ b/doc/v2.0/lorem/flickr.md @@ -1,47 +1,47 @@ -# Faker::LoremFlickr +# Faker::Lorem::Flickr Available since version 1.9.0. ```ruby -Faker::LoremFlickr.image #=> "http://loremflickr.com/300/300" +Faker::Lorem::Flickr.image #=> "http://loremflickr.com/300/300" -Faker::LoremFlickr.image("50x60") #=> "http://loremflickr.com/50/60" +Faker::Lorem::Flickr.image("50x60") #=> "http://loremflickr.com/50/60" -Faker::LoremFlickr.image("50x60", ['sports']) #=> "http://loremflickr.com/50/60/sports" +Faker::Lorem::Flickr.image("50x60", ['sports']) #=> "http://loremflickr.com/50/60/sports" -Faker::LoremFlickr.image("50x60", ['sports', 'fitness']) #=> "http://loremflickr.com/50/60/sports,fitness" +Faker::Lorem::Flickr.image("50x60", ['sports', 'fitness']) #=> "http://loremflickr.com/50/60/sports,fitness" -Faker::LoremFlickr.image("50x60", ['sports', 'fitness'], true) #=> "http://loremflickr.com/50/60/sports,fitness/all" +Faker::Lorem::Flickr.image("50x60", ['sports', 'fitness'], true) #=> "http://loremflickr.com/50/60/sports,fitness/all" -Faker::LoremFlickr.grayscale_image #=> "http://loremflickr.com/g/300/300/all" +Faker::Lorem::Flickr.grayscale_image #=> "http://loremflickr.com/g/300/300/all" -Faker::LoremFlickr.grayscale_image("50x60") #=> "http://loremflickr.com/g/50/60/all" +Faker::Lorem::Flickr.grayscale_image("50x60") #=> "http://loremflickr.com/g/50/60/all" -Faker::LoremFlickr.grayscale_image("50x60", ['sports']) #=> "http://loremflickr.com/g/50/60/sports" +Faker::Lorem::Flickr.grayscale_image("50x60", ['sports']) #=> "http://loremflickr.com/g/50/60/sports" -Faker::LoremFlickr.grayscale_image("50x60", ['sports', 'fitness']) #=> "http://loremflickr.com/g/50/60/sports,fitness" +Faker::Lorem::Flickr.grayscale_image("50x60", ['sports', 'fitness']) #=> "http://loremflickr.com/g/50/60/sports,fitness" -Faker::LoremFlickr.grayscale_image("50x60", ['sports', 'fitness'], true) #=> "http://loremflickr.com/g/50/60/sports,fitness/all" +Faker::Lorem::Flickr.grayscale_image("50x60", ['sports', 'fitness'], true) #=> "http://loremflickr.com/g/50/60/sports,fitness/all" -Faker::LoremFlickr.pixelated_image #=> "http://loremflickr.com/p/300/300/all" +Faker::Lorem::Flickr.pixelated_image #=> "http://loremflickr.com/p/300/300/all" -Faker::LoremFlickr.pixelated_image("50x60") #=> "http://loremflickr.com/p/50/60/all" +Faker::Lorem::Flickr.pixelated_image("50x60") #=> "http://loremflickr.com/p/50/60/all" -Faker::LoremFlickr.pixelated_image("50x60", ['sports']) #=> "http://loremflickr.com/p/50/60/sports" +Faker::Lorem::Flickr.pixelated_image("50x60", ['sports']) #=> "http://loremflickr.com/p/50/60/sports" -Faker::LoremFlickr.pixelated_image("50x60", ['sports', 'fitness']) #=> "http://loremflickr.com/p/50/60/sports,fitness" +Faker::Lorem::Flickr.pixelated_image("50x60", ['sports', 'fitness']) #=> "http://loremflickr.com/p/50/60/sports,fitness" -Faker::LoremFlickr.pixelated_image("50x60", ['sports', 'fitness'], true) #=> "http://loremflickr.com/p/50/60/sports,fitness/all" +Faker::Lorem::Flickr.pixelated_image("50x60", ['sports', 'fitness'], true) #=> "http://loremflickr.com/p/50/60/sports,fitness/all" -Faker::LoremFlickr.colorized_image #=> "http://loremflickr.com/red/300/300/all" +Faker::Lorem::Flickr.colorized_image #=> "http://loremflickr.com/red/300/300/all" -Faker::LoremFlickr.colorized_image("50x60") #=> "http://loremflickr.com/red/50/60/all" +Faker::Lorem::Flickr.colorized_image("50x60") #=> "http://loremflickr.com/red/50/60/all" -Faker::LoremFlickr.colorized_image("50x60", 'red') #=> "http://loremflickr.com/red/50/60/all" +Faker::Lorem::Flickr.colorized_image("50x60", 'red') #=> "http://loremflickr.com/red/50/60/all" -Faker::LoremFlickr.colorized_image("50x60", 'red', ['sports']) #=> "http://loremflickr.com/red/50/60/sports" +Faker::Lorem::Flickr.colorized_image("50x60", 'red', ['sports']) #=> "http://loremflickr.com/red/50/60/sports" -Faker::LoremFlickr.colorized_image("50x60", 'red', ['sports', 'fitness']) #=> "http://loremflickr.com/red/50/60/sports,fitness" +Faker::Lorem::Flickr.colorized_image("50x60", 'red', ['sports', 'fitness']) #=> "http://loremflickr.com/red/50/60/sports,fitness" -Faker::LoremFlickr.colorized_image("50x60", 'red', ['sports', 'fitness'], true) #=> "http://loremflickr.com/red/50/60/sports,fitness/all" +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/pixel.md b/doc/v2.0/lorem/pixel.md index 7951318f87..172325a48b 100644 --- a/doc/v2.0/lorem/pixel.md +++ b/doc/v2.0/lorem/pixel.md @@ -1,21 +1,21 @@ -# Faker::LoremPixel +# Faker::Lorem::Pixel Available since version 1.7.0. ```ruby -Faker::LoremPixel.image #=> "https://lorempixel.com/300/300" +Faker::Lorem::Pixel.image #=> "https://lorempixel.com/300/300" -Faker::LoremPixel.image("50x60") #=> "https://lorempixel.com/50/60" +Faker::Lorem::Pixel.image("50x60") #=> "https://lorempixel.com/50/60" -Faker::LoremPixel.image("50x60", true) #=> "https://lorempixel.com/g/50/60" +Faker::Lorem::Pixel.image("50x60", true) #=> "https://lorempixel.com/g/50/60" -Faker::LoremPixel.image("50x60", false, 'sports') #=> "https://lorempixel.com/50/60/sports" +Faker::Lorem::Pixel.image("50x60", false, 'sports') #=> "https://lorempixel.com/50/60/sports" -Faker::LoremPixel.image("50x60", false, 'sports', 3) #=> "https://lorempixel.com/50/60/sports/3" +Faker::Lorem::Pixel.image("50x60", false, 'sports', 3) #=> "https://lorempixel.com/50/60/sports/3" -Faker::LoremPixel.image("50x60", false, 'sports', 3, 'Dummy-text') #=> "https://lorempixel.com/50/60/sports/3/Dummy-text" +Faker::Lorem::Pixel.image("50x60", false, 'sports', 3, 'Dummy-text') #=> "https://lorempixel.com/50/60/sports/3/Dummy-text" -Faker::LoremPixel.image("50x60", false, 'sports', nil, 'Dummy-text') #=> "https://lorempixel.com/50/60/sports/Dummy-text" +Faker::Lorem::Pixel.image("50x60", false, 'sports', nil, 'Dummy-text') #=> "https://lorempixel.com/50/60/sports/Dummy-text" -Faker::LoremPixel.image(secure: false) #=> "http://lorempixel.com/300/300" +Faker::Lorem::Pixel.image(secure: false) #=> "http://lorempixel.com/300/300" ``` From c5ada4b80a320f92276e3b1ca54006053197e0a0 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sun, 27 Jan 2019 14:11:43 -0200 Subject: [PATCH 14/15] Update unreleased_readme --- unreleased_README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/unreleased_README.md b/unreleased_README.md index 6df1a10e14..2a834c02c1 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) @@ -242,6 +243,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) From 2b04f4b5a53b03c0c2c576ed49561f7bc0c63239 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sun, 27 Jan 2019 14:27:49 -0200 Subject: [PATCH 15/15] Remove old references --- unreleased_README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/unreleased_README.md b/unreleased_README.md index 2a834c02c1..3cbf201aa2 100644 --- a/unreleased_README.md +++ b/unreleased_README.md @@ -160,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) @@ -169,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)