Skip to content

Instantly share code, notes, and snippets.

@gamov
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save gamov/46054d7b4c28730f04c1 to your computer and use it in GitHub Desktop.

Select an option

Save gamov/46054d7b4c28730f04c1 to your computer and use it in GitHub Desktop.

Revisions

  1. gamov revised this gist May 29, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Markup Validation Assertion
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@

    # inspired by http://www.scottraymond.net/2005/9/20/validating-x-html-in-rails/
    def assert_valid_markup(markup = @response.body, fragment = false)
    str = if fragment
  2. gamov revised this gist Mar 11, 2015. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions Markup Validation Assertion
    Original file line number Diff line number Diff line change
    @@ -11,8 +11,7 @@
    query = 'fragment=' + CGI.escape(str) + '&output=xml'
    w3c.post2('/check', query)
    end
    # puts "Errors Nbr = #{response['X-W3C-Validator-Errors']}"
    # puts response.body result in html (save it to tmp?) then report as message below

    unless response['x-w3c-validator-status'] == 'Valid'
    val_folder = Rails.root.join('tmp').join('validations')
    val_folder.mkdir
  3. gamov renamed this gist Mar 11, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. gamov revised this gist Mar 11, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Markup Validation
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    # inspired by http://www.scottraymond.net/2005/9/20/validating-x-html-in-rails/
    def assert_valid_markup(markup = @response.body, fragment = false)
    str = if fragment
    "<!doctype html><head><title>T</title></head><body>#{markup}</body></html>"
  5. gamov created this gist Mar 11, 2015.
    22 changes: 22 additions & 0 deletions Markup Validation
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    def assert_valid_markup(markup = @response.body, fragment = false)
    str = if fragment
    "<!doctype html><head><title>T</title></head><body>#{markup}</body></html>"
    else
    markup.to_str # .to_str to remove SafeBuffer stuff
    end
    require 'net/http'
    # http://validator.w3.org/docs/api.html
    response = Net::HTTP.start('validator.w3.org') do |w3c|
    query = 'fragment=' + CGI.escape(str) + '&output=xml'
    w3c.post2('/check', query)
    end
    # puts "Errors Nbr = #{response['X-W3C-Validator-Errors']}"
    # puts response.body result in html (save it to tmp?) then report as message below
    unless response['x-w3c-validator-status'] == 'Valid'
    val_folder = Rails.root.join('tmp').join('validations')
    val_folder.mkdir
    file = val_folder.join("#{Time.now.to_i}.html")
    File.open(file, 'wb+') {|f| f.write(response.body) }
    end
    assert_equal 'Valid', response['x-w3c-validator-status'], "HTML Validation failed, see details here: #{file}"
    end