Assert Valid Markup
June 23rd, 2006
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.

Sorry, comments are closed for this article to ease the burden of pruning spam. If you have any further comments, just send me an email.