Skip to content
Browse files

test suite cleanup

  • Loading branch information...
1 parent 4cf8570 commit b85510b268fbbcb434b623bc14a48f00ea731b32 @svenfuchs committed Nov 5, 2010
Showing with 357 additions and 533 deletions.
  1. +1 −0 ci/Gemfile.all
  2. +0 −37 ci/Gemfile.all.lock
  3. +1 −0 ci/Gemfile.no-rails
  4. +0 −11 ci/Gemfile.no-rails.lock
  5. +1 −0 ci/Gemfile.rails-2.3.x
  6. +0 −18 ci/Gemfile.rails-2.3.x.lock
  7. +2 −0 ci/Gemfile.rails-3.x
  8. +0 −16 ci/Gemfile.rails-3.x.lock
  9. +0 −2 lib/i18n/exceptions.rb
  10. +10 −10 lib/i18n/tests/basics.rb
  11. +6 −6 lib/i18n/tests/defaults.rb
  12. +18 −18 lib/i18n/tests/interpolation.rb
  13. +6 −6 lib/i18n/tests/link.rb
  14. +12 −12 lib/i18n/tests/localization/date.rb
  15. +10 −10 lib/i18n/tests/localization/date_time.rb
  16. +9 −9 lib/i18n/tests/localization/procs.rb
  17. +9 −9 lib/i18n/tests/localization/time.rb
  18. +14 −14 lib/i18n/tests/lookup.rb
  19. +7 −7 lib/i18n/tests/pluralization.rb
  20. +9 −9 lib/i18n/tests/procs.rb
  21. +1 −3 test/api/all_features_test.rb
  22. +2 −4 test/api/cascade_test.rb
  23. +2 −4 test/api/chain_test.rb
  24. +3 −5 test/api/fallbacks_test.rb
  25. +1 −3 test/api/key_value_test.rb
  26. +3 −5 test/api/memoize_test.rb
  27. +3 −5 test/api/pluralization_test.rb
  28. +2 −4 test/api/simple_test.rb
  29. +17 −21 test/backend/cache_test.rb
  30. +1 −3 test/backend/cascade_test.rb
  31. +1 −3 test/backend/chain_test.rb
  32. +2 −8 test/backend/cldr_test.rb
  33. +1 −3 test/backend/exceptions_test.rb
  34. +1 −3 test/backend/fallbacks_test.rb
  35. +2 −4 test/backend/interpolation_compiler_test.rb
  36. +1 −3 test/backend/key_value_test.rb
  37. +3 −4 test/backend/memoize_test.rb
  38. +1 −3 test/backend/metadata_test.rb
  39. +1 −3 test/backend/pluralization_test.rb
  40. +6 −9 test/backend/simple_test.rb
  41. +1 −4 test/backend/transliterator_test.rb
  42. +1 −4 test/core_ext/hash_test.rb
  43. +1 −3 test/core_ext/string/interpolate_test.rb
  44. +2 −3 test/gettext/api_test.rb
  45. +3 −5 test/gettext/backend_test.rb
  46. +58 −51 test/i18n_exceptions_test.rb
  47. +4 −8 test/i18n_load_path_test.rb
  48. +115 −140 test/i18n_test.rb
  49. +1 −3 test/locale/fallbacks_test.rb
  50. +1 −18 test/test_helper.rb
  51. +1 −0 test/test_setup.rb
