test_helper.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. $KCODE = 'u' if RUBY_VERSION <= '1.9'
  2. require 'rubygems'
  3. require 'test/unit'
  4. # Do not load the i18n gem from libraries like active_support.
  5. #
  6. # This is required for testing against Rails 2.3 because active_support/vendor.rb#24 tries
  7. # to load I18n using the gem method. Instead, we want to test the local library of course.
  8. alias :gem_for_ruby_19 :gem # for 1.9. gives a super ugly seg fault otherwise
  9. def gem(gem_name, *version_requirements)
  10. gem_name =='i18n' ? puts("skipping loading the i18n gem ...") : super
  11. end
  12. require 'bundler/setup'
  13. require 'i18n'
  14. require 'mocha'
  15. require 'test_declarative'
  16. class Test::Unit::TestCase
  17. def teardown
  18. I18n.locale = nil
  19. I18n.default_locale = :en
  20. I18n.load_path = []
  21. I18n.available_locales = nil
  22. I18n.backend = nil
  23. end
  24. def translations
  25. I18n.backend.instance_variable_get(:@translations)
  26. end
  27. def store_translations(*args)
  28. data = args.pop
  29. locale = args.pop || :en
  30. I18n.backend.store_translations(locale, data)
  31. end
  32. def locales_dir
  33. File.dirname(__FILE__) + '/test_data/locales'
  34. end
  35. end
  36. module Kernel
  37. def setup_rufus_tokyo
  38. require 'rufus/tokyo'
  39. rescue LoadError => e
  40. puts "can't use KeyValue backend because: #{e.message}"
  41. end
  42. end
  43. Object.class_eval do
  44. def meta_class
  45. class << self; self; end
  46. end
  47. end unless Object.method_defined?(:meta_class)