diff --git a/CHANGELOG.md b/CHANGELOG.md index 5de9713ff5..e941e8af6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ - [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 #1503](https://github.com/stympy/faker/pull/1503) Add Books namespace [@vbrazo](https://github.com/vbrazo) + - Deprecates `::Dune`, `Lovecraft` - [PR #1480](https://github.com/stympy/faker/pull/1480) Add Music, Movies and TvShows namespaces [@vbrazo](https://github.com/vbrazo) - Deprecates `::Hobbit`, `HitchhikersGuideToTheGalaxy`, `::HarryPotter`, `::RockBand`, `::MichaelScott`, `::RuPaul` - [PR #1481](https://github.com/stympy/faker/pull/1481) Add Blockchain namespace [@vbrazo](https://github.com/vbrazo) diff --git a/doc/unreleased/default/book.md b/doc/unreleased/books/book.md similarity index 100% rename from doc/unreleased/default/book.md rename to doc/unreleased/books/book.md diff --git a/doc/unreleased/books/dune.md b/doc/unreleased/books/dune.md new file mode 100644 index 0000000000..eb4ca66288 --- /dev/null +++ b/doc/unreleased/books/dune.md @@ -0,0 +1,19 @@ +# Faker::Books::Dune + +### A Faker module beyond your dreams, test data beyond your imagination. + +```ruby +Faker::Books::Dune.character #=> "Leto Atreides" + +Faker::Books::Dune.title #=> "Duke" + +Faker::Books::Dune.planet #=> "Caladan" + +Faker::Books::Dune.quote #=> "A dead man, surely, no longer requires that water." + +Faker::Books::Dune.quote("baron_harkonnen") #=> "He who controls the spice, controls the universe!" + +Faker::Books::Dune.saying #=> "You do not beg the sun for mercy." + +Faker::Books::Dune.saying("fremen") #=> "May thy knife chip and shatter." +``` diff --git a/doc/unreleased/books/lovecraft.md b/doc/unreleased/books/lovecraft.md new file mode 100644 index 0000000000..a73b33e233 --- /dev/null +++ b/doc/unreleased/books/lovecraft.md @@ -0,0 +1,41 @@ +# Faker::Books::Lovecraft + +```ruby +Faker::Books::Lovecraft.fhtagn #=> "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn" +Faker::Books::Lovecraft.fhtagn(3) #=> "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn. Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn. Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn" + +Faker::Books::Lovecraft.deity #=> "Shub-Niggurath" + +Faker::Books::Lovecraft.tome #=> "Book of Eibon" + +Faker::Books::Lovecraft.location #=> "Kingsport" + +Faker::Books::Lovecraft.word #=> "furtive" + +# Optional arguments: word_count=4, random_words_to_add=6 +Faker::Books::Lovecraft.sentence #=> "Furtive antiquarian squamous dank cat loathsome amorphous lurk." +Faker::Books::Lovecraft.sentence(3) #=> "Daemoniac antediluvian fainted squamous comprehension gambrel nameless singular." +Faker::Books::Lovecraft.sentence(3, 1) #=> "Amorphous indescribable tenebrous." + +# Optional arguments: num=3, spaces_allowed = false +Faker::Books::Lovecraft.words #=> ["manuscript", "abnormal", "singular"] +Faker::Books::Lovecraft.words(2) #=> ["daemoniac", "cat"] +Faker::Books::Lovecraft.words(2, true) #=> ["lurk", "charnel"] + +# Optional arguments: sentence_count=3 +Faker::Books::Lovecraft.sentences #=> ["Nameless loathsome decadent gambrel.", "Ululate swarthy immemorial cat madness gibbous unmentionable unnamable.", "Decadent antediluvian non-euclidean tentacles amorphous tenebrous."] +Faker::Books::Lovecraft.sentences(2) #=> ["Antediluvian amorphous unmentionable singular accursed squamous immemorial.", "Gambrel daemoniac gibbous stygian shunned ululate iridescence abnormal."] + +# Optional arguments: sentence_count=3, random_sentences_to_add=3 +Faker::Books::Lovecraft.paragraph #=> "Squamous nameless daemoniac fungus ululate. Cyclopean stygian decadent loathsome manuscript tenebrous. Foetid abnormal stench. Dank non-euclidean comprehension eldritch. Charnel singular shunned lurk effulgence fungus." +Faker::Books::Lovecraft.paragraph(2) #=> "Decadent lurk tenebrous loathsome furtive spectral amorphous gibbous. Gambrel eldritch daemoniac cat madness comprehension stygian effulgence." +Faker::Books::Lovecraft.paragraph(2, 1) #=> "Stench cyclopean fainted antiquarian nameless. Antiquarian ululate tenebrous non-euclidean effulgence." + +# Optional arguments: paragraph_count=3 +Faker::Books::Lovecraft.paragraphs #=> ["Noisome daemoniac gibbous abnormal antediluvian. Unutterable fungus accursed stench noisome lurk madness indescribable. Antiquarian fungus gibbering lurk dank fainted. Hideous loathsome manuscript daemoniac lurk charnel foetid.", "Non-euclidean immemorial indescribable accursed furtive. Dank unnamable cyclopean tenebrous stench immemorial. Eldritch abnormal gibbering tenebrous. Singular accursed lurk.", "Charnel antediluvian unnamable cat blasphemous comprehension tenebrous. Nameless accursed amorphous unnamable stench. Squamous unnamable mortal accursed manuscript spectral gambrel amorphous. Shunned stygian charnel unutterable. Tenebrous ululate lurk amorphous unnamable."] +Faker::Books::Lovecraft.paragraphs(2) #=> ["Hideous amorphous manuscript antediluvian non-euclidean cat eldritch foetid. Stench squamous manuscript amorphous gibbering fainted gibbous. Accursed loathsome blasphemous iridescence antediluvian abnormal ululate manuscript. Singular manuscript gibbering decadent accursed indescribable.", "Tenebrous unnamable comprehension antediluvian lurk. Lurk spectral noisome gibbering. Furtive manuscript madness tenebrous daemoniac."] + +# Optional arguments: chars=3, supplemental=false +Faker::Books::Lovecraft.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::Books::Lovecraft.paragraph_by_chars(256) #=> "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/unreleased/default/dune.md b/doc/unreleased/default/dune.md deleted file mode 100644 index 9e21a14aaf..0000000000 --- a/doc/unreleased/default/dune.md +++ /dev/null @@ -1,18 +0,0 @@ -# Faker::Dune -### A Faker module beyond your dreams, test data beyond your imagination. - -```ruby -Faker::Dune.character #=> "Leto Atreides" - -Faker::Dune.title #=> "Duke" - -Faker::Dune.planet #=> "Caladan" - -Faker::Dune.quote #=> "A dead man, surely, no longer requires that water." - -Faker::Dune.quote("baron_harkonnen") #=> "He who controls the spice, controls the universe!" - -Faker::Dune.saying #=> "You do not beg the sun for mercy." - -Faker::Dune.saying("fremen") #=> "May thy knife chip and shatter." -``` diff --git a/doc/unreleased/default/lovecraft.md b/doc/unreleased/default/lovecraft.md deleted file mode 100644 index 6e30f23bfa..0000000000 --- a/doc/unreleased/default/lovecraft.md +++ /dev/null @@ -1,40 +0,0 @@ -# Faker::Lovecraft - -```ruby -Faker::Lovecraft.fhtagn(3) #=> "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn. Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn. Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn" - -Faker::Lovecraft.deity #=> "Shub-Niggurath" - -Faker::Lovecraft.tome #=> "Book of Eibon" - -Faker::Lovecraft.location #=> "Kingsport" - -Faker::Lovecraft.word #=> "furtive" - -# Optional arguments: word_count=4, random_words_to_add=6 -Faker::Lovecraft.sentence #=> "Furtive antiquarian squamous dank cat loathsome amorphous lurk." -Faker::Lovecraft.sentence(3) #=> "Daemoniac antediluvian fainted squamous comprehension gambrel nameless singular." -Faker::Lovecraft.sentence(3, 1) #=> "Amorphous indescribable tenebrous." - -# Optional arguments: num=3, spaces_allowed = false -Faker::Lovecraft.words #=> ["manuscript", "abnormal", "singular"] -Faker::Lovecraft.words(2) #=> ["daemoniac", "cat"] -Faker::Lovecraft.words(2, true) #=> ["lurk", "charnel"] - -# Optional arguments: sentence_count=3 -Faker::Lovecraft.sentences #=> ["Nameless loathsome decadent gambrel.", "Ululate swarthy immemorial cat madness gibbous unmentionable unnamable.", "Decadent antediluvian non-euclidean tentacles amorphous tenebrous."] -Faker::Lovecraft.sentences(2) #=> ["Antediluvian amorphous unmentionable singular accursed squamous immemorial.", "Gambrel daemoniac gibbous stygian shunned ululate iridescence abnormal."] - -# Optional arguments: sentence_count=3, random_sentences_to_add=3 -Faker::Lovecraft.paragraph #=> "Squamous nameless daemoniac fungus ululate. Cyclopean stygian decadent loathsome manuscript tenebrous. Foetid abnormal stench. Dank non-euclidean comprehension eldritch. Charnel singular shunned lurk effulgence fungus." -Faker::Lovecraft.paragraph(2) #=> "Decadent lurk tenebrous loathsome furtive spectral amorphous gibbous. Gambrel eldritch daemoniac cat madness comprehension stygian effulgence." -Faker::Lovecraft.paragraph(2, 1) #=> "Stench cyclopean fainted antiquarian nameless. Antiquarian ululate tenebrous non-euclidean effulgence." - -# Optional arguments: paragraph_count=3 -Faker::Lovecraft.paragraphs #=> ["Noisome daemoniac gibbous abnormal antediluvian. Unutterable fungus accursed stench noisome lurk madness indescribable. Antiquarian fungus gibbering lurk dank fainted. Hideous loathsome manuscript daemoniac lurk charnel foetid.", "Non-euclidean immemorial indescribable accursed furtive. Dank unnamable cyclopean tenebrous stench immemorial. Eldritch abnormal gibbering tenebrous. Singular accursed lurk.", "Charnel antediluvian unnamable cat blasphemous comprehension tenebrous. Nameless accursed amorphous unnamable stench. Squamous unnamable mortal accursed manuscript spectral gambrel amorphous. Shunned stygian charnel unutterable. Tenebrous ululate lurk amorphous unnamable."] -Faker::Lovecraft.paragraphs(2) #=> ["Hideous amorphous manuscript antediluvian non-euclidean cat eldritch foetid. Stench squamous manuscript amorphous gibbering fainted gibbous. Accursed loathsome blasphemous iridescence antediluvian abnormal ululate manuscript. Singular manuscript gibbering decadent accursed indescribable.", "Tenebrous unnamable comprehension antediluvian lurk. Lurk spectral noisome gibbering. Furtive manuscript madness tenebrous daemoniac."] - -# Optional arguments: chars=3, supplemental=false -Faker::Lovecraft.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::Lovecraft.paragraph_by_chars(256) #=> "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/default/book.rb b/lib/faker/books/book.rb similarity index 100% rename from lib/faker/default/book.rb rename to lib/faker/books/book.rb diff --git a/lib/faker/books/culture_series.rb b/lib/faker/books/culture_series.rb index 6646f9b2ae..2976385326 100644 --- a/lib/faker/books/culture_series.rb +++ b/lib/faker/books/culture_series.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Faker - module Books + class Books class CultureSeries < Base flexible :culture_series class << self diff --git a/lib/faker/books/dune.rb b/lib/faker/books/dune.rb new file mode 100644 index 0000000000..774012b29c --- /dev/null +++ b/lib/faker/books/dune.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +module Faker + class Books + class Dune < Base + class << self + # QUOTED_CHARACTERS = fetch("dune.quotes") + # SAYING_SOURCES = %w(translate("faker.dune.sources")) + + def character + fetch('dune.characters') + end + + def title + fetch('dune.titles') + end + + def planet + fetch('dune.planets') + end + + def quote(character = nil) + quoted_characters = translate('faker.dune.quotes').keys + + if character.nil? + character = sample(quoted_characters).to_s + else + character = character.to_s.downcase + + unless quoted_characters.include?(character.to_sym) + raise ArgumentError, + "Characters quoted can be left blank or #{quoted_characters.join(', ')}" + end + end + + fetch('dune.quotes.' + character) + end + + def saying(source = nil) + sourced_sayings = translate('faker.dune.sayings').keys + + if source.nil? + source = sample(sourced_sayings).to_s + else + source = source.to_s.downcase + + unless sourced_sayings.include?(source.to_sym) + raise ArgumentError, + "Sources quoted in sayings can be left blank or #{sourced_sayings.join(', ')}" + end + end + + fetch('dune.sayings.' + source) + end + end + end + end +end diff --git a/lib/faker/books/lovecraft.rb b/lib/faker/books/lovecraft.rb new file mode 100644 index 0000000000..43c9871bc5 --- /dev/null +++ b/lib/faker/books/lovecraft.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +module Faker + class Books + class Lovecraft < Base + class << self + def location + fetch('lovecraft.location') + end + + def fhtagn(number_of = 1) + Array.new(number_of) { fetch('lovecraft.fhtagn') }.join('. ') + end + + def deity + fetch('lovecraft.deity') + end + + def tome + fetch('lovecraft.tome') + end + + def sentence(word_count = 4, random_words_to_add = 6) + words(word_count + rand(random_words_to_add.to_i).to_i, true).join(' ').capitalize + '.' + end + + def word + random_word = sample(translate('faker.lovecraft.words')) + random_word =~ /\s/ ? word : random_word + end + + def words(num = 3, spaces_allowed = false) + resolved_num = resolve(num) + word_list = translate('faker.lovecraft.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 sentences(sentence_count = 3) + [].tap do |sentences| + 1.upto(resolve(sentence_count)) do + sentences << sentence(3) + end + end + end + + def paragraph(sentence_count = 3, random_sentences_to_add = 3) + sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i).join(' ') + end + + def paragraphs(paragraph_count = 3) + [].tap do |paragraphs| + 1.upto(resolve(paragraph_count)) do + paragraphs << paragraph(3) + end + end + end + + def paragraph_by_chars(chars = 256) + paragraph = paragraph(3) + + paragraph += ' ' + paragraph(3) while paragraph.length < chars + + paragraph[0...chars - 1] + '.' + end + end + end + end +end diff --git a/lib/faker/default/dune.rb b/lib/faker/default/dune.rb deleted file mode 100644 index d9bbcab579..0000000000 --- a/lib/faker/default/dune.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -module Faker - class Dune < Base - class << self - # QUOTED_CHARACTERS = fetch("dune.quotes") - # SAYING_SOURCES = %w(translate("faker.dune.sources")) - - def character - fetch('dune.characters') - end - - def title - fetch('dune.titles') - end - - def planet - fetch('dune.planets') - end - - def quote(character = nil) - quoted_characters = translate('faker.dune.quotes').keys - - if character.nil? - character = sample(quoted_characters).to_s - else - character = character.to_s.downcase - - unless quoted_characters.include?(character.to_sym) - raise ArgumentError, - "Characters quoted can be left blank or #{quoted_characters.join(', ')}" - end - end - - fetch('dune.quotes.' + character) - end - - def saying(source = nil) - sourced_sayings = translate('faker.dune.sayings').keys - - if source.nil? - source = sample(sourced_sayings).to_s - else - source = source.to_s.downcase - - unless sourced_sayings.include?(source.to_sym) - raise ArgumentError, - "Sources quoted in sayings can be left blank or #{sourced_sayings.join(', ')}" - end - end - - fetch('dune.sayings.' + source) - end - end - end -end diff --git a/lib/faker/default/lovecraft.rb b/lib/faker/default/lovecraft.rb deleted file mode 100644 index 696329d483..0000000000 --- a/lib/faker/default/lovecraft.rb +++ /dev/null @@ -1,71 +0,0 @@ -# frozen_string_literal: true - -module Faker - class Lovecraft < Base - class << self - def location - fetch('lovecraft.location') - end - - def fhtagn(number_of = 1) - Array.new(number_of) { fetch('lovecraft.fhtagn') }.join('. ') - end - - def deity - fetch('lovecraft.deity') - end - - def tome - fetch('lovecraft.tome') - end - - def sentence(word_count = 4, random_words_to_add = 6) - words(word_count + rand(random_words_to_add.to_i).to_i, true).join(' ').capitalize + '.' - end - - def word - random_word = sample(translate('faker.lovecraft.words')) - random_word =~ /\s/ ? word : random_word - end - - def words(num = 3, spaces_allowed = false) - resolved_num = resolve(num) - word_list = translate('faker.lovecraft.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 sentences(sentence_count = 3) - [].tap do |sentences| - 1.upto(resolve(sentence_count)) do - sentences << sentence(3) - end - end - end - - def paragraph(sentence_count = 3, random_sentences_to_add = 3) - sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i).join(' ') - end - - def paragraphs(paragraph_count = 3) - [].tap do |paragraphs| - 1.upto(resolve(paragraph_count)) do - paragraphs << paragraph(3) - end - end - end - - def paragraph_by_chars(chars = 256) - paragraph = paragraph(3) - - paragraph += ' ' + paragraph(3) while paragraph.length < chars - - paragraph[0...chars - 1] + '.' - end - end - end -end diff --git a/lib/faker/deprecate/dune.rb b/lib/faker/deprecate/dune.rb new file mode 100644 index 0000000000..cd168df521 --- /dev/null +++ b/lib/faker/deprecate/dune.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Faker + class Dune < Base + class << self + extend Gem::Deprecate + + def character + Faker::Books::Dune.character + end + + def title + Faker::Books::Dune.title + end + + def planet + Faker::Books::Dune.planet + end + + def quote(character = nil) + Faker::Books::Dune.quote(character) + end + + def saying(source = nil) + Faker::Books::Dune.saying(source) + end + + deprecate :character, 'Faker::Books::Dune.character', 2018, 12 + deprecate :title, 'Faker::Books::Dune.title', 2018, 12 + deprecate :planet, 'Faker::Books::Dune.planet', 2018, 12 + deprecate :quote, 'Faker::Books::Dune.quote', 2018, 12 + deprecate :saying, 'Faker::Books::Dune.saying', 2018, 12 + end + end +end diff --git a/lib/faker/deprecate/lovecraft.rb b/lib/faker/deprecate/lovecraft.rb new file mode 100644 index 0000000000..d6b499b7b1 --- /dev/null +++ b/lib/faker/deprecate/lovecraft.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +module Faker + class Lovecraft < Base + class << self + extend Gem::Deprecate + + def location + Faker::Books::Lovecraft.location + end + + def fhtagn(number_of = 1) + Faker::Books::Lovecraft.fhtagn(number_of) + end + + def deity + Faker::Books::Lovecraft.deity + end + + def tome + Faker::Books::Lovecraft.tome + end + + def sentence(word_count = 4, random_words_to_add = 6) + Faker::Books::Lovecraft.sentence(word_count, random_words_to_add) + end + + def word + Faker::Books::Lovecraft.word + end + + def words(num = 3, spaces_allowed = false) + Faker::Books::Lovecraft.words(num, spaces_allowed) + end + + def sentences(sentence_count = 3) + Faker::Books::Lovecraft.sentences(sentence_count) + end + + def paragraph(sentence_count = 3, random_sentences_to_add = 3) + Faker::Books::Lovecraft.paragraph(sentence_count, random_sentences_to_add) + end + + def paragraphs(paragraph_count = 3) + Faker::Books::Lovecraft.paragraphs(paragraph_count) + end + + def paragraph_by_chars(chars = 256) + Faker::Books::Lovecraft.paragraph_by_chars(chars) + end + + deprecate :location, 'Faker::Books::Lovecraft.location', 2018, 12 + deprecate :fhtagn, 'Faker::Books::Lovecraft.fhtagn', 2018, 12 + deprecate :deity, 'Faker::Books::Lovecraft.deity', 2018, 12 + deprecate :tome, 'Faker::Books::Lovecraft.tome', 2018, 12 + deprecate :sentence, 'Faker::Books::Lovecraft.sentence', 2018, 12 + deprecate :word, 'Faker::Books::Lovecraft.word', 2018, 12 + deprecate :words, 'Faker::Books::Lovecraft.words', 2018, 12 + deprecate :sentences, 'Faker::Books::Lovecraft.sentences', 2018, 12 + deprecate :paragraph, 'Faker::Books::Lovecraft.paragraph', 2018, 12 + deprecate :paragraphs, 'Faker::Books::Lovecraft.paragraphs', 2018, 12 + deprecate :paragraph_by_chars, 'Faker::Books::Lovecraft.paragraph_by_chars', 2018, 12 + end + end +end diff --git a/test/deprecate/test_deprecate_dune.rb b/test/deprecate/test_deprecate_dune.rb new file mode 100644 index 0000000000..1666a7646d --- /dev/null +++ b/test/deprecate/test_deprecate_dune.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require_relative '../test_helper' + +class TestDeprecateDune < Test::Unit::TestCase + def setup + @tester = Faker::Dune + end + + def test_character + assert @tester.character.match(/\w+/) + end + + def test_title + assert @tester.title.match(/\w+/) + end + + def test_planet + assert @tester.planet.match(/\w+/) + end + + def test_quote + assert @tester.quote.match(/\w+/) + end + + def test_saying + assert @tester.saying.match(/\w+/) + end +end diff --git a/test/faker/default/test_faker_lovecraft.rb b/test/deprecate/test_deprecate_lovecraft.rb similarity index 96% rename from test/faker/default/test_faker_lovecraft.rb rename to test/deprecate/test_deprecate_lovecraft.rb index 09eb0bf9cf..80fc5a7909 100644 --- a/test/faker/default/test_faker_lovecraft.rb +++ b/test/deprecate/test_deprecate_lovecraft.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require_relative '../../test_helper' +require_relative '../test_helper' -class TestFakerLovecraft < Test::Unit::TestCase +class TestDeprecateLovecraft < Test::Unit::TestCase def setup @tester = Faker::Lovecraft @wordlist = I18n.translate('faker.lovecraft.words') diff --git a/test/faker/default/test_faker_book.rb b/test/faker/books/test_book.rb similarity index 100% rename from test/faker/default/test_faker_book.rb rename to test/faker/books/test_book.rb diff --git a/test/faker/books/test_dune.rb b/test/faker/books/test_dune.rb new file mode 100644 index 0000000000..b0a0aef0d3 --- /dev/null +++ b/test/faker/books/test_dune.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require_relative '../../test_helper' + +class TestFakerBooksDune < Test::Unit::TestCase + def setup + @tester = Faker::Books::Dune + end + + def test_character + assert @tester.character.match(/\w+/) + end + + def test_title + assert @tester.title.match(/\w+/) + end + + def test_planet + assert @tester.planet.match(/\w+/) + end + + def test_quote + assert @tester.quote.match(/\w+/) + end + + def test_saying + assert @tester.saying.match(/\w+/) + end +end diff --git a/test/faker/books/test_lovecraft.rb b/test/faker/books/test_lovecraft.rb new file mode 100644 index 0000000000..86b2b76315 --- /dev/null +++ b/test/faker/books/test_lovecraft.rb @@ -0,0 +1,89 @@ +# frozen_string_literal: true + +require_relative '../../test_helper' + +class TestFakerBooksLovecraft < Test::Unit::TestCase + def setup + @tester = Faker::Books::Lovecraft + @wordlist = I18n.translate('faker.lovecraft.words') + end + + # Words delivered by this request should be on the wordlist. + def test_words + @words = @tester.words(1000) + @words.each { |w| assert @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 + + # Faker::Lovecraft.word generates random word from wordlist + def test_word + 1000.times { assert @wordlist.include?(@tester.word) } + end + + # Word should not return any word with spaces + def test_word_without_spaces + 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 + + def test_tome + assert @tester.tome.match(/\w/) + end + + def test_location + assert @tester.location.match(/\w/) + end + + def test_deity + assert @tester.deity.match(/\w/) + end + + def test_fhtagn + assert @tester.fhtagn.match(/\w/) + end +end diff --git a/unreleased_README.md b/unreleased_README.md index ef7c226511..cb42bd6b5a 100644 --- a/unreleased_README.md +++ b/unreleased_README.md @@ -122,7 +122,6 @@ gem 'faker', :git => 'https://github.com/stympy/faker.git', :branch => 'master' - [Faker::Avatar](doc/unreleased/default/avatar.md) - [Faker::Bank](doc/unreleased/default/bank.md) - [Faker::Beer](doc/unreleased/default/beer.md) - - [Faker::Book](doc/unreleased/default/book.md) - [Faker::Boolean](doc/unreleased/default/boolean.md) - [Faker::BossaNova](doc/unreleased/default/bossa_nova.md) - [Faker::Business](doc/unreleased/default/business.md) @@ -147,7 +146,6 @@ gem 'faker', :git => 'https://github.com/stympy/faker.git', :branch => 'master' - [Faker::Dessert](doc/unreleased/default/dessert.md) - [Faker::Device](doc/unreleased/default/device.md) - [Faker::DrivingLicence](doc/unreleased/default/driving_licence.md) - - [Faker::Dune](doc/unreleased/default/dune.md) - [Faker::Educator](doc/unreleased/default/educator.md) - [Faker::ElectricalComponents](doc/unreleased/default/electrical_components.md) - [Faker::Esport](doc/unreleased/default/esport.md) @@ -173,7 +171,6 @@ gem 'faker', :git => 'https://github.com/stympy/faker.git', :branch => 'master' - [Faker::Lorem](doc/unreleased/default/lorem.md) - [Faker::LoremFlickr](doc/unreleased/default/lorem_flickr.md) - [Faker::LoremPixel](doc/unreleased/default/lorem_pixel.md) - - [Faker::Lovecraft](doc/unreleased/default/lovecraft.md) - [Faker::Markdown](doc/unreleased/default/markdown.md) - [Faker::Marketing](doc/unreleased/default/marketing.md) - [Faker::Matz](doc/unreleased/default/matz.md) @@ -217,7 +214,10 @@ gem 'faker', :git => 'https://github.com/stympy/faker.git', :branch => 'master' - [Faker::Blockchain::Tezos](doc/unreleased/blockchain/tezos.md) ### Books + - [Faker::Book](doc/unreleased/books/book.md) - [Faker::Books::CultureSeries](doc/unreleased/books/culture_series.md) + - [Faker::Books::Dune](doc/unreleased/books/dune.md) + - [Faker::Books::Lovecraft](doc/unreleased/books/lovecraft.md) ### Creature - [Faker::Creature::Animal](doc/unreleased/creature/animal.md)