Class: I18nTest
- Defined in:
- lib/vendor/i18n/test/i18n_test.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #test_can_set_backend ⇒ Object
- #test_can_set_default_locale ⇒ Object
- #test_can_set_default_separator ⇒ Object
- #test_can_set_exception_handler ⇒ Object
- #test_can_set_locale_to_thread_current ⇒ Object
- #test_class_exception_handler ⇒ Object
- #test_defaults_to_dot_as_separator ⇒ Object
- #test_delegates_localize_to_backend ⇒ Object
- #test_delegates_translate_to_backend ⇒ Object
- #test_localize_nil_raises_argument_error ⇒ Object
- #test_localize_object_raises_argument_error ⇒ Object
- #test_normalize_keys ⇒ Object
- #test_proc_exception_handler ⇒ Object
-
#test_translate_given_a_bogus_key_raises_missing_translation_data ⇒ Object
def test_translate_given_no_args_raises_missing_translation_data assert_equal “translation missing: en, no key”, I18n.t end.
- #test_translate_given_no_locale_uses_i18n_locale ⇒ Object
- #test_translate_on_nested_symbol_keys_works ⇒ Object
- #test_translate_with_array_as_scope_works ⇒ Object
- #test_translate_with_array_containing_dot_separated_strings_as_scope_works ⇒ Object
- #test_translate_with_dot_separated_key_array_and_scope_works ⇒ Object
- #test_translate_with_key_array_and_dot_separated_scope_works ⇒ Object
- #test_translate_with_nested_string_keys_works ⇒ Object
- #test_translate_with_options_using_scope_works ⇒ Object
- #test_uses_custom_exception_handler ⇒ Object
- #test_uses_default_locale_as_locale_by_default ⇒ Object
- #test_uses_en_us_as_default_locale_by_default ⇒ Object
- #test_uses_passed_separator_to_normalize_keys ⇒ Object
- #test_uses_simple_backend_set_by_default ⇒ Object
Instance Method Details
#setup ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 6 def setup I18n.backend.store_translations :'en', { :currency => { :format => { :separator => '.', :delimiter => ',', } } } end |
#test_can_set_backend ⇒ Object
21 22 23 24 25 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 21 def test_can_set_backend assert_nothing_raised { I18n.backend = self } assert_equal self, I18n.backend I18n.backend = I18n::Backend::Simple.new end |
#test_can_set_default_locale ⇒ Object
31 32 33 34 35 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 31 def test_can_set_default_locale assert_nothing_raised { I18n.default_locale = 'de' } assert_equal :de, I18n.default_locale I18n.default_locale = :en end |
#test_can_set_default_separator ⇒ Object
52 53 54 55 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 52 def test_can_set_default_separator assert_nothing_raised { I18n.default_separator = "\001" } I18n.default_separator = '.' # revert it end |
#test_can_set_exception_handler ⇒ Object
69 70 71 72 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 69 def test_can_set_exception_handler assert_nothing_raised { I18n.exception_handler = :custom_exception_handler } I18n.exception_handler = :default_exception_handler # revert it end |
#test_can_set_locale_to_thread_current ⇒ Object
41 42 43 44 45 46 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 41 def test_can_set_locale_to_thread_current assert_nothing_raised { I18n.locale = 'de' } assert_equal :de, I18n.locale assert_equal :de, Thread.current[:locale] I18n.locale = :en end |
#test_class_exception_handler ⇒ Object
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 152 def test_class_exception_handler I18n.exception_handler = Class.new do def call(exception, locale, key, ) "No exception here! [Class handler]" end end.new assert_equal "No exception here! [Class handler]", I18n.translate(:test_class_handler) ensure I18n.exception_handler = :default_exception_handler end |
#test_defaults_to_dot_as_separator ⇒ Object
48 49 50 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 48 def test_defaults_to_dot_as_separator assert_equal '.', I18n.default_separator end |
#test_delegates_localize_to_backend ⇒ Object
86 87 88 89 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 86 def test_delegates_localize_to_backend I18n.backend.expects(:localize).with 'de', :whatever, :default I18n.localize :whatever, :locale => 'de' end |
#test_delegates_translate_to_backend ⇒ Object
81 82 83 84 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 81 def test_delegates_translate_to_backend I18n.backend.expects(:translate).with 'de', :foo, {} I18n.translate :foo, :locale => 'de' end |
#test_localize_nil_raises_argument_error ⇒ Object
135 136 137 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 135 def test_localize_nil_raises_argument_error assert_raises(I18n::ArgumentError) { I18n.l nil } end |
#test_localize_object_raises_argument_error ⇒ Object
139 140 141 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 139 def test_localize_object_raises_argument_error assert_raises(I18n::ArgumentError) { I18n.l Object.new } end |
#test_normalize_keys ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 57 def test_normalize_keys assert_equal [:en, :foo, :bar], I18n.send(:normalize_translation_keys, :en, :bar, :foo) assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, :'baz.buz', :'foo.bar') assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, 'baz.buz', 'foo.bar') assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, %w(baz buz), %w(foo bar)) assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, [:baz, :buz], [:foo, :bar]) end |
#test_proc_exception_handler ⇒ Object
143 144 145 146 147 148 149 150 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 143 def test_proc_exception_handler I18n.exception_handler = Proc.new { |exception, locale, key, | "No exception here! [Proc handler]" } assert_equal "No exception here! [Proc handler]", I18n.translate(:test_proc_handler) ensure I18n.exception_handler = :default_exception_handler end |
#test_translate_given_a_bogus_key_raises_missing_translation_data ⇒ Object
def test_translate_given_no_args_raises_missing_translation_data
assert_equal "translation missing: en, no key", I18n.t
end
131 132 133 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 131 def test_translate_given_a_bogus_key_raises_missing_translation_data assert_equal "translation missing: en, bogus", I18n.t(:bogus) end |
#test_translate_given_no_locale_uses_i18n_locale ⇒ Object
91 92 93 94 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 91 def test_translate_given_no_locale_uses_i18n_locale I18n.backend.expects(:translate).with :en, :foo, {} I18n.translate :foo end |
#test_translate_on_nested_symbol_keys_works ⇒ Object
96 97 98 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 96 def test_translate_on_nested_symbol_keys_works assert_equal ".", I18n.t(:'currency.format.separator') end |
#test_translate_with_array_as_scope_works ⇒ Object
104 105 106 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 104 def test_translate_with_array_as_scope_works assert_equal ".", I18n.t(:separator, :scope => %w(currency format)) end |
#test_translate_with_array_containing_dot_separated_strings_as_scope_works ⇒ Object
108 109 110 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 108 def test_translate_with_array_containing_dot_separated_strings_as_scope_works assert_equal ".", I18n.t(:separator, :scope => ['currency.format']) end |
#test_translate_with_dot_separated_key_array_and_scope_works ⇒ Object
116 117 118 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 116 def test_translate_with_dot_separated_key_array_and_scope_works assert_equal [".", ","], I18n.t(%w(format.separator format.delimiter), :scope => 'currency') end |
#test_translate_with_key_array_and_dot_separated_scope_works ⇒ Object
112 113 114 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 112 def test_translate_with_key_array_and_dot_separated_scope_works assert_equal [".", ","], I18n.t(%w(separator delimiter), :scope => 'currency.format') end |
#test_translate_with_nested_string_keys_works ⇒ Object
100 101 102 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 100 def test_translate_with_nested_string_keys_works assert_equal ".", I18n.t('currency.format.separator') end |
#test_translate_with_options_using_scope_works ⇒ Object
120 121 122 123 124 125 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 120 def I18n.backend.expects(:translate).with('de', :precision, :scope => :"currency.format") I18n. :locale => 'de', :scope => :'currency.format' do |locale| locale.t :precision end end |
#test_uses_custom_exception_handler ⇒ Object
74 75 76 77 78 79 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 74 def test_uses_custom_exception_handler I18n.exception_handler = :custom_exception_handler I18n.expects(:custom_exception_handler) I18n.translate :bogus I18n.exception_handler = :default_exception_handler # revert it end |
#test_uses_default_locale_as_locale_by_default ⇒ Object
37 38 39 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 37 def test_uses_default_locale_as_locale_by_default assert_equal I18n.default_locale, I18n.locale end |
#test_uses_en_us_as_default_locale_by_default ⇒ Object
27 28 29 |
# File 'lib/vendor/i18n/test/i18n_test.rb', line 27 def test_uses_en_us_as_default_locale_by_default assert_equal :en, I18n.default_locale end |