Created
April 27, 2011 09:03
-
-
Save remvee/943953 to your computer and use it in GitHub Desktop.
Extend rails functional test case with asserts for missing translations.
This file contains hidden or 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
| # 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.*?(>|>)(.+?)(<|<\\?)/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