-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5617db
commit 773ee31
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Faker::FunnyName | ||
|
||
```ruby | ||
Faker::FunnyName.name #=> "Sam Pull" | ||
|
||
Faker::FunnyName.two_word_name #=> "Shirley Knot" | ||
|
||
Faker::FunnyName.three_word_name #=> "Carson O. Gin" | ||
|
||
Faker::FunnyName.four_word_name #=> "Maude L. T. Ford" | ||
|
||
Faker::FunnyName.name_with_initial #=> "Heather N. Yonn" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Faker | ||
class FunnyName < Base | ||
flexible :funny_name | ||
|
||
class << self | ||
def name | ||
fetch('funny_name.name') | ||
end | ||
|
||
def two_word_name | ||
two_word_names = fetch_all('funny_name.name').select do |name| | ||
name.count(' ') == 1 | ||
end | ||
|
||
sample(two_word_names) | ||
end | ||
|
||
def three_word_name | ||
three_word_names = fetch_all('funny_name.name').select do |name| | ||
name.count(' ') == 2 | ||
end | ||
|
||
sample(three_word_names) | ||
end | ||
|
||
def four_word_name | ||
four_word_names = fetch_all('funny_name.name').select do |name| | ||
name.count(' ') == 3 | ||
end | ||
|
||
sample(four_word_names) | ||
end | ||
|
||
def name_with_initial | ||
names_with_initials = fetch_all('funny_name.name').select do |name| | ||
name.count('.') > 0 | ||
end | ||
|
||
sample(names_with_initials) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb') | ||
|
||
class TestFakerFunnyName < Test::Unit::TestCase | ||
|
||
def setup | ||
@tester = Faker::FunnyName | ||
end | ||
|
||
def test_name | ||
res = @tester.name | ||
assert res.is_a?(String) && !res.empty? | ||
end | ||
|
||
def test_two_word_name | ||
res = @tester.two_word_name | ||
assert res.count(' ') == 1 | ||
end | ||
|
||
def test_three_word_name | ||
res = @tester.three_word_name | ||
assert res.count(' ') == 2 | ||
end | ||
|
||
def test_four_word_name | ||
res = @tester.four_word_name | ||
assert res.count(' ') == 3 | ||
end | ||
|
||
def test_name_with_initial | ||
res = @tester.name_with_initial | ||
assert res.count('.') > 0 | ||
end | ||
end |