Permalink
Browse files

restructure tests: all testcases are now in the tests/cases directory…

…. clean up /refactor api tests: can now include all api test modules into one test case.
  • Loading branch information...
Sven Fuchs
Sven Fuchs committed Dec 5, 2009
1 parent 4397b3a commit 99c308e8170a50643da96eb74da6448f1c4f26bc
Showing with 887 additions and 1,469 deletions.
  1. +4 −4 test/all.rb
  2. +8 −8 test/api/basics.rb
  3. +40 −0 test/api/defaults.rb
  4. +65 −67 test/api/interpolation.rb
  5. +0 −52 test/api/lambda.rb
  6. +31 −38 test/api/link.rb
  7. +69 −50 test/api/localization/date.rb
  8. +66 −42 test/api/localization/date_time.rb
  9. +0 −26 test/api/localization/lambda.rb
  10. +54 −0 test/api/localization/procs.rb
  11. +71 −52 test/api/localization/time.rb
  12. +38 −0 test/api/lookup.rb
  13. +22 −24 test/api/pluralization.rb
  14. +40 −0 test/api/procs.rb
  15. +0 −51 test/api/translation.rb
  16. +0 −3 test/backend/active_record/all.rb
  17. +0 −54 test/backend/active_record/api_test.rb
  18. +0 −166 test/backend/active_record/setup.rb
  19. +0 −88 test/backend/all/api_test.rb
  20. +0 −80 test/backend/chain/api_test.rb
  21. +0 −84 test/backend/fallbacks/api_test.rb
  22. +0 −86 test/backend/pluralization/api_test.rb
  23. +0 −5 test/backend/simple/all.rb
  24. +0 −92 test/backend/simple/api_test.rb
  25. +0 −24 test/backend/simple/lookup_test.rb
  26. +0 −147 test/backend/simple/setup.rb
  27. +0 −83 test/backend/simple/translations_test.rb
  28. +28 −0 test/cases/api/active_record_test.rb
  29. +37 −0 test/cases/api/all_features_test.rb
  30. +26 −0 test/cases/api/chain_test.rb
  31. +33 −0 test/cases/api/fallbacks_test.rb
  32. +33 −0 test/cases/api/pluralization_test.rb
  33. +21 −0 test/cases/api/simple_test.rb
  34. +5 −8 ...ctive_record_missing/active_record_missing_test.rb → cases/backend/active_record/missing_test.rb}
  35. +13 −3 test/{backend/active_record → cases/backend}/active_record_test.rb
  36. +7 −7 test/{backend/cache → cases/backend}/cache_test.rb
  37. +1 −1 test/{backend/chain → cases/backend}/chain_test.rb
  38. +5 −5 test/{backend/fallbacks → cases/backend}/fallbacks_test.rb
  39. +1 −1 test/{backend/simple → cases/backend}/helpers_test.rb
  40. +12 −10 test/{backend/metadata → cases/backend}/metadata_test.rb
  41. +10 −10 test/{backend/pluralization → cases/backend}/pluralization_test.rb
  42. +77 −0 test/cases/backend/simple_test.rb
  43. +15 −15 test/{ → cases}/core_ext/string/interpolate_test.rb
  44. +1 −4 test/{ → cases}/gettext/api_test.rb
  45. +2 −2 test/{ → cases}/gettext/backend_test.rb
  46. +1 −1 test/{ → cases}/i18n_exceptions_test.rb
  47. +2 −2 test/{ → cases}/i18n_load_path_test.rb
  48. +1 −1 test/{ → cases}/i18n_test.rb
  49. +1 −3 test/{ → cases}/locale/fallbacks_test.rb
  50. +1 −3 test/{ → cases}/locale/tag/rfc4646_test.rb
  51. +1 −3 test/{ → cases}/locale/tag/simple_test.rb
  52. +45 −30 test/test_helper.rb
  53. +0 −34 test/with_options.rb
