Last active
August 29, 2015 13:55
-
-
Save henrik/8729516 to your computer and use it in GitHub Desktop.
Overwrite `t` helper in Rails views to raise in tests, which it otherwise doesn't do, even if I18n is configured to.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Overwrite `t` helper in Rails views to raise in tests, | |
# which it otherwise doesn't do, even if I18n is configured to. | |
# | |
# Installation: | |
# put in lib/i18n_raise_on_missing_in_action_view.rb | |
# and require "i18n_raise_on_missing_in_action_view" in e.g. config/environments/test.rb | |
if Rails.env.test? | |
module ActionView::Helpers::TranslationHelper | |
def t_with_raise(*args) | |
value = t_without_raise(*args) | |
if value.to_s.match(/title="translation missing: (.+)"/) | |
raise "Translation missing: #{$1}" | |
else | |
value | |
end | |
end | |
alias_method :translate_with_raise, :t_with_raise | |
alias_method_chain :t, :raise | |
alias_method_chain :translate, :raise | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment