Sha256: cc805489ae3659e8de013c31bc99fd1eca7b05e14919b10986a4595ee465bcd3
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
module Html module Test module Assertions def assert_tidy(body = nil) assert_validates(:tidy, body) end def assert_w3c(body = nil) assert_validates(:w3c, body) end def assert_xmllint(body = nil) assert_validates(:xmllint, body) end def assert_validates(types = nil, body = nil, url = nil, options = {}) verbose = ( options[:verbose] ) ? options[:verbose] : Html::Test::Validator.verbose body ||= @response.body types ||= [:tidy, :w3c, :xmllint] types = [types] if !types.is_a?(Array) types.each do |t| log("validating #{url} with #{t} ... ") if verbose error = Html::Test::Validator.send("#{t}_errors", body) if error.nil? log("OK\n") if verbose else log("FAILURE\n") if verbose assert_message = "Validator #{t} failed" assert_message << " for url #{url}" if url assert_message << " with message '#{error}'" Rails.logger.error(assert_message + " for response body:\n #{with_line_counts(body)}") assert(error.nil?, assert_message) end end end private def log(message) print(message) end def with_line_counts(body) separator = ("-" * 40) + $/ body_counts = separator.dup body.each_with_index do |line, i| body_counts << sprintf("%4u %s", i+1, line) # Right align line numbers end body_counts << separator body_counts end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jakewendt-html_test-0.2.3 | lib/assertions.rb |