Skip to content

Instantly share code, notes, and snippets.

@henrik
Last active August 29, 2015 13:55
Show Gist options
  • Save henrik/8729516 to your computer and use it in GitHub Desktop.
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.
# 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