forked from faker-ruby/faker
/
test_faker_city.rb
53 lines (48 loc) · 1.5 KB
/
test_faker_city.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require File.dirname(__FILE__) + '/test_helper.rb'
class TestFakerCity < Test::Unit::TestCase
def setup
@old_locales = I18n.config.available_locales
xx = {
faker: {
name: { first_name: ['alice'], last_name: ['smith'] },
address: { city_prefix: ['west'], city_suffix: ['burg'] }
}
}
I18n.config.available_locales += [:xx]
I18n.backend.store_translations(:xx, xx)
# rubocop:disable Lint/InterpolationCheck
xy = {
faker: {
address: {
city_prefix: ['big'],
city_root: ['rock'],
city_root_suffix: ['ing'],
city_suffix: ['town'],
city: ['#{city_prefix} #{city_root}#{city_root_suffix} #{city_suffix}']
}
}
}
# rubocop:enable Lint/InterpolationCheck
I18n.config.available_locales += [:xy]
I18n.backend.store_translations(:xy, xy)
end
def teardown
I18n.config.available_locales = @old_locales
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