View
@@ -1,8 +1,8 @@
# encoding: utf-8
-base = File.dirname(__FILE__)
-$LOAD_PATH.unshift base
+dir = File.dirname(__FILE__)
+$LOAD_PATH.unshift(dir)
-Dir["#{base}/**/*_test.rb"].sort.each do |file|
- require file.sub(/^#{base}\/(.*)\.rb$/, '\1')
+Dir["#{dir}/**/*_test.rb"].sort.each do |file|
+ require file.sub(/^#{dir}\/(.*)\.rb$/, '\1')
end
View
@@ -1,14 +1,14 @@
# encoding: utf-8
module Tests
- module Backend
- module Api
- module Basics
- def test_available_locales
- backend_store_translations 'de', :foo => 'bar'
- backend_store_translations 'en', :foo => 'foo'
- assert_equal ['de', 'en'], I18n.backend.available_locales.map{|locale| locale.to_s }.sort
- end
+ module Api
+ module Basics
+ def test_available_locales
+ store_translations('de', :foo => 'bar')
+ store_translations('en', :foo => 'foo')
+
+ assert I18n.available_locales.include?(:de)
+ assert I18n.available_locales.include?(:en)
end
end
end
View
@@ -0,0 +1,40 @@
+# encoding: utf-8
+
+module Tests
+ module Api
+ module Defaults
+ def setup
+ super
+ store_translations(:foo => { :bar => 'bar', :baz => 'baz' })
+ end
+
+ define_method "test defaults: given nil as a key it returns the given default" do
+ assert_equal 'default', I18n.t(nil, :default => 'default')
+ end
+
+ define_method "test defaults: given a symbol as a default it translates the symbol" do
+ assert_equal 'bar', I18n.t(nil, :default => :'foo.bar')
+ end
+
+ define_method "test defaults: given a symbol as a default and a scope it stays inside the scope when looking up the symbol" do
+ assert_equal 'bar', I18n.t(:missing, :default => :bar, :scope => :foo)
+ end
+
+ define_method "test defaults: given an array as a default it returns the first match" do
+ assert_equal 'bar', I18n.t(:does_not_exist, :default => [:does_not_exist_2, :'foo.bar'])
+ end
+
+ define_method "test defaults: given an array of missing keys it raises a MissingTranslationData exception" do
+ assert_raises I18n::MissingTranslationData do
+ I18n.t(:does_not_exist, :default => [:does_not_exist_2, :does_not_exist_3], :raise => true)
+ end
+ end
+
+ define_method "test defaults: using a custom scope separator" do
+ # data must have been stored using the custom separator when using the ActiveRecord backend
+ I18n.backend.store_translations(:en, { :foo => { :bar => 'bar' } }, { :separator => '|' })
+ assert_equal 'bar', I18n.t(nil, :default => :'foo|bar', :separator => '|')
+ end
+ end
+ end
+end
View
@@ -1,93 +1,91 @@
# encoding: utf-8
module Tests
- module Backend
- module Api
- module Interpolation
- def interpolate(*args)
- options = args.last.is_a?(Hash) ? args.pop : {}
- key = args.pop
- I18n.backend.translate('en', key, options)
- end
+ module Api
+ module Interpolation
+ def interpolate(*args)
+ options = args.last.is_a?(Hash) ? args.pop : {}
+ key = args.pop
+ I18n.backend.translate('en', key, options)
+ end
- def test_interpolation_given_no_interpolation_values_it_does_not_alter_the_string
- assert_equal 'Hi {{name}}!', interpolate(:default => 'Hi {{name}}!')
- end
+ define_method "test interpolation: given no values it does not alter the string" do
+ assert_equal 'Hi {{name}}!', interpolate(:default => 'Hi {{name}}!')
+ end
- def test_interpolation_given_interpolation_values_it_interpolates_the_values_to_the_string
- assert_equal 'Hi David!', interpolate(:default => 'Hi {{name}}!', :name => 'David')
- end
+ define_method "test interpolation: given values it interpolates them into the string" do
+ assert_equal 'Hi David!', interpolate(:default => 'Hi {{name}}!', :name => 'David')
+ end
- def test_interpolation_given_interpolation_values_with_nil_values_it_interpolates_the_values_to_the_string
- assert_equal 'Hi !', interpolate(:default => 'Hi {{name}}!', :name => nil)
- end
+ define_method "test interpolation: given a nil value it still interpolates it into the string" do
+ assert_equal 'Hi !', interpolate(:default => 'Hi {{name}}!', :name => nil)
+ end
- def test_interpolation_given_a_lambda_as_a_value_it_calls_it_when_the_string_contains_the_key
- assert_equal 'Hi David!', interpolate(:default => 'Hi {{name}}!', :name => lambda { 'David' })
- end
+ define_method "test interpolation: given a lambda as a value it calls it if the string contains the key" do
+ assert_equal 'Hi David!', interpolate(:default => 'Hi {{name}}!', :name => lambda { 'David' })
+ end
- def test_interpolation_given_a_lambda_as_a_value_it_does_not_call_it_when_the_string_does_not_contain_the_key
- assert_nothing_raised { interpolate(:default => 'Hi!', :name => lambda { raise 'fail' }) }
- end
+ define_method "test interpolation: given a lambda as a value it does not call it if the string does not contain the key" do
+ assert_nothing_raised { interpolate(:default => 'Hi!', :name => lambda { raise 'fail' }) }
+ end
- def test_interpolation_given_interpolation_values_but_missing_a_key_it_raises_a_missing_interpolation_argument_exception
- assert_raises(I18n::MissingInterpolationArgument) do
- interpolate(:default => '{{foo}}', :bar => 'bar')
- end
+ define_method "test interpolation: given values but missing a key it raises I18n::MissingInterpolationArgument" do
+ assert_raises(I18n::MissingInterpolationArgument) do
+ interpolate(:default => '{{foo}}', :bar => 'bar')
end
+ end
- def test_interpolation_does_not_raise_missing_interpolation_argument_exceptions_for_escaped_variables
- assert_nothing_raised(I18n::MissingInterpolationArgument) do
- assert_equal 'Barr {{foo}}', interpolate(:default => '{{bar}} \{{foo}}', :bar => 'Barr')
- end
+ define_method "test interpolation: it does not raise I18n::MissingInterpolationArgument for escaped variables" do
+ assert_nothing_raised(I18n::MissingInterpolationArgument) do
+ assert_equal 'Barr {{foo}}', interpolate(:default => '{{bar}} \{{foo}}', :bar => 'Barr')
end
+ end
- def test_interpolation_does_not_change_the_original_stored_translation_string_and_allows_reinterpolation
- I18n.backend.store_translations(:en, :interpolate => 'Hi {{name}}!')
- assert_equal 'Hi David!', interpolate(:interpolate, :name => 'David')
- assert_equal 'Hi Yehuda!', interpolate(:interpolate, :name => 'Yehuda')
- # assert_equal 'Hi {{name}}!', I18n.backend.instance_variable_get(:@translations)[:en][:interpolate]
- end
+ define_method "test interpolation: it does not change the original, stored translation string" do
+ I18n.backend.store_translations(:en, :interpolate => 'Hi {{name}}!')
+ assert_equal 'Hi David!', interpolate(:interpolate, :name => 'David')
+ assert_equal 'Hi Yehuda!', interpolate(:interpolate, :name => 'Yehuda')
+ end
- def test_interpolate_with_ruby_1_9_syntax
- assert_equal 'Hi David!', interpolate(:default => 'Hi %{name}!', :name => 'David')
- end
+ define_method "test interpolation: works with Ruby 1.9 syntax" do
+ assert_equal 'Hi David!', interpolate(:default => 'Hi %{name}!', :name => 'David')
+ end
- def test_interpolate_given_a_value_hash_interpolates_into_unicode_string
- assert_equal 'Häi David!', interpolate(:default => 'Häi {{name}}!', :name => 'David')
- end
+ define_method "test interpolation: given the translation is in utf-8 it still works" do
+ assert_equal 'Häi David!', interpolate(:default => 'Häi {{name}}!', :name => 'David')
+ end
- def test_interpolate_given_a_unicode_value_hash_interpolates_to_the_string
- assert_equal 'Hi ゆきひろ!', interpolate(:default => 'Hi {{name}}!', :name => 'ゆきひろ')
- end
+ define_method "test interpolation: given the value is in utf-8 it still works" do
+ assert_equal 'Hi ゆきひろ!', interpolate(:default => 'Hi {{name}}!', :name => 'ゆきひろ')
+ end
- def test_interpolate_given_a_unicode_value_hash_interpolates_into_unicode_string
- assert_equal 'こんにちは、ゆきひろさん!', interpolate(:default => 'こんにちは、{{name}}さん!', :name => 'ゆきひろ')
- end
+ define_method "test interpolation: given the translation and the value are in utf-8 it still works" do
+ assert_equal 'こんにちは、ゆきひろさん!', interpolate(:default => 'こんにちは、{{name}}さん!', :name => 'ゆきひろ')
+ end
- if Kernel.const_defined?(:Encoding)
- def test_interpolate_given_a_non_unicode_multibyte_value_hash_interpolates_into_a_string_with_the_same_encoding
- assert_equal euc_jp('Hi ゆきひろ!'), interpolate(:default => 'Hi {{name}}!', :name => euc_jp('ゆきひろ'))
- end
+ if Kernel.const_defined?(:Encoding)
+ define_method "test interpolation: given a utf-8 translation and a euc-jp value it returns a translation in euc-jp" do
+ assert_equal euc_jp('Hi ゆきひろ!'), interpolate(:default => 'Hi {{name}}!', :name => euc_jp('ゆきひろ'))
+ end
- def test_interpolate_given_a_unicode_value_hash_into_a_non_unicode_multibyte_string_raises_encoding_compatibility_error
- assert_raises(Encoding::CompatibilityError) do
- interpolate(:default => euc_jp('こんにちは、{{name}}さん!'), :name => 'ゆきひろ')
- end
+ define_method "test interpolation: given a euc-jp translation and a utf-8 value it raises Encoding::CompatibilityError" do
+ assert_raises(Encoding::CompatibilityError) do
+ interpolate(:default => euc_jp('こんにちは、{{name}}さん!'), :name => 'ゆきひろ')
end
-
- def test_interpolate_given_a_non_unicode_multibyte_value_hash_into_an_unicode_string_raises_encoding_compatibility_error
- assert_raises(Encoding::CompatibilityError) do
- interpolate(:default => 'こんにちは、{{name}}さん!', :name => euc_jp('ゆきひろ'))
- end
+ end
+
+ # TODO should better explain how this relates to the test above with the simpler utf-8 default string
+ define_method "test interpolation: given a utf-8 translation and a euc-jp value it raises Encoding::CompatibilityError" do
+ assert_raises(Encoding::CompatibilityError) do
+ interpolate(:default => 'こんにちは、{{name}}さん!', :name => euc_jp('ゆきひろ'))
end
end
+ end
- def test_interpolate_given_a_string_containing_a_reserved_key_raises_reserved_interpolation_key
- assert_raises(I18n::ReservedInterpolationKey) { interpolate(:default => '{{default}}', :foo => :bar) }
- assert_raises(I18n::ReservedInterpolationKey) { interpolate(:default => '{{scope}}', :foo => :bar) }
- assert_raises(I18n::ReservedInterpolationKey) { interpolate(:default => '{{separator}}', :foo => :bar) }
- end
+ define_method "test interpolation: given a translations containing a reserved key it raises I18n::ReservedInterpolationKey" do
+ assert_raises(I18n::ReservedInterpolationKey) { interpolate(:default => '{{default}}', :foo => :bar) }
+ assert_raises(I18n::ReservedInterpolationKey) { interpolate(:default => '{{scope}}', :foo => :bar) }
+ assert_raises(I18n::ReservedInterpolationKey) { interpolate(:default => '{{separator}}', :foo => :bar) }
end
end
end
View
@@ -1,52 +0,0 @@
-# encoding: utf-8
-
-module Tests
- module Backend
- module Api
- module Lambda
- def test_translate_simple_proc
- setup_proc_translations
- assert_equal 'bar=bar, baz=baz, foo=foo', I18n.backend.translate('en', :a_lambda, :foo => 'foo', :bar => 'bar', :baz => 'baz')
- end
-
- def test_translate_proc_in_defaults
- setup_proc_translations
- assert_equal 'bar=bar, baz=baz, foo=foo', I18n.backend.translate('en', :does_not_exist, :default => :a_lambda, :foo => 'foo', :bar => 'bar', :baz => 'baz')
- assert_equal 'bar=bar, baz=baz, foo=foo', I18n.backend.translate('en', :does_not_exist, :default => [:does_not_exist_2, :does_not_exist_3, :a_lambda], :foo => 'foo', :bar => 'bar', :baz => 'baz')
- end
-
- def test_translate_proc_with_pluralize
- setup_proc_translations
- params = { :zero => 'zero', :one => 'one', :other => 'other' }
- assert_equal 'zero', I18n.backend.translate('en', :lambda_for_pluralize, params.merge(:count => 0))
- assert_equal 'one', I18n.backend.translate('en', :lambda_for_pluralize, params.merge(:count => 1))
- assert_equal 'other', I18n.backend.translate('en', :lambda_for_pluralize, params.merge(:count => 2))
- end
-
- def test_translate_proc_with_interpolate
- setup_proc_translations
- assert_equal 'bar baz foo', I18n.backend.translate('en', :lambda_for_interpolate, :foo => 'foo', :bar => 'bar', :baz => 'baz')
- end
-
- def test_translate_with_proc_as_default
- expected = 'result from lambda'
- assert_equal expected, I18n.backend.translate(:en, :'does not exist', :default => lambda { |key, values| expected })
- end
-
- private
-
- def setup_proc_translations
- I18n.backend.store_translations 'en', {
- :a_lambda => lambda { |key, values|
- values.keys.sort_by(&:to_s).collect { |key| "#{key}=#{values[key]}"}.join(', ')
- },
- :lambda_for_pluralize => lambda { |key, values| values },
- :lambda_for_interpolate => lambda { |key, values|
- "{{#{values.keys.sort_by(&:to_s).join('}} {{')}}}"
- }
- }
- end
- end
- end
- end
-end
View
@@ -1,47 +1,40 @@
# encoding: utf-8
module Tests
- module Backend
- module Api
- module Link
- def test_translate_calls_translate_if_resolves_to_a_symbol
- setup_linked_translations
- assert_equal 'foo', I18n.backend.translate('en', :link_to_foo)
- end
-
- def test_translate_calls_translate_if_resolves_to_a_symbol2
- setup_linked_translations
- assert_equal('baz', I18n.backend.translate('en', :link_to_baz))
- end
-
- def test_translate_calls_translate_if_resolves_to_a_symbol3
- setup_linked_translations
- assert I18n.backend.translate('en', :link_to_bar).key?(:baz)
- end
+ module Api
+ module Link
+ define_method "test linked lookup: given the key resolves to a symbol it looks up the symbol" do
+ setup_linked_translations
+ assert_equal 'foo', I18n.backend.translate('en', :link_to_foo)
+ end
- def test_translate_calls_translate_if_resolves_to_a_symbol_with_scope_1
- setup_linked_translations
- assert_equal('baz', I18n.backend.translate('en', :link_to_baz, :scope => :bar))
- end
+ define_method "test linked lookup: given the key resolves to a dot-separated symbol it looks up the dot-separated symbol (1)" do
+ setup_linked_translations
+ assert_equal('baz', I18n.backend.translate('en', :link_to_baz))
+ end
+
+ define_method "test linked lookup: given the key resolves to a dot-separated symbol it looks up the dot-separated symbol (2)" do
+ setup_linked_translations
+ assert_equal('buz', I18n.backend.translate('en', :'bar.link_to_buz'))
+ end
+
+ define_method "test linked lookup: given a scope and the key resolves to a symbol it looks up the symbol within the scope" do
+ setup_linked_translations
+ assert_equal('baz', I18n.backend.translate('en', :link_to_baz, :scope => :bar))
+ end
+
+ protected
- def test_translate_calls_translate_if_resolves_to_a_symbol_with_scope_1
- setup_linked_translations
- assert_equal('buz', I18n.backend.translate('en', :'bar.link_to_buz'))
+ def setup_linked_translations
+ I18n.backend.store_translations 'en', {
+ :foo => 'foo',
+ :bar => { :baz => 'baz', :link_to_baz => :baz, :link_to_buz => :'boz.buz' },
+ :boz => { :buz => 'buz' },
+ :link_to_foo => :foo,
+ :link_to_bar => :bar,
+ :link_to_baz => :'bar.baz'
+ }
end
-
- private
-
- def setup_linked_translations
- I18n.backend.store_translations 'en', {
- :foo => 'foo',
- :bar => { :baz => 'baz', :link_to_baz => :baz, :link_to_buz => :'boz.buz' },
- :boz => { :buz => 'buz' },
- :link_to_foo => :foo,
- :link_to_bar => :bar,
- :link_to_baz => :'bar.baz'
- }
- end
- end
end
end
end
Oops, something went wrong.

0 comments on commit 99c308e

Please sign in to comment.