1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00
thoughtbot--shoulda-matchers/spec/support/unit/helpers/i18n_faker.rb

30 lines
717 B
Ruby
Raw Normal View History

module UnitTests
module I18nFaker
extend self
def self.configure_example_group(example_group)
example_group.include(self)
end
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
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
end