View
1 ci/Gemfile.all
@@ -8,3 +8,4 @@ gem 'ffi'
gem 'ruby-cldr'
gem 'ruby2ruby'
gem 'ParseTree'
+gem 'test_declarative'
View
37 ci/Gemfile.all.lock
@@ -1,37 +0,0 @@
-GEM
- remote: http://rubygems.org/
- specs:
- ParseTree (3.0.6)
- RubyInline (>= 3.7.0)
- sexp_processor (>= 3.0.0)
- RubyInline (3.8.6)
- ZenTest (~> 4.3)
- ZenTest (4.4.0)
- activesupport (3.0.1)
- ffi (0.6.3)
- rake (>= 0.8.7)
- mocha (0.9.9)
- rake
- rake (0.8.7)
- ruby-cldr (0.0.1)
- ruby2ruby (1.2.5)
- ruby_parser (~> 2.0)
- sexp_processor (~> 3.0)
- ruby_parser (2.0.5)
- sexp_processor (~> 3.0)
- rufus-tokyo (1.0.7)
- sexp_processor (3.0.5)
- sqlite3-ruby (1.3.2)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- ParseTree
- activesupport (~> 3.0.0)
- ffi
- mocha
- ruby-cldr
- ruby2ruby
- rufus-tokyo
- sqlite3-ruby
View
1 ci/Gemfile.no-rails
@@ -1,4 +1,5 @@
source :rubygems
gem 'mocha'
+gem 'test_declarative'
View
11 ci/Gemfile.no-rails.lock
@@ -1,11 +0,0 @@
-GEM
- specs:
- mocha (0.9.8)
- rake
- rake (0.8.7)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- mocha
View
1 ci/Gemfile.rails-2.3.x
@@ -3,4 +3,5 @@ source :rubygems
gem 'activesupport', '~> 2.3'
gem 'sqlite3-ruby'
gem 'mocha'
+gem 'test_declarative'
View
18 ci/Gemfile.rails-2.3.x.lock
@@ -1,18 +0,0 @@
-GEM
- specs:
- activerecord (2.3.8)
- activesupport (= 2.3.8)
- activesupport (2.3.8)
- mocha (0.9.8)
- rake
- rake (0.8.7)
- sqlite3-ruby (1.3.1)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- activerecord (~> 2.3)
- activesupport (~> 2.3)
- mocha
- sqlite3-ruby
View
2 ci/Gemfile.rails-3.x
@@ -3,3 +3,5 @@ source :rubygems
gem 'activesupport', '~> 3.0.0'
gem 'sqlite3-ruby'
gem 'mocha'
+gem 'test_declarative'
+
View
16 ci/Gemfile.rails-3.x.lock
@@ -1,16 +0,0 @@
-GEM
- remote: http://rubygems.org/
- specs:
- activesupport (3.0.1)
- mocha (0.9.9)
- rake
- rake (0.8.7)
- sqlite3-ruby (1.3.2)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- activesupport (~> 3.0.0)
- mocha
- sqlite3-ruby
View
2 lib/i18n/exceptions.rb
@@ -1,5 +1,3 @@
-# encoding: utf-8
-
class KeyError < IndexError
def initialize(message = nil)
super(message || "key not found")
View
20 lib/i18n/tests/basics.rb
@@ -1,22 +1,21 @@
-# encoding: utf-8
-
module I18n
module Tests
module Basics
def teardown
I18n.available_locales = nil
end
- def test_available_locales
+ test "available_locales returns the locales stored to the backend by default" do
I18n.backend.store_translations('de', :foo => 'bar')
I18n.backend.store_translations('en', :foo => 'foo')
assert I18n.available_locales.include?(:de)
assert I18n.available_locales.include?(:en)
end
- def test_available_locales_setter
+ test "available_locales can be set to something else independently from the actual locale data" do
I18n.backend.store_translations('de', :foo => 'bar')
+ I18n.backend.store_translations('en', :foo => 'foo')
I18n.available_locales = :foo
assert_equal [:foo], I18n.available_locales
@@ -25,29 +24,30 @@ def test_available_locales_setter
assert_equal [:foo, :bar], I18n.available_locales
I18n.available_locales = nil
- assert_equal [:de, :en], I18n.available_locales.sort {|a,b| a.to_s <=> b.to_s}
+ assert I18n.available_locales.include?(:de)
+ assert I18n.available_locales.include?(:en)
end
- def test_available_locales_memoizes_when_explicitely_set
+ test "available_locales memoizes when set explicitely" do
I18n.backend.expects(:available_locales).never
I18n.available_locales = [:foo]
I18n.backend.store_translations('de', :bar => 'baz')
I18n.reload!
assert_equal [:foo], I18n.available_locales
end
- def test_available_locales_delegates_to_backend_when_not_explicitely_set
+ test "available_locales delegates to the backend when not set explicitely" do
I18n.backend.expects(:available_locales).twice
assert_equal I18n.available_locales, I18n.available_locales
end
- def test_delete_value
+ test "storing a nil value as a translation removes it from the available locale data" do
I18n.backend.store_translations(:en, :to_be_deleted => 'bar')
- assert_equal 'bar', I18n.t('to_be_deleted', :default => 'baz')
+ assert_equal 'bar', I18n.t(:to_be_deleted, :default => 'baz')
I18n.cache_store.clear if I18n.respond_to?(:cache_store) && I18n.cache_store
I18n.backend.store_translations(:en, :to_be_deleted => nil)
- assert_equal 'baz', I18n.t('to_be_deleted', :default => 'baz')
+ assert_equal 'baz', I18n.t(:to_be_deleted, :default => 'baz')
end
end
end
View
12 lib/i18n/tests/defaults.rb
@@ -8,29 +8,29 @@ def setup
I18n.backend.store_translations(:en, :foo => { :bar => 'bar', :baz => 'baz' })
end
- define_method "test defaults: given nil as a key it returns the given default" do
+ 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
+ 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
+ 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
+ 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
+ test "defaults: given an array of missing keys it raises a MissingTranslationData exception" do
assert_raise 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
+ 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 => '|')
View
36 lib/i18n/tests/interpolation.rb
@@ -16,96 +16,96 @@ module Interpolation
# * Security concerns: if I allow users to translate a web site, they can
# insert %{} in messages causing the I18n lookup to fail in every request.
#
- define_method "test interpolation: given no values it does not alter the string" do
+ test "interpolation: given no values it does not alter the string" do
assert_equal 'Hi %{name}!', interpolate(:default => 'Hi %{name}!')
end
- define_method "test interpolation: given values it interpolates them into the string" do
+ test "interpolation: given values it interpolates them into the string" do
assert_equal 'Hi David!', interpolate(:default => 'Hi %{name}!', :name => 'David')
end
- define_method "test interpolation: given a nil value it still interpolates it into the string" do
+ test "interpolation: given a nil value it still interpolates it into the string" do
assert_equal 'Hi !', interpolate(:default => 'Hi %{name}!', :name => nil)
end
- define_method "test interpolation: given a lambda as a value it calls it if the string contains the key" do
+ 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 { |*args| 'David' })
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
+ 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 { |*args| raise 'fail' }) }
end
- define_method "test interpolation: given values but missing a key it raises I18n::MissingInterpolationArgument" do
+ test "interpolation: given values but missing a key it raises I18n::MissingInterpolationArgument" do
assert_raise(I18n::MissingInterpolationArgument) do
interpolate(:default => '%{foo}', :bar => 'bar')
end
end
- define_method "test interpolation: it does not raise I18n::MissingInterpolationArgument for escaped variables" do
+ 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
- define_method "test interpolation: it does not change the original, stored translation string" do
+ 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
- define_method "test interpolation: works with the deprecated syntax" do
+ test "interpolation: works with the deprecated syntax" do
deprecation = capture(:stderr) do
assert_equal 'Hi David!', interpolate(:default => 'Hi {{name}}!', :name => 'David')
end
assert_match "The {{key}} interpolation syntax in I18n messages is deprecated", deprecation
end
- define_method "test interpolation: given the translation is in utf-8 it still works" do
+ 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
- define_method "test interpolation: given the value is in utf-8 it still works" do
+ test "interpolation: given the value is in utf-8 it still works" do
assert_equal 'Hi ゆきひろ!', interpolate(:default => 'Hi %{name}!', :name => 'ゆきひろ')
end
- define_method "test interpolation: given the translation and the value are in utf-8 it still works" do
+ 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)
- define_method "test interpolation: given a euc-jp translation and a utf-8 value it raises Encoding::CompatibilityError" do
+ test "interpolation: given a euc-jp translation and a utf-8 value it raises Encoding::CompatibilityError" do
assert_raise(Encoding::CompatibilityError) do
interpolate(:default => euc_jp('こんにちは、%{name}さん!'), :name => 'ゆきひろ')
end
end
- define_method "test interpolation: given a utf-8 translation and a euc-jp value it raises Encoding::CompatibilityError" do
+ test "interpolation: given a utf-8 translation and a euc-jp value it raises Encoding::CompatibilityError" do
assert_raise(Encoding::CompatibilityError) do
interpolate(:default => 'こんにちは、%{name}さん!', :name => euc_jp('ゆきひろ'))
end
end
- define_method "test interpolation: ASCII strings in the backend should be encoded to UTF8 if interpolation options are in UTF8" do
+ test "interpolation: ASCII strings in the backend should be encoded to UTF8 if interpolation options are in UTF8" do
I18n.backend.store_translations 'en', 'encoding' => ('%{who} let me go'.force_encoding("ASCII"))
result = I18n.t 'encoding', :who => "måmmå miå"
assert_equal Encoding::UTF_8, result.encoding
end
- define_method "test interpolation: UTF8 strings in the backend are still returned as UTF8 with ASCII interpolation" do
+ test "interpolation: UTF8 strings in the backend are still returned as UTF8 with ASCII interpolation" do
I18n.backend.store_translations 'en', 'encoding' => 'måmmå miå %{what}'
result = I18n.t 'encoding', :what => 'let me go'.force_encoding("ASCII")
assert_equal Encoding::UTF_8, result.encoding
end
- define_method "test interpolation: UTF8 strings in the backend are still returned as UTF8 even with numbers interpolation" do
+ test "interpolation: UTF8 strings in the backend are still returned as UTF8 even with numbers interpolation" do
I18n.backend.store_translations 'en', 'encoding' => '%{count} times: måmmå miå'
result = I18n.t 'encoding', :count => 3
assert_equal Encoding::UTF_8, result.encoding
end
end
- define_method "test interpolation: given a translations containing a reserved key it raises I18n::ReservedInterpolationKey" do
+ test "interpolation: given a translations containing a reserved key it raises I18n::ReservedInterpolationKey" do
assert_raise(I18n::ReservedInterpolationKey) { interpolate(:default => '%{default}', :foo => :bar) }
assert_raise(I18n::ReservedInterpolationKey) { interpolate(:default => '%{scope}', :foo => :bar) }
assert_raise(I18n::ReservedInterpolationKey) { interpolate(:default => '%{separator}', :foo => :bar) }
View
12 lib/i18n/tests/link.rb
@@ -3,47 +3,47 @@
module I18n
module Tests
module Link
- define_method "test linked lookup: if a key resolves to a symbol it looks up the symbol" do
+ test "linked lookup: if a key resolves to a symbol it looks up the symbol" do
I18n.backend.store_translations 'en', {
:link => :linked,
:linked => 'linked'
}
assert_equal 'linked', I18n.backend.translate('en', :link)
end
- define_method "test linked lookup: if a key resolves to a dot-separated symbol it looks up the symbol" do
+ test "linked lookup: if a key resolves to a dot-separated symbol it looks up the symbol" do
I18n.backend.store_translations 'en', {
:link => :"foo.linked",
:foo => { :linked => 'linked' }
}
assert_equal('linked', I18n.backend.translate('en', :link))
end
- define_method "test linked lookup: if a dot-separated key resolves to a symbol it looks up the symbol" do
+ test "linked lookup: if a dot-separated key resolves to a symbol it looks up the symbol" do
I18n.backend.store_translations 'en', {
:foo => { :link => :linked },
:linked => 'linked'
}
assert_equal('linked', I18n.backend.translate('en', :'foo.link'))
end
- define_method "test linked lookup: if a dot-separated key resolves to a dot-separated symbol it looks up the symbol" do
+ test "linked lookup: if a dot-separated key resolves to a dot-separated symbol it looks up the symbol" do
I18n.backend.store_translations 'en', {
:foo => { :link => :"bar.linked" },
:bar => { :linked => 'linked' }
}
assert_equal('linked', I18n.backend.translate('en', :'foo.link'))
end
- define_method "test linked lookup: links always refer to the absolute key" do
+ test "linked lookup: links always refer to the absolute key" do
I18n.backend.store_translations 'en', {
:foo => { :link => :linked, :linked => 'linked in foo' },
:linked => 'linked absolutely'
}
assert_equal 'linked absolutely', I18n.backend.translate('en', :link, :scope => :foo)
end
- define_method "test linked lookup: a link can resolve to a namespace in the middle of a dot-separated key" do
+ test "linked lookup: a link can resolve to a namespace in the middle of a dot-separated key" do
I18n.backend.store_translations 'en', {
:activemodel => { :errors => { :messages => { :blank => "can't be blank" } } },
:activerecord => { :errors => { :messages => :"activemodel.errors.messages" } }
View
24 lib/i18n/tests/localization/date.rb
@@ -10,53 +10,53 @@ def setup
@date = ::Date.new(2008, 3, 1)
end
- define_method "test localize Date: given the short format it uses it" do
+ test "localize Date: given the short format it uses it" do
# TODO should be Mrz, shouldn't it?
assert_equal '01. Mar', I18n.l(@date, :format => :short, :locale => :de)
end
- define_method "test localize Date: given the long format it uses it" do
+ test "localize Date: given the long format it uses it" do
assert_equal '01. März 2008', I18n.l(@date, :format => :long, :locale => :de)
end
- define_method "test localize Date: given the default format it uses it" do
+ test "localize Date: given the default format it uses it" do
assert_equal '01.03.2008', I18n.l(@date, :format => :default, :locale => :de)
end
- define_method "test localize Date: given a day name format it returns the correct day name" do
+ test "localize Date: given a day name format it returns the correct day name" do
assert_equal 'Samstag', I18n.l(@date, :format => '%A', :locale => :de)
end
- define_method "test localize Date: given an abbreviated day name format it returns the correct abbreviated day name" do
+ test "localize Date: given an abbreviated day name format it returns the correct abbreviated day name" do
assert_equal 'Sa', I18n.l(@date, :format => '%a', :locale => :de)
end
- define_method "test localize Date: given a month name format it returns the correct month name" do
+ test "localize Date: given a month name format it returns the correct month name" do
assert_equal 'März', I18n.l(@date, :format => '%B', :locale => :de)
end
- define_method "test localize Date: given an abbreviated month name format it returns the correct abbreviated month name" do
+ test "localize Date: given an abbreviated month name format it returns the correct abbreviated month name" do
# TODO should be Mrz, shouldn't it?
assert_equal 'Mar', I18n.l(@date, :format => '%b', :locale => :de)
end
- define_method "test localize Date: given an unknown format it does not fail" do
+ test "localize Date: given an unknown format it does not fail" do
assert_nothing_raised { I18n.l(@date, :format => '%x') }
end
- define_method "test localize Date: given nil it raises I18n::ArgumentError" do
+ test "localize Date: given nil it raises I18n::ArgumentError" do
assert_raise(I18n::ArgumentError) { I18n.l(nil) }
end
- define_method "test localize Date: given a plain Object it raises I18n::ArgumentError" do
+ test "localize Date: given a plain Object it raises I18n::ArgumentError" do
assert_raise(I18n::ArgumentError) { I18n.l(Object.new) }
end
- define_method "test localize Date: given a format is missing it raises I18n::MissingTranslationData" do
+ test "localize Date: given a format is missing it raises I18n::MissingTranslationData" do
assert_raise(I18n::MissingTranslationData) { I18n.l(@date, :format => :missing) }
end
- define_method "test localize Date: it does not alter the format string" do
+ test "localize Date: it does not alter the format string" do
assert_equal '01. Februar 2009', I18n.l(::Date.parse('2009-02-01'), :format => :long, :locale => :de)
assert_equal '01. Oktober 2009', I18n.l(::Date.parse('2009-10-01'), :format => :long, :locale => :de)
end
View
20 lib/i18n/tests/localization/date_time.rb
@@ -11,47 +11,47 @@ def setup
@other_datetime = ::DateTime.new(2008, 3, 1, 18)
end
- define_method "test localize DateTime: given the short format it uses it" do
+ test "localize DateTime: given the short format it uses it" do
# TODO should be Mrz, shouldn't it?
assert_equal '01. Mar 06:00', I18n.l(@datetime, :format => :short, :locale => :de)
end
- define_method "test localize DateTime: given the long format it uses it" do
+ test "localize DateTime: given the long format it uses it" do
assert_equal '01. März 2008 06:00', I18n.l(@datetime, :format => :long, :locale => :de)
end
- define_method "test localize DateTime: given the default format it uses it" do
+ test "localize DateTime: given the default format it uses it" do
# TODO should be Mrz, shouldn't it?
assert_equal 'Sa, 01. Mar 2008 06:00:00 +0000', I18n.l(@datetime, :format => :default, :locale => :de)
end
- define_method "test localize DateTime: given a day name format it returns the correct day name" do
+ test "localize DateTime: given a day name format it returns the correct day name" do
assert_equal 'Samstag', I18n.l(@datetime, :format => '%A', :locale => :de)
end
- define_method "test localize DateTime: given an abbreviated day name format it returns the correct abbreviated day name" do
+ test "localize DateTime: given an abbreviated day name format it returns the correct abbreviated day name" do
assert_equal 'Sa', I18n.l(@datetime, :format => '%a', :locale => :de)
end
- define_method "test localize DateTime: given a month name format it returns the correct month name" do
+ test "localize DateTime: given a month name format it returns the correct month name" do
assert_equal 'März', I18n.l(@datetime, :format => '%B', :locale => :de)
end
- define_method "test localize DateTime: given an abbreviated month name format it returns the correct abbreviated month name" do
+ test "localize DateTime: given an abbreviated month name format it returns the correct abbreviated month name" do
# TODO should be Mrz, shouldn't it?
assert_equal 'Mar', I18n.l(@datetime, :format => '%b', :locale => :de)
end
- define_method "test localize DateTime: given a meridian indicator format it returns the correct meridian indicator" do
+ test "localize DateTime: given a meridian indicator format it returns the correct meridian indicator" do
assert_equal 'am', I18n.l(@datetime, :format => '%p', :locale => :de)
assert_equal 'pm', I18n.l(@other_datetime, :format => '%p', :locale => :de)
end
- define_method "test localize DateTime: given an unknown format it does not fail" do
+ test "localize DateTime: given an unknown format it does not fail" do
assert_nothing_raised { I18n.l(@datetime, :format => '%x') }
end
- define_method "test localize DateTime: given a format is missing it raises I18n::MissingTranslationData" do
+ test "localize DateTime: given a format is missing it raises I18n::MissingTranslationData" do
assert_raise(I18n::MissingTranslationData) { I18n.l(@datetime, :format => :missing) }
end
View
18 lib/i18n/tests/localization/procs.rb
@@ -4,58 +4,58 @@ module I18n
module Tests
module Localization
module Procs
- define_method "test localize: using day names from lambdas" do
+ test "localize: using day names from lambdas" do
setup_time_proc_translations
time = ::Time.parse('2008-03-01 6:00 UTC')
assert_match /Суббота/, I18n.l(time, :format => "%A, %d %B", :locale => :ru)
assert_match /суббота/, I18n.l(time, :format => "%d %B (%A)", :locale => :ru)
end
- define_method "test localize: using month names from lambdas" do
+ test "localize: using month names from lambdas" do
setup_time_proc_translations
time = ::Time.parse('2008-03-01 6:00 UTC')
assert_match /марта/, I18n.l(time, :format => "%d %B %Y", :locale => :ru)
assert_match /Март /, I18n.l(time, :format => "%B %Y", :locale => :ru)
end
- define_method "test localize: using abbreviated day names from lambdas" do
+ test "localize: using abbreviated day names from lambdas" do
setup_time_proc_translations
time = ::Time.parse('2008-03-01 6:00 UTC')
assert_match /марта/, I18n.l(time, :format => "%d %b %Y", :locale => :ru)
assert_match /март /, I18n.l(time, :format => "%b %Y", :locale => :ru)
end
- define_method "test localize Date: given a format that resolves to a Proc it calls the Proc with the object" do
+ test "localize Date: given a format that resolves to a Proc it calls the Proc with the object" do
setup_time_proc_translations
date = ::Date.new(2008, 3, 1, 6)
assert_equal '[Sat, 01 Mar 2008, {}]', I18n.l(date, :format => :proc, :locale => :ru)
end
- define_method "test localize Date: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
+ test "localize Date: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
setup_time_proc_translations
date = ::Date.new(2008, 3, 1, 6)
assert_equal '[Sat, 01 Mar 2008, {:foo=>"foo"}]', I18n.l(date, :format => :proc, :foo => 'foo', :locale => :ru)
end
- define_method "test localize DateTime: given a format that resolves to a Proc it calls the Proc with the object" do
+ test "localize DateTime: given a format that resolves to a Proc it calls the Proc with the object" do
setup_time_proc_translations
datetime = ::DateTime.new(2008, 3, 1, 6)
assert_equal '[Sat, 01 Mar 2008 06:00:00 +0000, {}]', I18n.l(datetime, :format => :proc, :locale => :ru)
end
- define_method "test localize DateTime: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
+ test "localize DateTime: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
setup_time_proc_translations
datetime = ::DateTime.new(2008, 3, 1, 6)
assert_equal '[Sat, 01 Mar 2008 06:00:00 +0000, {:foo=>"foo"}]', I18n.l(datetime, :format => :proc, :foo => 'foo', :locale => :ru)
end
- define_method "test localize Time: given a format that resolves to a Proc it calls the Proc with the object" do
+ test "localize Time: given a format that resolves to a Proc it calls the Proc with the object" do
setup_time_proc_translations
time = ::Time.parse('2008-03-01 6:00 UTC')
assert_equal [time, {}].inspect, I18n.l(time, :format => :proc, :locale => :ru)
end
- define_method "test localize Time: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
+ test "localize Time: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
setup_time_proc_translations
time = ::Time.parse('2008-03-01 6:00 UTC')
options = { :foo => 'foo' }
View
18 lib/i18n/tests/localization/time.rb
@@ -11,12 +11,12 @@ def setup
@other_time = ::Time.parse('2008-03-01 18:00 UTC')
end
- define_method "test localize Time: given the short format it uses it" do
+ test "localize Time: given the short format it uses it" do
# TODO should be Mrz, shouldn't it?
assert_equal '01. Mar 06:00', I18n.l(@time, :format => :short, :locale => :de)
end
- define_method "test localize Time: given the long format it uses it" do
+ test "localize Time: given the long format it uses it" do
assert_equal '01. März 2008 06:00', I18n.l(@time, :format => :long, :locale => :de)
end
@@ -25,33 +25,33 @@ def setup
# assert_equal 'Sa, 01. Mar 2008 06:00:00 +0000', I18n.l(@time, :format => :default, :locale => :de)
# end
- define_method "test localize Time: given a day name format it returns the correct day name" do
+ test "localize Time: given a day name format it returns the correct day name" do
assert_equal 'Samstag', I18n.l(@time, :format => '%A', :locale => :de)
end
- define_method "test localize Time: given an abbreviated day name format it returns the correct abbreviated day name" do
+ test "localize Time: given an abbreviated day name format it returns the correct abbreviated day name" do
assert_equal 'Sa', I18n.l(@time, :format => '%a', :locale => :de)
end
- define_method "test localize Time: given a month name format it returns the correct month name" do
+ test "localize Time: given a month name format it returns the correct month name" do
assert_equal 'März', I18n.l(@time, :format => '%B', :locale => :de)
end
- define_method "test localize Time: given an abbreviated month name format it returns the correct abbreviated month name" do
+ test "localize Time: given an abbreviated month name format it returns the correct abbreviated month name" do
# TODO should be Mrz, shouldn't it?
assert_equal 'Mar', I18n.l(@time, :format => '%b', :locale => :de)
end
- define_method "test localize Time: given a meridian indicator format it returns the correct meridian indicator" do
+ test "localize Time: given a meridian indicator format it returns the correct meridian indicator" do
assert_equal 'am', I18n.l(@time, :format => '%p', :locale => :de)
assert_equal 'pm', I18n.l(@other_time, :format => '%p', :locale => :de)
end
- define_method "test localize Time: given an unknown format it does not fail" do
+ test "localize Time: given an unknown format it does not fail" do
assert_nothing_raised { I18n.l(@time, :format => '%x') }
end
- define_method "test localize Time: given a format is missing it raises I18n::MissingTranslationData" do
+ test "localize Time: given a format is missing it raises I18n::MissingTranslationData" do
assert_raise(I18n::MissingTranslationData) { I18n.l(@time, :format => :missing) }
end
View
28 lib/i18n/tests/lookup.rb
@@ -9,64 +9,64 @@ def setup
:string => "a", :array => %w(a b c), :hash => { "a" => "b" })
end
- define_method "test lookup: it returns a string" do
+ test "lookup: it returns a string" do
assert_equal("a", I18n.t(:string))
end
- define_method "test lookup: it returns hash" do
+ test "lookup: it returns hash" do
assert_equal({ :a => "b" }, I18n.t(:hash))
end
- define_method "test lookup: it returns a array" do
+ test "lookup: it returns a array" do
assert_equal(%w(a b c), I18n.t(:array))
end
- define_method "test lookup: it returns a native true" do
+ test "lookup: it returns a native true" do
assert I18n.t(:truthy) === true
end
- define_method "test lookup: it returns a native false" do
+ test "lookup: it returns a native false" do
assert I18n.t(:falsy) === false
end
- define_method "test lookup: given a missing key, no default and no raise option it returns an error message" do
+ test "lookup: given a missing key, no default and no raise option it returns an error message" do
assert_equal "translation missing: en.missing", I18n.t(:missing)
end
- define_method "test lookup: given a missing key, no default and the raise option it raises MissingTranslationData" do
+ test "lookup: given a missing key, no default and the raise option it raises MissingTranslationData" do
assert_raise(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
end
- define_method "test lookup: does not raise an exception if no translation data is present for the given locale" do
+ test "lookup: does not raise an exception if no translation data is present for the given locale" do
assert_nothing_raised { I18n.t(:foo, :locale => :xx) }
end
- define_method "test lookup: given an array of keys it translates all of them" do
+ test "lookup: given an array of keys it translates all of them" do
assert_equal %w(bar baz), I18n.t([:bar, :baz], :scope => [:foo])
end
- define_method "test lookup: using a custom scope separator" do
+ test "lookup: 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('foo|bar', :separator => '|')
end
# In fact it probably *should* fail but Rails currently relies on using the default locale instead.
# So we'll stick to this for now until we get it fixed in Rails.
- define_method "test lookup: given nil as a locale it does not raise but use the default locale" do
+ test "lookup: given nil as a locale it does not raise but use the default locale" do
# assert_raise(I18n::InvalidLocale) { I18n.t(:bar, :locale => nil) }
assert_nothing_raised { I18n.t(:bar, :locale => nil) }
end
- define_method "test lookup: a resulting String is not frozen" do
+ test "lookup: a resulting String is not frozen" do
assert !I18n.t(:string).frozen?
end
- define_method "test lookup: a resulting Array is not frozen" do
+ test "lookup: a resulting Array is not frozen" do
assert !I18n.t(:array).frozen?
end
- define_method "test lookup: a resulting Hash is not frozen" do
+ test "lookup: a resulting Hash is not frozen" do
assert !I18n.t(:hash).frozen?
end
end
View
14 lib/i18n/tests/pluralization.rb
@@ -3,31 +3,31 @@
module I18n
module Tests
module Pluralization
- define_method "test pluralization: given 0 it returns the :zero translation if it is defined" do
+ test "pluralization: given 0 it returns the :zero translation if it is defined" do
assert_equal 'zero', I18n.t(:default => { :zero => 'zero' }, :count => 0)
end
- define_method "test pluralization: given 0 it returns the :other translation if :zero is not defined" do
+ test "pluralization: given 0 it returns the :other translation if :zero is not defined" do
assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 0)
end
- define_method "test pluralization: given 1 it returns the singular translation" do
+ test "pluralization: given 1 it returns the singular translation" do
assert_equal 'bar', I18n.t(:default => { :one => 'bar' }, :count => 1)
end
- define_method "test pluralization: given 2 it returns the :other translation" do
+ test "pluralization: given 2 it returns the :other translation" do
assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 2)
end
- define_method "test pluralization: given 3 it returns the :other translation" do
+ test "pluralization: given 3 it returns the :other translation" do
assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 3)
end
- define_method "test pluralization: given nil it returns the whole entry" do
+ test "pluralization: given nil it returns the whole entry" do
assert_equal({ :one => 'bar' }, I18n.t(:default => { :one => 'bar' }, :count => nil))
end
- define_method "test pluralization: given incomplete pluralization data it raises I18n::InvalidPluralizationData" do
+ test "pluralization: given incomplete pluralization data it raises I18n::InvalidPluralizationData" do
assert_raise(I18n::InvalidPluralizationData) { I18n.t(:default => { :one => 'bar' }, :count => 2) }
end
end
View
18 lib/i18n/tests/procs.rb
@@ -3,45 +3,45 @@
module I18n
module Tests
module Procs
- define_method "test lookup: given a translation is a proc it calls the proc with the key and interpolation values" do
+ test "lookup: given a translation is a proc it calls the proc with the key and interpolation values" do
I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| filter_args(*args) })
assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:a_lambda, :foo => 'foo')
end
- define_method "test defaults: given a default is a Proc it calls it with the key and interpolation values" do
+ test "defaults: given a default is a Proc it calls it with the key and interpolation values" do
proc = lambda { |*args| filter_args(*args) }
assert_equal '[nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo')
end
- define_method "test defaults: given a default is a key that resolves to a Proc it calls it with the key and interpolation values" do
+ test "defaults: given a default is a key that resolves to a Proc it calls it with the key and interpolation values" do
I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| filter_args(*args) })
assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => :a_lambda, :foo => 'foo')
assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => [nil, :a_lambda], :foo => 'foo')
end
- define_method "test interpolation: given an interpolation value is a lambda it calls it with key and values before interpolating it" do
+ test "interpolation: given an interpolation value is a lambda it calls it with key and values before interpolating it" do
proc = lambda { |*args| filter_args(*args) }
assert_match %r(\[\{:foo=>#<Proc.*>\}\]), I18n.t(nil, :default => '%{foo}', :foo => proc)
end
- define_method "test interpolation: given a key resolves to a Proc that returns a string then interpolation still works" do
+ test "interpolation: given a key resolves to a Proc that returns a string then interpolation still works" do
proc = lambda { |*args| "%{foo}: " + filter_args(*args) }
assert_equal 'foo: [nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo')
end
- define_method "test pluralization: given a key resolves to a Proc that returns valid data then pluralization still works" do
+ test "pluralization: given a key resolves to a Proc that returns valid data then pluralization still works" do
proc = lambda { |*args| { :zero => 'zero', :one => 'one', :other => 'other' } }
assert_equal 'zero', I18n.t(:default => proc, :count => 0)
assert_equal 'one', I18n.t(:default => proc, :count => 1)
assert_equal 'other', I18n.t(:default => proc, :count => 2)
end
- define_method "test lookup: given the option :resolve => false was passed it does not resolve proc translations" do
+ test "lookup: given the option :resolve => false was passed it does not resolve proc translations" do
I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| filter_args(*args) })
assert_equal Proc, I18n.t(:a_lambda, :resolve => false).class
end
- define_method "test lookup: given the option :resolve => false was passed it does not resolve proc default" do
+ test "lookup: given the option :resolve => false was passed it does not resolve proc default" do
assert_equal Proc, I18n.t(nil, :default => lambda { |*args| filter_args(*args) }, :resolve => false).class
end
@@ -52,4 +52,4 @@ def filter_args(*args)
end
end
end
-end
+end
View
4 test/api/all_features_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
begin
require 'rubygems'
View
6 test/api/cascade_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
class I18nCascadeApiTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
@@ -27,4 +25,4 @@ def setup
test "make sure we use a backend with Cascade included" do
assert_equal Backend, I18n.backend.class
end
-end
+end
View
6 test/api/chain_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
class I18nApiChainTest < Test::Unit::TestCase
def setup
@@ -23,4 +21,4 @@ def setup
test "make sure we use the Chain backend" do
assert_equal I18n::Backend::Chain, I18n.backend.class
end
-end
+end
View
8 test/api/fallbacks_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
class I18nFallbacksApiTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
@@ -27,6 +25,6 @@ def setup
test "make sure we use a backend with Fallbacks included" do
assert_equal Backend, I18n.backend.class
end
-
+
# links: test that keys stored on one backend can link to keys stored on another backend
-end
+end
View
4 test/api/key_value_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
I18n::Tests.setup_rufus_tokyo
View
8 test/api/memoize_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
class I18nMemoizeBackendWithSimpleApiTest < Test::Unit::TestCase
include I18n::Tests::Basics
@@ -44,7 +42,7 @@ class I18nMemoizeBackendWithKeyValueApiTest < Test::Unit::TestCase
# include I18n::Tests::Procs
# include I18n::Tests::Localization::Procs
-
+
class MemoizeBackend < I18n::Backend::KeyValue
include I18n::Backend::Memoize
end
@@ -55,7 +53,7 @@ def setup
I18n.backend = MemoizeBackend.new(STORE)
super
end
-
+
test "make sure we use the MemoizeBackend backend" do
assert_equal MemoizeBackend, I18n.backend.class
end
View
8 test/api/pluralization_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
class I18nPluralizationApiTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
@@ -27,6 +25,6 @@ def setup
test "make sure we use a backend with Pluralization included" do
assert_equal Backend, I18n.backend.class
end
-
+
# links: test that keys stored on one backend can link to keys stored on another backend
-end
+end
View
6 test/api/simple_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
class I18nSimpleBackendApiTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
@@ -27,4 +25,4 @@ def setup
test "make sure we use the Simple backend" do
assert_equal I18n::Backend::Simple, I18n.backend.class
end
-end
+end
View
38 test/backend/cache_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
begin
require 'active_support'
@@ -27,26 +25,24 @@ def teardown
assert I18n.cache_store.is_a?(ActiveSupport::Cache::MemoryStore)
end
- with_mocha do
- test "translate hits the backend and caches the response" do
- I18n.backend.expects(:lookup).returns('Foo')
- assert_equal 'Foo', I18n.t(:foo)
+ test "translate hits the backend and caches the response" do
+ I18n.backend.expects(:lookup).returns('Foo')
+ assert_equal 'Foo', I18n.t(:foo)
- I18n.backend.expects(:lookup).never
- assert_equal 'Foo', I18n.t(:foo)
+ I18n.backend.expects(:lookup).never
+ assert_equal 'Foo', I18n.t(:foo)
- I18n.backend.expects(:lookup).returns('Bar')
- assert_equal 'Bar', I18n.t(:bar)
- end
+ I18n.backend.expects(:lookup).returns('Bar')
+ assert_equal 'Bar', I18n.t(:bar)
+ end
- test "still raises MissingTranslationData but also caches it" do
- I18n.backend.expects(:lookup).returns(nil)
- assert_raise(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
+ test "still raises MissingTranslationData but also caches it" do
+ I18n.backend.expects(:lookup).returns(nil)
+ assert_raise(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
- I18n.cache_store.expects(:write).never
- I18n.backend.expects(:lookup).never
- assert_raise(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
- end
+ I18n.cache_store.expects(:write).never
+ I18n.backend.expects(:lookup).never
+ assert_raise(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
end
test "uses 'i18n' as a cache key namespace by default" do
@@ -68,10 +64,10 @@ def teardown
test "keys should not be equal" do
interpolation_values1 = { :foo => 1, :bar => 2 }
interpolation_values2 = { :foo => 2, :bar => 1 }
-
+
key1 = I18n.backend.send(:cache_key, :en, :some_key, interpolation_values1)
key2 = I18n.backend.send(:cache_key, :en, :some_key, interpolation_values2)
-
+
assert key1 != key2
end
View
4 test/backend/cascade_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
class I18nBackendCascadeTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
View
4 test/backend/chain_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
class I18nBackendChainTest < Test::Unit::TestCase
def setup
View
10 test/backend/cldr_test.rb
@@ -1,10 +1,4 @@
-# encoding: utf-8
-
-begin
- require 'cldr'
-rescue LoadError
- puts "Skipping tests for I18n::Backend::Cldr because the ruby-cldr gem is not installed."
-end
+require File.expand_path('../../test_helper', __FILE__)
if defined?(Cldr)
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
@@ -147,4 +141,4 @@ def datetime
assert_equal '123457', I18n.l(123456.78, :format => :stupid)
end
end
-end
+end
View
4 test/backend/exceptions_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
class I18nBackendExceptionsTest < Test::Unit::TestCase
def setup
View
4 test/backend/fallbacks_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
class I18nBackendFallbacksTranslateTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
View
6 test/backend/interpolation_compiler_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
class InterpolationCompilerTest < Test::Unit::TestCase
Compiler = I18n::Backend::InterpolationCompiler::Compiler
@@ -101,4 +99,4 @@ def interpolate(*args)
super
end
-end
+end
View
4 test/backend/key_value_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
I18n::Tests.setup_rufus_tokyo
View
7 test/backend/memoize_test.rb
@@ -1,6 +1,5 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
+
require 'backend/simple_test'
class I18nBackendMemoizeTest < I18nBackendSimpleTest
@@ -45,4 +44,4 @@ def test_resets_available_locales_on_store_translations
assert I18n.available_locales.include?(:copa)
assert_equal 1, I18n.backend.spy_calls
end
-end
+end
View
4 test/backend/metadata_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
class I18nBackendMetadataTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
View
4 test/backend/pluralization_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
class I18nBackendPluralizationTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
View
15 test/backend/simple_test.rb
@@ -1,7 +1,4 @@
-# encoding: utf-8
-
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
class I18nBackendSimpleTest < Test::Unit::TestCase
def setup
@@ -13,12 +10,12 @@ def setup
test "simple backend translate: given nil as a key it still interpolations the default value" do
assert_equal "Hi David", I18n.t(nil, :default => "Hi %{name}", :name => "David")
end
-
+
# loading translations
test "simple load_translations: given an unknown file type it raises I18n::UnknownFileType" do
assert_raise(I18n::UnknownFileType) { I18n.backend.load_translations("#{locales_dir}/en.xml") }
end
-
+
test "simple load_translations: given a Ruby file name it does not raise anything" do
assert_nothing_raised { I18n.backend.load_translations("#{locales_dir}/en.rb") }
end
@@ -27,7 +24,7 @@ def setup
I18n.backend.load_translations
assert_equal({ :en => { :foo => { :bar => 'baz' } } }, I18n.backend.send(:translations))
end
-
+
test "simple load_rb: loads data from a Ruby file" do
data = I18n.backend.send(:load_rb, "#{locales_dir}/en.rb")
assert_equal({ :en => { :fuh => { :bah => 'bas' } } }, data)
@@ -44,7 +41,7 @@ def setup
expected = { :en => { :fuh => { :bah => "bas" }, :foo => { :bar => "baz" } } }
assert_equal expected, translations
end
-
+
# storing translations
test "simple store_translations: stores translations, ... no, really :-)" do
@@ -67,7 +64,7 @@ def setup
I18n.backend.store_translations 'en', 'foo' => {'bar' => 'bar', 'baz' => 'baz'}
assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], translations
end
-
+
# reloading translations
test "simple reload_translations: unloads translations" do
View
5 test/backend/transliterator_test.rb
@@ -1,9 +1,6 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
class I18nBackendTransliterator < Test::Unit::TestCase
-
def setup
I18n.backend = I18n::Backend::Simple.new
@proc = lambda { |n| n.upcase }
View
5 test/core_ext/hash_test.rb
@@ -1,7 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
require 'i18n/core_ext/hash'
class I18nCoreExtHashInterpolationTest < Test::Unit::TestCase
View
4 test/core_ext/string/interpolate_test.rb
@@ -1,6 +1,4 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../../test_helper', __FILE__)
# thanks to Masao's String extensions these should work the same in
# Ruby 1.8 (patched) and Ruby 1.9 (native)
View
5 test/gettext/api_test.rb
@@ -1,6 +1,5 @@
# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
require 'i18n/gettext/helpers'
include I18n::Gettext::Helpers
@@ -204,4 +203,4 @@ def test_npgettext_looks_up_a_plural_with_alternative_syntax
assert_equal '2 spezielle Äpfel', npgettext('special', ['A special apple', '%{count} special apples'], 2)
assert_equal '2 spezielle Äpfel', np_('special', ['A special apple', '%{count} special apples'], 2)
end
-end
+end
View
8 test/gettext/backend_test.rb
@@ -3,8 +3,7 @@
# apparently Ruby 1.9.1p129 has encoding problems with the gettext po parser
unless RUBY_VERSION == '1.9.1' && RUBY_PATCHLEVEL <= 129
- $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
- require 'test_helper'
+ require File.expand_path('../../test_helper', __FILE__)
class I18nGettextBackendTest < Test::Unit::TestCase
include I18n::Gettext::Helpers
@@ -84,12 +83,11 @@ def test_pluralizes_namespaced_entry_with_alternative_syntax
assert_equal 'Rad', npgettext('Car', ['wheel', 'wheels'], 1)
assert_equal 'Räder', npgettext('Car', ['wheel', 'wheels'], 2)
end
-
+
def test_ngettextpluralizes_entry_with_dots
I18n.locale = :de
assert_equal 'Auf 1 Achse.', n_("On %{count} wheel.", "On %{count} wheels.", 1)
assert_equal 'Auf 2 Achsen.', n_("On %{count} wheel.", "On %{count} wheels.", 2)
end
-
end
-end
+end
View
109 test/i18n_exceptions_test.rb
@@ -1,109 +1,116 @@
-# encoding: utf-8
-$:.unshift File.expand_path(File.dirname(__FILE__) + '/')
-require 'test_helper'
+require File.expand_path('../test_helper', __FILE__)
class I18nExceptionsTest < Test::Unit::TestCase
def test_invalid_locale_stores_locale
force_invalid_locale
rescue I18n::ArgumentError => e
- assert_nil e.locale
+ assert_nil exception.locale
end
- def test_invalid_locale_message
- force_invalid_locale
- rescue I18n::ArgumentError => e
- assert_equal 'nil is not a valid locale', e.message
+ test "passing an invalid locale raises an InvalidLocale exception" do
+ force_invalid_locale do |exception|
+ assert_equal 'nil is not a valid locale', exception.message
+ end
end
- def test_missing_translation_data_stores_locale_key_and_options
- force_missing_translation_data
- rescue I18n::ArgumentError => e
- options = {:scope => :bar}
- assert_equal 'de', e.locale
- assert_equal :foo, e.key
- assert_equal options, e.options
+ test "MissingTranslationData exception stores locale, key and options" do
+ force_missing_translation_data do |exception|
+ assert_equal 'de', exception.locale
+ assert_equal :foo, exception.key
+ assert_equal({:scope => :bar}, exception.options)
+ end
end
- def test_missing_translation_data_message
- force_missing_translation_data
- rescue I18n::ArgumentError => e
- assert_equal 'translation missing: de.bar.foo', e.message
+ test "MissingTranslationData message contains the locale and scoped key" do
+ force_missing_translation_data do |exception|
+ assert_equal 'translation missing: de.bar.foo', exception.message
+ end
end
- def test_missing_translation_data_html_message
- force_missing_translation_data
- rescue I18n::ArgumentError => e
- assert_equal '<span class="translation_missing" title="translation missing: de.bar.foo">Foo</span>', e.html_message
+ test "MissingTranslationData html_message is a span with the titlelized last key token" do
+ force_missing_translation_data do |exception|
+ assert_equal '<span class="translation_missing" title="translation missing: de.bar.foo">Foo</span>', exception.html_message
+ end
end
- def test_missing_translation_data_rescue_format_html
+ test "ExceptionHandler returns the html_message if :rescue_format => :html was given" do
message = force_missing_translation_data(:rescue_format => :html)
assert_equal '<span class="translation_missing" title="translation missing: de.bar.foo">Foo</span>', message
end
- def test_invalid_pluralization_data_stores_entry_and_count
- force_invalid_pluralization_data
- rescue I18n::ArgumentError => e
- assert_equal [:bar], e.entry
- assert_equal 1, e.count
+ test "InvalidPluralizationData stores entry and count" do
+ force_invalid_pluralization_data do |exception|
+ assert_equal [:bar], exception.entry
+ assert_equal 1, exception.count
+ end
end
- def test_invalid_pluralization_data_message
- force_invalid_pluralization_data
- rescue I18n::ArgumentError => e
- assert_equal 'translation data [:bar] can not be used with :count => 1', e.message
+ test "InvalidPluralizationData message contains count and data" do
+ force_invalid_pluralization_data do |exception|
+ assert_equal 'translation data [:bar] can not be used with :count => 1', exception.message
+ end
end
- def test_missing_interpolation_argument_stores_key_and_string
+ test "MissingInterpolationArgument stores key and string" do
assert_raise(I18n::MissingInterpolationArgument) { force_missing_interpolation_argument }
- force_missing_interpolation_argument
- rescue I18n::ArgumentError => e
- # assert_equal :bar, e.key
- assert_equal "%{bar}", e.string
+ force_missing_interpolation_argument do |exception|
+ # assert_equal :bar, exception.key
+ assert_equal "%{bar}", exception.string
+ end
end
- def test_missing_interpolation_argument_message
- force_missing_interpolation_argument
- rescue I18n::ArgumentError => e
- assert_equal 'missing interpolation argument in "%{bar}" ({:baz=>"baz"} given)', e.message
+ test "MissingInterpolationArgument message contains the missing and given arguments" do
+ force_missing_interpolation_argument do |exception|
+ assert_equal 'missing interpolation argument in "%{bar}" ({:baz=>"baz"} given)', exception.message
+ end
end
- def test_reserved_interpolation_key_stores_key_and_string
- force_reserved_interpolation_key
- rescue I18n::ArgumentError => e
- assert_equal :scope, e.key
- assert_equal "%{scope}", e.string
+ test "ReservedInterpolationKey stores key and string" do
+ force_reserved_interpolation_key do |exception|
+ assert_equal :scope, exception.key
+ assert_equal "%{scope}", exception.string
+ end
end
- def test_reserved_interpolation_key_message
- force_reserved_interpolation_key
- rescue I18n::ArgumentError => e
- assert_equal 'reserved key :scope used in "%{scope}"', e.message
+ test "ReservedInterpolationKey message contains the reserved key" do
+ force_reserved_interpolation_key do |exception|
+ assert_equal 'reserved key :scope used in "%{scope}"', exception.message
+ end
end
private
def force_invalid_locale
I18n.translate(:foo, :locale => nil)
+ rescue I18n::ArgumentError => e
+ block_given? ? yield(e) : raise(e)
end
def force_missing_translation_data(options = {})
I18n.backend.store_translations('de', :bar => nil)
I18n.translate(:foo, options.merge(:scope => :bar, :locale => :de))
+ rescue I18n::ArgumentError => e
+ block_given? ? yield(e) : raise(e)
end
def force_invalid_pluralization_data
I18n.backend.store_translations('de', :foo => [:bar])
I18n.translate(:foo, :count => 1, :locale => :de)
+ rescue I18n::ArgumentError => e
+ block_given? ? yield(e) : raise(e)
end
def force_missing_interpolation_argument
I18n.backend.store_translations('de', :foo => "%{bar}")
I18n.translate(:foo, :baz => 'baz', :locale => :de)
+ rescue I18n::ArgumentError => e
+ block_given? ? yield(e) : raise(e)
end
def force_reserved_interpolation_key
I18n.backend.store_translations('de', :foo => "%{scope}")
I18n.translate(:foo, :baz => 'baz', :locale => :de)
+ rescue I18n::ArgumentError => e
+ block_given? ? yield(e) : raise(e)
end
end
View
12 test/i18n_load_path_test.rb
@@ -1,29 +1,25 @@
-# encoding: utf-8
-$:.unshift File.expand_path(File.dirname(__FILE__) + '/')
-require 'test_helper'
+require File.expand_path('../test_helper', __FILE__)
class I18nLoadPathTest < Test::Unit::TestCase
- # include Tests::Backend::Simple::Setup::Base
-
def setup
I18n.locale = :en
I18n.backend = I18n::Backend::Simple.new
store_translations(:en, :foo => {:bar => 'bar', :baz => 'baz'})
end
- def test_nested_load_paths_do_not_break_locale_loading
+ test "nested load paths do not break locale loading" do
I18n.load_path = [[locales_dir + '/en.yml']]
assert_equal "baz", I18n.t(:'foo.bar')
end
- def test_load_empty_yml_raises_an_error
+ test "loading an empty yml file raises an InvalidLocaleData exception" do
assert_raise I18n::InvalidLocaleData do
I18n.load_path = [[locales_dir + '/invalid/empty.yml']]
I18n.t(:'foo.bar', :default => "baz")
end
end
- def test_adding_arrays_of_filenames_to_load_path_do_not_break_locale_loading
+ test "adding arrays of filenames to the load path does not break locale loading" do
I18n.load_path << Dir[locales_dir + '/*.{rb,yml}']
assert_equal "baz", I18n.t(:'foo.bar')
end
View
255 test/i18n_test.rb
@@ -1,65 +1,62 @@
-# encoding: utf-8
-$:.unshift(File.expand_path(File.dirname(__FILE__))); $:.uniq!
-require 'test_helper'
+require File.expand_path('../test_helper', __FILE__)
class I18nTest < Test::Unit::TestCase
def setup
- I18n.backend.store_translations :'en', {
- :currency => {
- :format => {
- :separator => '.',
- :delimiter => ',',
- }
- }
- }
+ I18n.backend.store_translations(:'en', :currency => { :format => { :separator => '.', :delimiter => ',', } })
end
- def test_version
+ test "exposes its VERSION constant" do
assert I18n::VERSION
end
- def test_uses_simple_backend_set_by_default
+ test "uses the simple backend by default" do
assert I18n.backend.is_a?(I18n::Backend::Simple)
end
- def test_can_set_backend
- assert_nothing_raised { I18n.backend = self }
- assert_equal self, I18n.backend
- ensure
- I18n.backend = I18n::Backend::Simple.new
+ test "can set the backend" do
+ begin
+ assert_nothing_raised { I18n.backend = self }
+ assert_equal self, I18n.backend
+ ensure
+ I18n.backend = I18n::Backend::Simple.new
+ end
end
- def test_uses_en_us_as_default_locale_by_default
+ test "uses :en as a default_locale by default" do
assert_equal :en, I18n.default_locale
end
- def test_can_set_default_locale
- assert_nothing_raised { I18n.default_locale = 'de' }
- assert_equal :de, I18n.default_locale
- ensure
- I18n.default_locale = :en
+ test "can set the default locale" do
+ begin
+ assert_nothing_raised { I18n.default_locale = 'de' }
+ assert_equal :de, I18n.default_locale
+ ensure
+ I18n.default_locale = :en
+ end
end
- def test_uses_default_locale_as_locale_by_default
+ test "uses the default locale as a locale by default" do
assert_equal I18n.default_locale, I18n.locale
end
- def test_can_set_locale_to_thread_current
+ test "sets the current locale to Thread.current" do
assert_nothing_raised { I18n.locale = 'de' }
assert_equal :de, I18n.locale
assert_equal :de, Thread.current[:i18n_config].locale
I18n.locale = :en
end
- def test_can_set_i18n_config
- I18n.config = self
- assert_equal self, I18n.config
- assert_equal self, Thread.current[:i18n_config]
- ensure
- I18n.config = ::I18n::Config.new
+ test "can set the configuration object" do
+ begin
+ I18n.config = self
+ assert_equal self, I18n.config
+ assert_equal self, Thread.current[:i18n_config]
+ ensure
+ I18n.config = ::I18n::Config.new
+ end
end
- def test_locale_is_not_shared_between_configurations
+ test "locale is not shared between configurations" do
a = I18n::Config.new
b = I18n::Config.new
a.locale = :fr
@@ -69,193 +66,171 @@ def test_locale_is_not_shared_between_configurations
assert_equal :en, I18n.locale
end
- def test_other_options_are_shared_between_configurations
- a = I18n::Config.new
- b = I18n::Config.new
- a.default_locale = :fr
- b.default_locale = :es
- assert_equal :es, a.default_locale
- assert_equal :es, b.default_locale
- assert_equal :es, I18n.default_locale
- ensure
- I18n.default_locale = :en
+ test "other options are shared between configurations" do
+ begin
+ a = I18n::Config.new
+ b = I18n::Config.new
+ a.default_locale = :fr
+ b.default_locale = :es
+ assert_equal :es, a.default_locale
+ assert_equal :es, b.default_locale
+ assert_equal :es, I18n.default_locale
+ ensure
+ I18n.default_locale = :en
+ end
end
- def test_defaults_to_dot_as_separator
+ test "uses a dot as a default_separator by default" do
assert_equal '.', I18n.default_separator
end
- def test_can_set_default_separator
- assert_nothing_raised { I18n.default_separator = "\001" }
- ensure
- I18n.default_separator = '.' # revert it
+ test "can set the default_separator" do
+ begin
+ assert_nothing_raised { I18n.default_separator = "\001" }
+ ensure
+ I18n.default_separator = '.'
+ end
end
- def test_normalize_keys
+ test "normalize_keys normalizes given locale, keys and scope to an array of single-key symbols" do
assert_equal [:en, :foo, :bar], I18n.normalize_keys(:en, :bar, :foo)
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, :'baz.buz', :'foo.bar')
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, 'baz.buz', 'foo.bar')
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, %w(baz buz), %w(foo bar))
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, [:baz, :buz], [:foo, :bar])
end
- def test_normalize_keys_should_not_attempt_to_sym_on_empty_string
- assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, :'baz.buz', :'foo..bar')
- assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, :'baz.buz', :'foo......bar')
+ test "normalize_keys discards empty keys" do
+ assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, :'baz..buz', :'foo..bar')
+ assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, :'baz......buz', :'foo......bar')
+ assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, ['baz', nil, '', 'buz'], ['foo', nil, '', 'bar'])
end
- def test_uses_passed_separator_to_normalize_keys
+ test "normalize_keys uses a given separator" do
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, :'baz|buz', :'foo|bar', '|')
end
- def test_can_set_exception_handler
- previous_exception_handler = I18n.exception_handler
- assert_nothing_raised { I18n.exception_handler = :custom_exception_handler }
- ensure
- I18n.exception_handler = previous_exception_handler
+ test "can set the exception_handler" do
+ begin
+ previous_exception_handler = I18n.exception_handler
+ assert_nothing_raised { I18n.exception_handler = :custom_exception_handler }
+ ensure
+ I18n.exception_handler = previous_exception_handler
+ end
end
- with_mocha do
- def test_uses_custom_exception_handler_set_to_i18n_exception_handler
+ test "uses a custom exception handler set to I18n.exception_handler" do
+ begin
previous_exception_handler = I18n.exception_handler
I18n.exception_handler = :custom_exception_handler
I18n.expects(:custom_exception_handler)
I18n.translate :bogus
ensure
I18n.exception_handler = previous_exception_handler
end
+ end
- def test_uses_custom_exception_handler_passed_as_option
- I18n.expects(:custom_exception_handler)
- I18n.translate(:bogus, :exception_handler => :custom_exception_handler)
- end
+ test "uses a custom exception handler passed as an option" do
+ I18n.expects(:custom_exception_handler)
+ I18n.translate(:bogus, :exception_handler => :custom_exception_handler)
+ end
- def test_delegates_translate_to_backend
- I18n.backend.expects(:translate).with('de', :foo, {})
- I18n.translate :foo, :locale => 'de'
- end
+ test "delegates translate calls to the backend" do
+ I18n.backend.expects(:translate).with('de', :foo, {})
+ I18n.translate :foo, :locale => 'de'
+ end
- def test_delegates_localize_to_backend
- I18n.backend.expects(:localize).with('de', :whatever, :default, {})
- I18n.localize :whatever, :locale => 'de'
- end
+ test "delegates localize calls to the backend" do
+ I18n.backend.expects(:localize).with('de', :whatever, :default, {})
+ I18n.localize :whatever, :locale => 'de'
+ end
- def test_translate_given_no_locale_uses_i18n_locale
- I18n.backend.expects(:translate).with(:en, :foo, {})
- I18n.translate :foo
- end
+ test "translate given no locale uses the current locale" do
+ I18n.backend.expects(:translate).with(:en, :foo, {})
+ I18n.translate :foo
end
- def test_translate_on_nested_symbol_keys_works
+ test "translate works with nested symbol keys" do
assert_equal ".", I18n.t(:'currency.format.separator')
end
- def test_translate_with_nested_string_keys_works
+ test "translate works with nested string keys" do
assert_equal ".", I18n.t('currency.format.separator')
end
- def test_translate_with_array_as_scope_works
+ test "translate with an array as a scope works" do
assert_equal ".", I18n.t(:separator, :scope => %w(currency format))
end
- def test_translate_with_array_containing_dot_separated_strings_as_scope_works
+ test "translate with an array containing dot separated strings as a scope works" do
assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
end
- def test_translate_with_key_array_and_dot_separated_scope_works
+ test "translate with an array of keys and a dot separated string as a scope works" do
assert_equal [".", ","], I18n.t(%w(separator delimiter), :scope => 'currency.format')
end
- def test_translate_with_dot_separated_key_array_and_scope_works
+ test "translate with an array of dot separated keys and a scope works" do
assert_equal [".", ","], I18n.t(%w(format.separator format.delimiter), :scope => 'currency')
end
- # with_mocha do
- # 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
- # end
-
# def test_translate_given_no_args_raises_missing_translation_data
# assert_equal "translation missing: en, no key", I18n.t
# end
- def test_translate_given_a_bogus_key_raises_missing_translation_data
+ test "translate given a bogus key returns an error message" do
assert_equal "translation missing: en.bogus", I18n.t(:bogus)
end
- def test_translate_empty_string_raises_argument_error
+ test "translate given an empty string as a key raises an I18n::ArgumentError" do
assert_raise(I18n::ArgumentError) { I18n.t("") }
end
- def test_localize_nil_raises_argument_error
+ test "localize given nil raises an I18n::ArgumentError" do
assert_raise(I18n::ArgumentError) { I18n.l nil }