module AnnoTranslate::Assertions
Additions to TestUnit to make testing i18n easier
Public Instance Methods
assert_translated(msg = nil) { || ... }
click to toggle source
Assert that within the block there are no missing translation keys. This can be used in a more tailored way that the global strict_mode
Example:
assert_translated do str = "Test will fail for #{I18n.t('a_missing_key')}" end
# File lib/annotranslate.rb, line 245 def assert_translated(msg = nil, &block) # Enable strict mode to force raising of MissingTranslationData AnnoTranslate.strict_mode(true) msg ||= "Expected no missing translation keys" begin yield # Credtit for running the assertion assert(true, msg) rescue I18n::MissingTranslationData => e # Fail! error = build_message(msg, "Exception raised:\n?", e) AnnoTranslate.log.error assert_block(error) {false} ensure # uninstall strict exception handler AnnoTranslate.strict_mode(false) end end