Skip to content

Commit

Permalink
Create our own TestCase class to add methods
Browse files Browse the repository at this point in the history
Rather than extending the base Test::Unit::TestCase, simply create our
own test case and add methods to it, and make sure we inherit from this
new test case everywhere.

Also make sure to call `super` on the teardown method.
  • Loading branch information
carlosantoniodasilva committed May 9, 2014
1 parent 38f7d53 commit 706bcbf
Show file tree
Hide file tree
Showing 32 changed files with 61 additions and 57 deletions.
2 changes: 1 addition & 1 deletion test/api/all_features_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
puts "not testing with Cache enabled because active_support can not be found"
end

class I18nAllFeaturesApiTest < Test::Unit::TestCase
class I18nAllFeaturesApiTest < I18n::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Metadata
include I18n::Backend::Cache
Expand Down
2 changes: 1 addition & 1 deletion test/api/cascade_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class I18nCascadeApiTest < Test::Unit::TestCase
class I18nCascadeApiTest < I18n::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Cascade
end
Expand Down
2 changes: 1 addition & 1 deletion test/api/chain_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class I18nApiChainTest < Test::Unit::TestCase
class I18nApiChainTest < I18n::TestCase
def setup
super
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, I18n.backend)
Expand Down
2 changes: 1 addition & 1 deletion test/api/fallbacks_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class I18nFallbacksApiTest < Test::Unit::TestCase
class I18nFallbacksApiTest < I18n::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Fallbacks
end
Expand Down
4 changes: 2 additions & 2 deletions test/api/key_value_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'test_helper'

I18n::Tests.setup_rufus_tokyo
I18n::TestCase.setup_rufus_tokyo

class I18nKeyValueApiTest < Test::Unit::TestCase
class I18nKeyValueApiTest < I18n::TestCase
include I18n::Tests::Basics
include I18n::Tests::Defaults
include I18n::Tests::Interpolation
Expand Down
6 changes: 3 additions & 3 deletions test/api/memoize_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class I18nMemoizeBackendWithSimpleApiTest < Test::Unit::TestCase
class I18nMemoizeBackendWithSimpleApiTest < I18n::TestCase
include I18n::Tests::Basics
include I18n::Tests::Defaults
include I18n::Tests::Interpolation
Expand All @@ -27,9 +27,9 @@ def setup
end
end

I18n::Tests.setup_rufus_tokyo
I18n::TestCase.setup_rufus_tokyo

class I18nMemoizeBackendWithKeyValueApiTest < Test::Unit::TestCase
class I18nMemoizeBackendWithKeyValueApiTest < I18n::TestCase
include I18n::Tests::Basics
include I18n::Tests::Defaults
include I18n::Tests::Interpolation
Expand Down
7 changes: 1 addition & 6 deletions test/api/override_test.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
require 'test_helper'

class I18nOverrideTest < Test::Unit::TestCase
class I18nOverrideTest < I18n::TestCase
module OverrideInverse

def translate(*args)
super(*args).reverse
end
alias :t :translate

end

module OverrideSignature

def translate(*args)
args.first + args[1]
end
alias :t :translate

end

def setup
Expand Down Expand Up @@ -44,5 +40,4 @@ def setup
@I18n.extend OverrideSignature
assert_equal 'HelloWelcome message on home page', @I18n.translate('Hello', 'Welcome message on home page', :tokenize => true) # tr8n example
end

end
2 changes: 1 addition & 1 deletion test/api/pluralization_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class I18nPluralizationApiTest < Test::Unit::TestCase
class I18nPluralizationApiTest < I18n::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Pluralization
end
Expand Down
2 changes: 1 addition & 1 deletion test/api/simple_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class I18nSimpleBackendApiTest < Test::Unit::TestCase
class I18nSimpleBackendApiTest < I18n::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Pluralization
end
Expand Down
2 changes: 1 addition & 1 deletion test/backend/cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$stderr.puts "Skipping cache tests using ActiveSupport"
else

