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

Class Method Summary collapse

Class Attribute Details

.translation_backendObject

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_translationsObject

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_translationsObject

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