forked from faker-ruby/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_flexible.rb
72 lines (59 loc) · 1.93 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
62
63
64
65
66
67
68
69
70
71
72
# frozen_string_literal: true
require_relative 'test_helper'
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
assert_includes %i[fudge chocolate caramel], Faker::Foodie.yummie
end
end
def test_flexible_single_value
I18n.with_locale(:xx) do
assert_equal 'delicious', Faker::Foodie.taste
end
end
def test_flexible_fallbacks_to_english
I18n.backend.store_translations(:en, faker: { chow: { taste: 'superdelicious' } })
I18n.with_locale(:home) do
assert_equal 'superdelicious', Faker::Foodie.taste
end
I18n.reload!
end
def test_raises_missing_translation_data_when_not_even_english_defined
I18n.with_locale(:xx) do
assert_raise(I18n::MissingTranslationData) do
Faker::Foodie.eeew
end
end
end
def test_address_is_flexible
I18n.with_locale(:home) do
assert_includes %i[bed hospital airplane], Faker::Address.birthplace
end
end
def test_name_is_flexible
I18n.with_locale(:kindergarden) do
assert_includes %i[alice cheryl tatiana], Faker::Name.girls_name
end
end
def test_company_is_flexible
I18n.with_locale(:work) do
assert_equal(:work, Faker::Company.do_stuff)
end
end
end