Class: I18nSimpleBackendLocalizeTimeTest

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

Instance Method Summary collapse

Methods included from I18nSimpleBackendTestSetup

#add_datetime_translations, #backend_get_translations, #setup_backend

Instance Method Details

#setupObject



418
419
420
421
422
423
424
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 418

def setup
  @old_timezone, ENV['TZ'] = ENV['TZ'], 'UTC'
  @backend = I18n::Backend::Simple.new
  add_datetime_translations
  @morning = Time.parse '2008-01-01 6:00 UTC'
  @evening = Time.parse '2008-01-01 18:00 UTC'
end

#teardownObject



426
427
428
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 426

def teardown
  @old_timezone ? ENV['TZ'] = @old_timezone : ENV.delete('TZ')
end

#test_translate_given_a_day_name_format_it_returns_the_correct_day_nameObject

TODO Seems to break on Windows because ENV is ignored. What’s a better way to do this? def test_translate_given_the_default_format_it_uses_it

assert_equal 'Di, 01. Jan 2008 06:00:00 +0000', @backend.localize('de', @morning, :default)

end



443
444
445
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 443

def test_translate_given_a_day_name_format_it_returns_the_correct_day_name
  assert_equal 'Dienstag', @backend.localize('de', @morning, '%A')
end

#test_translate_given_a_meridian_indicator_format_it_returns_the_correct_meridian_indicatorObject



459
460
461
462
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 459

def test_translate_given_a_meridian_indicator_format_it_returns_the_correct_meridian_indicator
  assert_equal 'am', @backend.localize('de', @morning, '%p')
  assert_equal 'pm', @backend.localize('de', @evening, '%p')
end

#test_translate_given_a_month_name_format_it_returns_the_correct_month_nameObject



451
452
453
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 451

def test_translate_given_a_month_name_format_it_returns_the_correct_month_name
  assert_equal 'Januar', @backend.localize('de', @morning, '%B')
end

#test_translate_given_an_abbr_day_name_format_it_returns_the_correct_abbrevated_day_nameObject



447
448
449
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 447

def test_translate_given_an_abbr_day_name_format_it_returns_the_correct_abbrevated_day_name
  assert_equal 'Di', @backend.localize('de', @morning, '%a')
end

#test_translate_given_an_abbr_month_name_format_it_returns_the_correct_abbrevated_month_nameObject



455
456
457
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 455

def test_translate_given_an_abbr_month_name_format_it_returns_the_correct_abbrevated_month_name
  assert_equal 'Jan', @backend.localize('de', @morning, '%b')
end

#test_translate_given_an_unknown_format_it_does_not_failObject



468
469
470
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 468

def test_translate_given_an_unknown_format_it_does_not_fail
  assert_nothing_raised{ @backend.localize 'de', @morning, '%x' }
end

#test_translate_given_no_format_it_does_not_failObject



464
465
466
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 464

def test_translate_given_no_format_it_does_not_fail
  assert_nothing_raised{ @backend.localize 'de', @morning }
end

#test_translate_given_the_long_format_it_uses_itObject



434
435
436
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 434

def test_translate_given_the_long_format_it_uses_it
  assert_equal '01. Januar 2008 06:00', @backend.localize('de', @morning, :long)
end

#test_translate_given_the_short_format_it_uses_itObject



430
431
432
# File 'lib/vendor/i18n/test/simple_backend_test.rb', line 430

def test_translate_given_the_short_format_it_uses_it
  assert_equal '01. Jan 06:00', @backend.localize('de', @morning, :short)
end