Skip to content

Instantly share code, notes, and snippets.

@remvee
Created April 27, 2011 09:03
Show Gist options
  • Select an option

  • Save remvee/943953 to your computer and use it in GitHub Desktop.

Select an option

Save remvee/943953 to your computer and use it in GitHub Desktop.
Extend rails functional test case with asserts for missing translations.
# Extend functional test case with asserts for missing translations.
# These asserts are automatically included on +assert_response+ and
# +should_respond_with+.
class ActionController::TestCase
def assert_no_missing_translations
assert(@response.body !~ %r{ class=.*translation_missing.*?(>|&gt;)(.+?)(<|&lt;\\?)/span},
"missing translation in body: #{$2.inspect}")
assert(@response.body !~ /^translation missing: (.*)$/,
"missing translation in body: #{$1.inspect}")
assert(flash.values.join("\n") !~ /^translation missing: (.*)$/,
"missing translation in flash: #{$1.inspect}")
end
def assert_response_with_no_missing_translations(*args)
assert_response_without_no_missing_translations(*args)
assert_no_missing_translations
end
alias_method_chain :assert_response, :no_missing_translations
if defined?(Shoulda)
def self.should_not_miss_translations
should "not miss translations" do
assert_no_missing_translations
end
end
class << self
def should_respond_with_with_no_missing_translations(*args)
should_respond_with_without_no_missing_translations(*args)
should_not_miss_translations
end
alias_method_chain :should_respond_with, :no_missing_translations
end
end
end if RAILS_ENV == "test"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment