/
test_flexible.rb
61 lines (52 loc) · 1.64 KB
/
test_flexible.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
54
55
56
57
58
59
60
61
require File.dirname(__FILE__) + '/test_helper.rb'
module Faker
class Foodie < Base
flexible :chow
end
end
class TestFlexible < Test::Unit::TestCase
def setup
@old_locales = I18n.config.available_locales
I18n.config.available_locales += %i[xx home kindergarden work]
I18n.backend.store_translations(:xx, faker: { chow: { yummie: %i[fudge chocolate caramel], taste: 'delicious' } })
I18n.backend.store_translations(:home, faker: { address: { birthplace: %i[bed hospital airplane] } })
I18n.backend.store_translations(:kindergarden, faker: { name: { girls_name: %i[alice cheryl tatiana] } })
I18n.backend.store_translations(:work, faker: { company: { do_stuff: %i[work work work] } })
end
def teardown
I18n.config.available_locales = @old_locales
end
def test_flexible_multiple_values
I18n.with_locale(:xx) do
actual = Faker::Foodie.yummie
assert %i[fudge chocolate caramel].include? actual
end
end
def test_flexible_single_value
I18n.with_locale(:xx) do
assert_equal 'delicious', Faker::Foodie.taste
end
end
def test_raises_no_method_error
I18n.with_locale(:xx) do
assert_raise(NoMethodError) do
Faker::Foodie.eeew
end
end
end
def test_address_is_flexible
I18n.with_locale(:home) do
assert %i[bed hospital airplane].include? Faker::Address.birthplace
end
end
def test_name_is_flexible
I18n.with_locale(:kindergarden) do
assert %i[alice cheryl tatiana].include? Faker::Name.girls_name
end
end
def test_company_is_flexible
I18n.with_locale(:work) do
assert Faker::Company.do_stuff == :work
end
end
end