diff options
| -rw-r--r-- | test/test_helper.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/test_helper.rb b/test/test_helper.rb index b7fe2b58..ec9b18b3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb | |||
| @@ -78,4 +78,25 @@ class ActiveSupport::TestCase | |||
| 78 | node.lock_for_editing!(user) | 78 | node.lock_for_editing!(user) |
| 79 | node.draft || node.create_new_draft(user) | 79 | node.draft || node.create_new_draft(user) |
| 80 | end | 80 | end |
| 81 | |||
| 82 | def assert_well_formed | ||
| 83 | body = @response.body | ||
| 84 | doc = if body.lstrip.start_with?("<!DOCTYPE", "<html") | ||
| 85 | Nokogiri::HTML5(body, max_errors: -1) | ||
| 86 | else | ||
| 87 | Nokogiri::HTML5.fragment(body, max_errors: -1) | ||
| 88 | end | ||
| 89 | assert_empty doc.errors, | ||
| 90 | "Malformed markup:\n#{doc.errors.map(&:to_s).join("\n")}" | ||
| 91 | end | ||
| 92 | end | ||
| 93 | |||
| 94 | class ActionController::TestCase | ||
| 95 | def process(*args, **kwargs) | ||
| 96 | super.tap do | ||
| 97 | if @response&.successful? && @response.media_type == "text/html" | ||
| 98 | assert_well_formed | ||
| 99 | end | ||
| 100 | end | ||
| 101 | end | ||
| 81 | end | 102 | end |
