Module: RackTest::ValidateDom
- Defined in:
- lib/capybara/validate_html5.rb
Instance Method Summary collapse
-
#base_href ⇒ Object
Skip HTML validation during base_href calculations.
-
#dom ⇒ Object
If loading the DOM for the first time and not skipping HTML validation, validate the HTML and expect no errors.
-
#skip_html_validation ⇒ Object
Skip HTML validation inside the block.
Instance Method Details
#base_href ⇒ Object
Skip HTML validation during base_href calculations.
60 61 62 |
# File 'lib/capybara/validate_html5.rb', line 60 def base_href skip_html_validation{super} end |
#dom ⇒ Object
If loading the DOM for the first time and not skipping HTML validation, validate the HTML and expect no errors.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/capybara/validate_html5.rb', line 31 def dom unless @dom || @skip_html_validation errors = Nokogiri::HTML5(html, max_errors: 10).errors unless errors.empty? called_from = caller_locations.detect do |loc| loc.path !~ %r{lib/(capybara|nokogiri|minitest)} end html_lines = html.split("\n").map.with_index{|line, i| "#{sprintf("%6i", i+1)}: #{line}"} error_info = String.new error_info << (<<END_MSG) invalid HTML on page returned for #{last_request.path}, called from #{called_from.path}:#{called_from.lineno} END_MSG errors.each do |error| error_line = error.line begin_line = error_line - 3 end_line = error_line + 3 begin_line = 0 if begin_line < 0 error_info << error.to_s << "\n" << html_lines[begin_line..end_line].join("\n") << "\n\n" end raise HTML5ValidationError, "#{errors.size} HTML5 validation errors: #{error_info}" end end super end |
#skip_html_validation ⇒ Object
Skip HTML validation inside the block.
21 22 23 24 25 26 27 |
# File 'lib/capybara/validate_html5.rb', line 21 def skip_html_validation skip = @skip_html_validation @skip_html_validation = true yield ensure @skip_html_validation = skip end |