Module: TextHelpers::RSpec::TestHelpers
- Defined in:
- lib/text_helpers/rspec.rb
Overview
TextHelpers::RSpec::TestHelpers contains helper methods to be used from within your examples.
Instance Method Summary collapse
-
#set_translation(path, value, locale: I18n.locale, scope: nil) ⇒ Object
Public: Set a new translation in the test translations.
Instance Method Details
#set_translation(path, value, locale: I18n.locale, scope: nil) ⇒ Object
Public: Set a new translation in the test translations.
path - The path to the key, like ‘models.user.attributes.title’. value - The localized value. locale - The locale the translation should be defined in. scope - The scope the translation should be defined under.
Returns true on success.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/text_helpers/rspec.rb', line 46 def set_translation(path, value, locale: I18n.locale, scope: nil) *hash_keys, last_key = I18n.normalize_keys(nil, path, scope) data = {} last_hash = hash_keys.inject(data) { |h,k| h[k] = Hash.new } last_hash[last_key] = value TextHelpers::RSpec.translation_backend.store_translations(locale, data) true end |