Class: I18nSimpleBackendTranslateTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
I18nSimpleBackendTestSetup
Defined in:
lib/vendor/i18n/test/simple_backend_test.rb

Instance Method Summary collapse

Methods included from I18nSimpleBackendTestSetup

#add_datetime_translations, #backend_get_translations, #setup_backend

Instance Method Details

#test_given_no_keys_it_returns_the_defaultObject



145
146
147
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 145

def test_given_no_keys_it_returns_the_default
  assert_equal 'default', @backend.translate('en', nil, :default => 'default')
end

#test_translate_an_array_of_keys_translates_all_of_themObject



163
164
165
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 163

def test_translate_an_array_of_keys_translates_all_of_them
  assert_equal %w(bar baz), @backend.translate('en', [:bar, :baz], :scope => [:foo])
end

#test_translate_calls_interpolateObject



172
173
174
175
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 172

def test_translate_calls_interpolate
  @backend.expects(:interpolate).with 'en', 'bar', {}
  @backend.translate 'en', :bar, :scope => [:foo]
end

#test_translate_calls_interpolate_including_count_as_a_valueObject



177
178
179
180
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 177

def test_translate_calls_interpolate_including_count_as_a_value
  @backend.expects(:interpolate).with 'en', 'bar', {:count => 1}
  @backend.translate 'en', :bar, :scope => [:foo], :count => 1
end

#test_translate_calls_lookup_with_locale_givenObject



140
141
142
143
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 140

def test_translate_calls_lookup_with_locale_given
  @backend.expects(:lookup).with('de', :bar, [:foo]).returns 'bar'
  @backend.translate 'de', :bar, :scope => [:foo]
end

#test_translate_calls_pluralizeObject



167
168
169
170
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 167

def test_translate_calls_pluralize
  @backend.expects(:pluralize).with 'en', 'bar', 1
  @backend.translate 'en', :bar, :scope => [:foo], :count => 1
end

#test_translate_given_a_symbol_as_a_default_translates_the_symbolObject



149
150
151
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 149

def test_translate_given_a_symbol_as_a_default_translates_the_symbol
  assert_equal 'bar', @backend.translate('en', nil, :scope => [:foo], :default => :bar)
end

#test_translate_given_an_array_as_default_uses_the_first_matchObject



153
154
155
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 153

def test_translate_given_an_array_as_default_uses_the_first_match
  assert_equal 'bar', @backend.translate('en', :does_not_exist, :scope => [:foo], :default => [:does_not_exist_2, :bar])
end

#test_translate_given_an_array_of_inexistent_keys_it_raises_missing_translation_dataObject



157
158
159
160
161
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 157

def test_translate_given_an_array_of_inexistent_keys_it_raises_missing_translation_data
  assert_raises I18n::MissingTranslationData do
    @backend.translate('en', :does_not_exist, :scope => [:foo], :default => [:does_not_exist_2, :does_not_exist_3])
  end
end

#test_translate_given_nil_as_a_locale_raises_an_argument_errorObject



182
183
184
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 182

def test_translate_given_nil_as_a_locale_raises_an_argument_error
  assert_raises(I18n::InvalidLocale){ @backend.translate nil, :bar }
end

#test_translate_with_a_bogus_key_and_no_default_raises_missing_translation_dataObject



186
187
188
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 186

def test_translate_with_a_bogus_key_and_no_default_raises_missing_translation_data
  assert_raises(I18n::MissingTranslationData){ @backend.translate 'de', :bogus }
end