|
7 | 7 | let(:key) { :invalid_formatter } |
8 | 8 | let(:attributes) { { klass: String, to_format: 'xml' } } |
9 | 9 |
|
| 10 | + before { I18n.default_locale = :de } |
| 11 | + after do |
| 12 | + I18n.available_locales = %i[en] |
| 13 | + I18n.enforce_available_locales = false |
| 14 | + end |
| 15 | + |
10 | 16 | context 'when I18n enforces available locales' do |
11 | 17 | before { I18n.enforce_available_locales = true } |
12 | | - after do |
13 | | - I18n.available_locales = %i[de en] |
14 | | - I18n.enforce_available_locales = false |
15 | | - end |
16 | 18 |
|
17 | 19 | context 'when the fallback locale is available' do |
18 | | - before do |
19 | | - I18n.available_locales = %i[de en] |
20 | | - I18n.default_locale = :de |
21 | | - end |
| 20 | + before { I18n.available_locales = %i[de en] } |
22 | 21 |
|
23 | 22 | it 'returns the translated message' do |
24 | 23 | expect(subject).to eq('cannot convert String to xml') |
25 | 24 | end |
26 | 25 | end |
27 | 26 |
|
28 | 27 | context 'when the fallback locale is not available' do |
29 | | - before do |
30 | | - I18n.available_locales = %i[de jp] |
31 | | - I18n.default_locale = :de |
32 | | - end |
| 28 | + before { I18n.available_locales = %i[de jp] } |
33 | 29 |
|
34 | 30 | it 'returns the translation string' do |
35 | 31 | expect(subject).to eq("grape.errors.messages.#{key}") |
|
39 | 35 |
|
40 | 36 | context 'when I18n does not enforce available locales' do |
41 | 37 | before { I18n.enforce_available_locales = false } |
42 | | - after { I18n.available_locales = %i[de en] } |
43 | 38 |
|
44 | 39 | context 'when the fallback locale is available' do |
45 | | - before do |
46 | | - I18n.available_locales = %i[de en] |
47 | | - I18n.default_locale = :de |
48 | | - end |
| 40 | + before { I18n.available_locales = %i[de en] } |
49 | 41 |
|
50 | 42 | it 'returns the translated message' do |
51 | 43 | expect(subject).to eq('cannot convert String to xml') |
52 | 44 | end |
53 | 45 | end |
54 | 46 |
|
55 | 47 | context 'when the fallback locale is not available' do |
56 | | - before do |
57 | | - I18n.available_locales = %i[de jp] |
58 | | - I18n.default_locale = :de |
59 | | - end |
| 48 | + before { I18n.available_locales = %i[de jp] } |
60 | 49 |
|
61 | 50 | it 'returns the translated message' do |
62 | 51 | expect(subject).to eq('cannot convert String to xml') |
|
0 commit comments