Class: I18nTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 9

def setup
  I18n.backend.store_translations :'en', {
    :currency => {
      :format => {
        :separator => '.',
        :delimiter => ',',
      }
    }
  }
end

#test_can_set_backendObject



24
25
26
27
28
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 24

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_localeObject



34
35
36
37
38
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 34

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_exception_handlerObject



51
52
53
54
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 51

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_currentObject



44
45
46
47
48
49
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 44

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_delegates_localize_to_backendObject



68
69
70
71
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 68

def test_delegates_localize_to_backend
  I18n.backend.expects(:localize).with 'de', :whatever, :default
  I18n.localize :whatever, :locale => 'de'
end

#test_delegates_translate_to_backendObject



63
64
65
66
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 63

def test_delegates_translate_to_backend
  I18n.backend.expects(:translate).with 'de', :foo, {}
  I18n.translate :foo, :locale => 'de'
end

#test_localize_nil_raises_argument_errorObject



117
118
119
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 117

def test_localize_nil_raises_argument_error
  assert_raise(I18n::ArgumentError) { I18n.l nil }
end

#test_localize_object_raises_argument_errorObject



121
122
123
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 121

def test_localize_object_raises_argument_error
  assert_raise(I18n::ArgumentError) { I18n.l Object.new }
end

#test_translate_given_a_bogus_key_raises_missing_translation_dataObject

def test_translate_given_no_args_raises_missing_translation_data

assert_equal "translation missing: en, no key", I18n.t

end



113
114
115
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 113

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_localeObject



73
74
75
76
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 73

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_worksObject



78
79
80
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 78

def test_translate_on_nested_symbol_keys_works
  assert_equal ".", I18n.t(:'currency.format.separator')
end

#test_translate_with_array_as_scope_worksObject



86
87
88
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 86

def test_translate_with_array_as_scope_works
  assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
end

#test_translate_with_array_containing_dot_separated_strings_as_scope_worksObject



90
91
92
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 90

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_worksObject



98
99
100
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 98

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_worksObject



94
95
96
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 94

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_worksObject



82
83
84
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 82

def test_translate_with_nested_string_keys_works
  assert_equal ".", I18n.t('currency.format.separator')
end

#test_translate_with_options_using_scope_worksObject



102
103
104
105
106
107
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 102

def test_translate_with_options_using_scope_works
  I18n.backend.expects(:translate).with('de', :precision, :scope => :"currency.format")
  I18n.with_options :locale => 'de', :scope => :'currency.format' do |locale|
    locale.t :precision
  end
end

#test_uses_custom_exception_handlerObject



56
57
58
59
60
61
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 56

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_defaultObject



40
41
42
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 40

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_defaultObject



30
31
32
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 30

def test_uses_en_us_as_default_locale_by_default
  assert_equal 'en', I18n.default_locale
end

#test_uses_simple_backend_set_by_defaultObject



20
21
22
# File 'lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb', line 20

def test_uses_simple_backend_set_by_default
  assert I18n.backend.is_a?(I18n::Backend::Simple)
end