class I18nBackendCacheTest < Test::Unit::TestCase
class I18nBackendCacheTest < I18n::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Cache
end
Expand Down
2 changes: 1 addition & 1 deletion test/backend/cascade_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class I18nBackendCascadeTest < Test::Unit::TestCase
class I18nBackendCascadeTest < I18n::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Cascade
end
Expand Down
2 changes: 1 addition & 1 deletion test/backend/chain_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class I18nBackendChainTest < Test::Unit::TestCase
class I18nBackendChainTest < I18n::TestCase
def setup
@first = backend(:en => {
:foo => 'Foo', :formats => { :short => 'short' }, :plural_1 => { :one => '%{count}' }, :dates => {:a => "A"}
Expand Down
2 changes: 1 addition & 1 deletion test/backend/exceptions_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class I18nBackendExceptionsTest < Test::Unit::TestCase
class I18nBackendExceptionsTest < I18n::TestCase
def setup
I18n.backend = I18n::Backend::Simple.new
end
Expand Down
8 changes: 4 additions & 4 deletions test/backend/fallbacks_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class I18nBackendFallbacksTranslateTest < Test::Unit::TestCase
class I18nBackendFallbacksTranslateTest < I18n::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Fallbacks
end
Expand Down Expand Up @@ -75,7 +75,7 @@ def setup
test "should ensure that default is not splitted on new line char" do
assert_equal "Default \n Bar", I18n.t(:missing_bar, :default => "Default \n Bar")
end

test "should not raise error when enforce_available_locales is true, :'pt' is missing and default is a Symbol" do
I18n.enforce_available_locales = true
begin
Expand All @@ -86,7 +86,7 @@ def setup
end
end

class I18nBackendFallbacksLocalizeTest < Test::Unit::TestCase
class I18nBackendFallbacksLocalizeTest < I18n::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Fallbacks
end
Expand Down Expand Up @@ -118,7 +118,7 @@ def setup
end
end

class I18nBackendFallbacksWithChainTest < Test::Unit::TestCase
class I18nBackendFallbacksWithChainTest < I18n::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Fallbacks
end
Expand Down
4 changes: 2 additions & 2 deletions test/backend/interpolation_compiler_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class InterpolationCompilerTest < Test::Unit::TestCase
class InterpolationCompilerTest < I18n::TestCase
Compiler = I18n::Backend::InterpolationCompiler::Compiler

def compile_and_interpolate(str, values = {})
Expand Down Expand Up @@ -95,7 +95,7 @@ def test_custom_missing_interpolation_argument_handler
end
end

class I18nBackendInterpolationCompilerTest < Test::Unit::TestCase
class I18nBackendInterpolationCompilerTest < I18n::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::InterpolationCompiler
end
Expand Down
4 changes: 2 additions & 2 deletions test/backend/key_value_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'test_helper'

I18n::Tests.setup_rufus_tokyo
I18n::TestCase.setup_rufus_tokyo

class I18nBackendKeyValueTest < Test::Unit::TestCase
class I18nBackendKeyValueTest < I18n::TestCase
def setup_backend!(subtree=true)
I18n.backend = I18n::Backend::KeyValue.new(Rufus::Tokyo::Cabinet.new('*'), subtree)
store_translations(:en, :foo => { :bar => 'bar', :baz => 'baz' })
Expand Down
2 changes: 1 addition & 1 deletion test/backend/metadata_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class I18nBackendMetadataTest < Test::Unit::TestCase
class I18nBackendMetadataTest < I18n::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Metadata
end
Expand Down
2 changes: 1 addition & 1 deletion test/backend/pluralization_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class I18nBackendPluralizationTest < Test::Unit::TestCase
class I18nBackendPluralizationTest < I18n::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Pluralization
include I18n::Backend::Fallbacks
Expand Down
2 changes: 1 addition & 1 deletion test/backend/simple_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class I18nBackendSimpleTest < Test::Unit::TestCase
class I18nBackendSimpleTest < I18n::TestCase
def setup
I18n.backend = I18n::Backend::Simple.new
I18n.load_path = [locales_dir + '/en.yml']
Expand Down
2 changes: 1 addition & 1 deletion test/backend/transliterator_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# encoding: utf-8
require 'test_helper'

class I18nBackendTransliterator < Test::Unit::TestCase
class I18nBackendTransliterator < I18n::TestCase
def setup
I18n.backend = I18n::Backend::Simple.new
@proc = lambda { |n| n.upcase }
Expand Down
2 changes: 1 addition & 1 deletion test/core_ext/hash_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'test_helper'
require 'i18n/core_ext/hash'

class I18nCoreExtHashInterpolationTest < Test::Unit::TestCase
class I18nCoreExtHashInterpolationTest < I18n::TestCase
test "#deep_symbolize_keys" do
hash = { 'foo' => { 'bar' => { 'baz' => 'bar' } } }
expected = { :foo => { :bar => { :baz => 'bar' } } }
Expand Down
2 changes: 1 addition & 1 deletion test/core_ext/string/interpolate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# some tests taken from Masao's tests
# http://github.com/mutoh/gettext/blob/edbbe1fa8238fa12c7f26f2418403015f0270e47/test/test_string.rb

class I18nCoreExtStringInterpolationTest < Test::Unit::TestCase
class I18nCoreExtStringInterpolationTest < I18n::TestCase
test "String interpolates a single argument" do
assert_equal "Masao", "%s" % "Masao"
end
Expand Down
2 changes: 1 addition & 1 deletion test/gettext/api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

include I18n::Gettext::Helpers

class I18nGettextApiTest < Test::Unit::TestCase
class I18nGettextApiTest < I18n::TestCase
def setup
I18n.locale = :en
I18n.backend.store_translations :de, {
Expand Down
2 changes: 1 addition & 1 deletion test/gettext/backend_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# apparently Ruby 1.9.1p129 has encoding problems with the gettext po parser
unless RUBY_VERSION == '1.9.1' && RUBY_PATCHLEVEL <= 129

class I18nGettextBackendTest < Test::Unit::TestCase
class I18nGettextBackendTest < I18n::TestCase
include I18n::Gettext::Helpers

class Backend < I18n::Backend::Simple
Expand Down
2 changes: 1 addition & 1 deletion test/i18n/exceptions_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class I18nExceptionsTest < Test::Unit::TestCase
class I18nExceptionsTest < I18n::TestCase
def test_invalid_locale_stores_locale
force_invalid_locale
rescue I18n::ArgumentError => exception
Expand Down
4 changes: 2 additions & 2 deletions test/i18n/interpolate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# thanks to Masao's String extensions, some tests taken from Masao's tests
# http://github.com/mutoh/gettext/blob/edbbe1fa8238fa12c7f26f2418403015f0270e47/test/test_string.rb

class I18nInterpolateTest < Test::Unit::TestCase
class I18nInterpolateTest < I18n::TestCase
test "String interpolates a hash argument w/ named placeholders" do
assert_equal "Masao Mutoh", I18n.interpolate("%{first} %{last}", :first => 'Masao', :last => 'Mutoh' )
end
Expand Down Expand Up @@ -60,7 +60,7 @@ def test_sprintf_mix_unformatted_and_formatted_named_placeholders
end
end

class I18nMissingInterpolationCustomHandlerTest < Test::Unit::TestCase
class I18nMissingInterpolationCustomHandlerTest < I18n::TestCase
def setup
@old_handler = I18n.config.missing_interpolation_argument_handler
I18n.config.missing_interpolation_argument_handler = lambda do |key, values, string|
Expand Down
2 changes: 1 addition & 1 deletion test/i18n/load_path_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class I18nLoadPathTest < Test::Unit::TestCase
class I18nLoadPathTest < I18n::TestCase
def setup
I18n.locale = :en
I18n.backend = I18n::Backend::Simple.new
Expand Down
2 changes: 1 addition & 1 deletion test/i18n_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# encoding: utf-8
require 'test_helper'

class I18nTest < Test::Unit::TestCase
class I18nTest < I18n::TestCase
def setup
store_translations(:en, :currency => { :format => { :separator => '.', :delimiter => ',', } })
store_translations(:nl, :currency => { :format => { :separator => ',', :delimiter => '.', } })
Expand Down
4 changes: 2 additions & 2 deletions test/locale/fallbacks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

include I18n::Locale

class I18nFallbacksDefaultsTest < Test::Unit::TestCase
class I18nFallbacksDefaultsTest < I18n::TestCase
def teardown
I18n.default_locale = :en
end
Expand All @@ -26,7 +26,7 @@ def teardown
end
end

class I18nFallbacksComputationTest < Test::Unit::TestCase
class I18nFallbacksComputationTest < I18n::TestCase
def setup
@fallbacks = Fallbacks.new(:'en-US')
end
Expand Down
6 changes: 3 additions & 3 deletions test/locale/tag/rfc4646_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# encoding: utf-8
require 'test_helper'

class I18nLocaleTagRfc4646ParserTest < Test::Unit::TestCase
class I18nLocaleTagRfc4646ParserTest < I18n::TestCase
include I18n::Locale

test "Rfc4646::Parser given a valid tag 'de' returns an array of subtags" do
Expand Down Expand Up @@ -31,7 +31,7 @@ class I18nLocaleTagRfc4646ParserTest < Test::Unit::TestCase

# Tag for the locale 'de-Latn-DE-Variant-a-ext-x-phonebk-i-klingon'

class I18nLocaleTagSubtagsTest < Test::Unit::TestCase
class I18nLocaleTagSubtagsTest < I18n::TestCase
include I18n::Locale

def setup
Expand Down Expand Up @@ -78,7 +78,7 @@ def setup

# Tag inheritance

class I18nLocaleTagSubtagsTest < Test::Unit::TestCase
class I18nLocaleTagSubtagsTest < I18n::TestCase
test "#parent returns 'de-Latn-DE-variant-a-ext-x-phonebk' as the parent of 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon'" do
tag = Tag::Rfc4646.new(*%w(de Latn DE variant a-ext x-phonebk i-klingon))
assert_equal 'de-Latn-DE-variant-a-ext-x-phonebk', tag.parent.to_s
Expand Down
2 changes: 1 addition & 1 deletion test/locale/tag/simple_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# encoding: utf-8
require 'test_helper'

class I18nLocaleTagSimpleTest < Test::Unit::TestCase
class I18nLocaleTagSimpleTest < I18n::TestCase
include I18n::Locale

test "returns 'de' as the language subtag in lowercase" do
Expand Down
Loading

0 comments on commit 706bcbf

Please sign in to comment.