7 require 'active_support'
9 class I18nExceptionsTest
< Test
::Unit::TestCase
10 def test_invalid_locale_stores_locale
12 rescue I18n
::ArgumentError => e
16 def test_invalid_locale_message
18 rescue I18n
::ArgumentError => e
19 assert_equal
'nil is not a valid locale', e
.message
22 def test_missing_translation_data_stores_locale_key_and_options
23 force_missing_translation_data
24 rescue I18n
::ArgumentError => e
25 options
= {:scope => :bar}
26 assert_equal
'de', e
.locale
27 assert_equal
:foo, e
.key
28 assert_equal options
, e
.options
31 def test_missing_translation_data_message
32 force_missing_translation_data
33 rescue I18n
::ArgumentError => e
34 assert_equal
'translation missing: de, bar, foo', e
.message
37 def test_invalid_pluralization_data_stores_entry_and_count
38 force_invalid_pluralization_data
39 rescue I18n
::ArgumentError => e
40 assert_equal
[:bar], e
.entry
41 assert_equal
1, e
.count
44 def test_invalid_pluralization_data_message
45 force_invalid_pluralization_data
46 rescue I18n
::ArgumentError => e
47 assert_equal
'translation data [:bar] can not be used with :count => 1', e
.message
50 def test_missing_interpolation_argument_stores_key_and_string
51 force_missing_interpolation_argument
52 rescue I18n
::ArgumentError => e
53 assert_equal
'bar', e
.key
54 assert_equal
"{{bar}}", e
.string
57 def test_missing_interpolation_argument_message
58 force_missing_interpolation_argument
59 rescue I18n
::ArgumentError => e
60 assert_equal
'interpolation argument bar missing in "{{bar}}"', e
.message
63 def test_reserved_interpolation_key_stores_key_and_string
64 force_reserved_interpolation_key
65 rescue I18n
::ArgumentError => e
66 assert_equal
'scope', e
.key
67 assert_equal
"{{scope}}", e
.string
70 def test_reserved_interpolation_key_message
71 force_reserved_interpolation_key
72 rescue I18n
::ArgumentError => e
73 assert_equal
'reserved key "scope" used in "{{scope}}"', e
.message
77 def force_invalid_locale
78 I18n
.backend
.translate
nil, :foo
81 def force_missing_translation_data
82 I18n
.backend
.store_translations
'de', :bar => nil
83 I18n
.backend
.translate
'de', :foo, :scope => :bar
86 def force_invalid_pluralization_data
87 I18n
.backend
.store_translations
'de', :foo => [:bar]
88 I18n
.backend
.translate
'de', :foo, :count => 1
91 def force_missing_interpolation_argument
92 I18n
.backend
.store_translations
'de', :foo => "{{bar}}"
93 I18n
.backend
.translate
'de', :foo, :baz => 'baz'
96 def force_reserved_interpolation_key
97 I18n
.backend
.store_translations
'de', :foo => "{{scope}}"
98 I18n
.backend
.translate
'de', :foo, :baz => 'baz'