forked from ruby-grape/grape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_spec.rb
81 lines (62 loc) · 2.12 KB
/
base_spec.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
73
74
75
76
77
78
79
80
81
# frozen_string_literal: true
describe Grape::Exceptions::Base do
describe '#to_s' do
subject { described_class.new(message: message).to_s }
let(:message) { 'a_message' }
it { is_expected.to eq(message) }
end
describe '#message' do
subject { described_class.new(message: message).message }
let(:message) { 'a_message' }
it { is_expected.to eq(message) }
end
describe '#compose_message' do
subject { described_class.new.send(:compose_message, key, **attributes) }
let(:key) { :invalid_formatter }
let(:attributes) { { klass: String, to_format: 'xml' } }
after do
I18n.enforce_available_locales = true
I18n.available_locales = %i[en]
I18n.locale = :en
I18n.default_locale = :en
I18n.reload!
end
context 'when I18n enforces available locales' do
before { I18n.enforce_available_locales = true }
context 'when the fallback locale is available' do
before do
I18n.available_locales = %i[de en]
I18n.default_locale = :de
end
it 'returns the translated message' do
expect(subject).to eq('cannot convert String to xml')
end
end
context 'when the fallback locale is not available' do
before do
I18n.available_locales = %i[de jp]
I18n.locale = :de
I18n.default_locale = :de
end
it 'returns the translation string' do
expect(subject).to eq("grape.errors.messages.#{key}")
end
end
end
context 'when I18n does not enforce available locales' do
before { I18n.enforce_available_locales = false }
context 'when the fallback locale is available' do
before { I18n.available_locales = %i[de en] }
it 'returns the translated message' do
expect(subject).to eq('cannot convert String to xml')
end
end
context 'when the fallback locale is not available' do
before { I18n.available_locales = %i[de jp] }
it 'returns the translated message' do
expect(subject).to eq('cannot convert String to xml')
end
end
end
end
end