Module: TextHelpers::RSpec
- Defined in:
- lib/text_helpers/rspec.rb
Overview
TextHelpers::RSpec contains some helpers for making testing around i18n easier, especially with tests that may generate keys that map to translations that aren’t/should not be present in your production localization files.
Defined Under Namespace
Modules: TestHelpers
Class Attribute Summary collapse
-
.translation_backend ⇒ Object
Returns the value of attribute translation_backend.
Class Method Summary collapse
-
.reset_spec_translations ⇒ Object
Public: Reset the test translations.
-
.setup_spec_translations ⇒ Object
Public: Set up the test translation environment.
Class Attribute Details
.translation_backend ⇒ Object
Returns the value of attribute translation_backend.
8 9 10 |
# File 'lib/text_helpers/rspec.rb', line 8 def translation_backend @translation_backend end |
Class Method Details
.reset_spec_translations ⇒ Object
Public: Reset the test translations.
Clears out any translations added during an example run.
Returns nothing.
26 27 28 29 30 31 32 |
# File 'lib/text_helpers/rspec.rb', line 26 def self.reset_spec_translations if self.translation_backend.nil? raise "translation_backend is nil. Ensure .setup_spec_translations was called" end self.translation_backend.reload! end |
.setup_spec_translations ⇒ Object
Public: Set up the test translation environment.
Should ideally be called in an RSpec ‘before(:suite)` hook.
Returns the new I18n backend.
16 17 18 19 |
# File 'lib/text_helpers/rspec.rb', line 16 def self.setup_spec_translations self.translation_backend = I18n::Backend::Simple.new I18n.backend = I18n::Backend::Chain.new(self.translation_backend, I18n.backend) end |