2014-10-26 20:51:42 -04:00
|
|
|
module UnitTests
|
|
|
|
module I18nFaker
|
|
|
|
extend self
|
2014-10-15 02:13:17 -04:00
|
|
|
|
2014-10-26 20:51:42 -04:00
|
|
|
def self.configure_example_group(example_group)
|
|
|
|
example_group.include(self)
|
|
|
|
end
|
2013-03-28 20:02:52 -04:00
|
|
|
|
2019-01-30 00:58:03 -05:00
|
|
|
def stubbing_translations(translations)
|
|
|
|
stub_translations(translations)
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
I18n.backend.reload!
|
|
|
|
I18n.backend.send(:init_translations)
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_translations(translations)
|
|
|
|
translations.each do |key, message|
|
|
|
|
stub_translation(key, message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-10-26 20:51:42 -04:00
|
|
|
def stub_translation(key_or_keys, message)
|
|
|
|
keys = [key_or_keys].flatten.join('.').split('.')
|
|
|
|
tree = keys.reverse.inject(message) { |data, key| { key => data } }
|
|
|
|
I18n.backend.store_translations(:en, tree)
|
|
|
|
end
|
|
|
|
end
|
2013-03-28 20:02:52 -04:00
|
|
|
end
|