1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
# encoding: utf-8
$KCODE = 'u' unless RUBY_VERSION >= '1.9'
$:.unshift File.expand_path("../lib", File.dirname(__FILE__))
$:.unshift File.expand_path(File.dirname(__FILE__))
$:.uniq!
require 'rubygems'
require 'test/unit'
require 'time'
require 'yaml'
require 'i18n'
require 'test_setup_requirements'
setup_mocha
class Test::Unit::TestCase
def self.test(name, &block)
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
defined = instance_method(test_name) rescue false
raise "#{test_name} is already defined in #{self}" if defined
if block_given?
define_method(test_name, &block)
else
define_method(test_name) do
flunk "No implementation provided for #{name}"
end
end
end
def self.with_mocha
yield if Object.respond_to?(:expects)
end
def teardown
I18n.locale = nil
I18n.default_locale = :en
I18n.load_path = []
I18n.available_locales = nil
I18n.backend = nil
end
def translations
I18n.backend.instance_variable_get(:@translations)
end
def store_translations(*args)
data = args.pop
locale = args.pop || :en
I18n.backend.store_translations(locale, data)
end
def locales_dir
File.dirname(__FILE__) + '/test_data/locales'
end
def euc_jp(string)
string.encode!(Encoding::EUC_JP)
end
def can_store_procs?
I18n.backend.class != I18n::Backend::ActiveRecord or
I18n::Backend::ActiveRecord.included_modules.include?(I18n::Backend::ActiveRecord::StoreProcs)
end
def capture(stream)
begin
stream = stream.to_s
eval "$#{stream} = StringIO.new"
yield
result = eval("$#{stream}").string
ensure
eval("$#{stream} = #{stream.upcase}")
end
result
end
end
Object.class_eval do
def meta_class
class << self; self; end
end
end unless Object.method_defined?(:meta_class)
|