June 23, 2006

Posted by John

Tagged testing and web standards

Older: Streamlined

Newer: Martin Fowler Keynote

Assert Valid Markup

Wow, this is pretty cool. Scott Raymond just posted a test helper that posts to the w3c’s validator and asserts that the response is valid. The helper that should go in test/test_helper.rb is …

def assert_valid_markup(markup=@response.body)
  require 'net/http'
  response = Net::HTTP.start('validator.w3.org') do |w3c|
    query = 'fragment=' + CGI.escape(markup) + '&output=xml'
    w3c.post2('/check', query)
  end
  assert_equal 'Valid', response['x-w3c-validator-status']
end

The example use he provided is …

def test_home
  get :home
  assert_valid_markup
end

For a standards nut like me, this could come in really handy.

0 Comments

Thoughts? Do Tell...


textile enabled, preview above, please be nice
use <pre><code class="ruby"></code></pre> for code blocks

About

Authored by John Nunemaker (Noo-neh-maker), a web developer and programmer who has fallen deeply in love with Ruby. More about John.

Syndication

Feed IconRailsTips Articles - An assortment of howto's and thoughts on Ruby and Rails.

Feed IconRails Quick Tips - Ruby and Rails related links.