Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/default/lorem.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Faker::Lorem

```ruby
# Keyword arguments: exclude_words (prevent specific words from being produced)
Faker::Lorem.word #=> "repellendus"
Faker::Lorem.word(exclude_words: 'error') #=> "nisi"
Faker::Lorem.word(exclude_words: 'id, error') #=> "et"
Faker::Lorem.word(exclude_words: ['id', 'error']) #=> "consequatur"

# Keyword arguments: number, supplemental (words from a supplementary list of Lorem-like words)
Faker::Lorem.words #=> ["dolores", "adipisci", "nesciunt"]
Expand Down
7 changes: 5 additions & 2 deletions lib/faker/default/lorem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ class << self
#
# @example
# Faker::Lorem.word #=> "soluto"
# Faker::Lorem.word(exclude_words: 'error') #=> "nisi"
# Faker::Lorem.word(exclude_words: 'id, error') #=> "et"
# Faker::Lorem.word(exclude_words: ['id', 'error']) #=> "consequatur"
#
# @faker.version 2.1.3
def word
sample(translate('faker.lorem.words'))
def word(exclude_words: nil)
words(number: 1, exclude_words: exclude_words).first
end

##
Expand Down
18 changes: 17 additions & 1 deletion test/faker/default/test_faker_lorem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,28 @@ def test_supplemental_words

# Faker::Lorem.word generates random word from standard wordlist
def test_word
@tester = Faker::Lorem
@standard_wordlist = I18n.translate('faker.lorem.words')

100.times { assert_includes @standard_wordlist, @tester.word }
end

def test_excluded_words_on_word
excluded_words_array = @tester.words(number: 2)
w = @tester.word(exclude_words: excluded_words_array)

assert_not_equal w, excluded_words_array[0]
assert_not_equal w, excluded_words_array[1]
end

def test_excluded_words_as_string_on_word
excluded_words_array = @tester.words(number: 2)
excluded_word_string = excluded_words_array.join(', ')
w = @tester.word(exclude_words: excluded_word_string)

assert_not_equal w, excluded_words_array[0]
assert_not_equal w, excluded_words_array[1]
end

def test_exact_sentence_word_count
assert_equal 2, @tester.sentence(word_count: 2, supplemental: false, random_words_to_add: 0).split.length
end
Expand Down