forked from faker-ruby/faker
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow flexible formats for city names.
- Loading branch information
Showing
3 changed files
with
73 additions
and
11 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
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,54 @@ | ||
require File.dirname(__FILE__) + '/test_helper.rb' | ||
|
||
class TestFakerCity < Test::Unit::TestCase | ||
def setup | ||
xx = { | ||
:faker => { | ||
:name => {:first_name => [:alice], :last_name => [:smith]}, | ||
:address => {:city_prefix => [:west], :city_suffix => [:burg]} | ||
} | ||
} | ||
I18n.backend.store_translations(:xx, xx) | ||
|
||
xy = { | ||
:faker => { | ||
:address => { | ||
:city_prefix => [:big], | ||
:city_root => [:rock], | ||
:city_root_suffix => [:ing], | ||
:city_suffix => [:town], | ||
:city_formats => [[:city_prefix, :space, :city_root, :city_root_suffix, :space, :city_suffix]] | ||
} | ||
} | ||
} | ||
I18n.backend.store_translations(:xy, xy) | ||
end | ||
|
||
def test_default_city_root_is_first_name_or_last_name | ||
I18n.with_locale(:xx) do | ||
100.times do | ||
root = Faker::Address.default_root | ||
assert [:alice, :smith].include?(root), "Expected 'alice' or 'smith', but got #{root}" | ||
end | ||
end | ||
end | ||
|
||
def test_default_city_formats | ||
I18n.with_locale(:xx) do | ||
100.times do | ||
cities = ["west alice", "west smith", "west aliceburg", "west smithburg", "aliceburg", "smithburg"] | ||
city = Faker::Address.city | ||
assert cities.include?(city), "Expected <#{cities.join(' / ')}>, but got #{city}" | ||
end | ||
end | ||
end | ||
|
||
def test_city_formats_are_flexible | ||
I18n.with_locale(:xy) do | ||
cities = ['big rocking town'] | ||
city = Faker::Address.city | ||
assert cities.include?(city), "Expected <#{cities.join(' / ')}>, but got #{city}" | ||
end | ||
end | ||
|
||
end |