Automatic Markup Validation

2,992 views

Published on

A short presentation explaining how to automatically validate all markup (RSS and HTML right now) generated by the Ruby on Rails testing infrastructure.

More information at the <a href="http://blog.spotstory.com">Spotstory blog</a> post <a href="http://blog.spotstory.com/2007/04/09/automatic-markup-validation/">about this subject</a>.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,992
On SlideShare
0
From Embeds
0
Number of Embeds
48
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Automatic Markup Validation

  1. 1. Automatic Markup Validation Aron Atkins aron@spotstory.com 617.335.2871 Boston Ruby Group April 10, 2007 1
  2. 2. What’s the story? • Mechanical validation of many formats • XHTML/HTML • CSS • RSS • etc. • Checking for legal markup reduces risk • Dangling div, td, etc. 2
  3. 3. Available Plugins • assert_valid_markup • Uses W3 Validator to check XHTML/HTML • A local server can improve performance • assert_valid_asset • Built upon assert_valid_markup • Adds CSS validation using W3 • RSS parser built into Ruby • Future could use public validators (ATOM, etc) • Other XML formats? DTD? 3
  4. 4. Give a little helper ... • Install assert_valid_markup • Install the test_validation_helper.rb • http://blog.spotstory.com/2007/04/09/ automatic-markup-validation • test/test_helper.rb require File.expand_path( File.dirname(__FILE__) + "/test/test_validation_helper.rb") 4
  5. 5. Don’t be shy ... • test/test_validation_helper.rb alias :non_validating_get :get alias :non_validating_post :post def get(path, parameters=nil, headers={}, flash=nil) non_validating_get path, parameters, headers, flash check_markup end def post(path,parameters=nil,headers={}, flash=nil) non_validating_post path, parameters, headers, flash check_markup end 5
  6. 6. Validation Dispatch • test/test_validation_helper.rb def check_markup return if ! ENV['NO_VALIDATION'].nil? if @response.redirect? elsif javascript_response? || json_response? || kml_response? elsif xml_response? assert_rss_valid print "+" else assert_html_valid print "+" end end 6
  7. 7. HTML Validation • test/test_validation_helper.rb def assert_html_valid begin assert_valid_markup rescue print " VALIDATION FAILED: HEADERS: " @response.headers.each { |hdr,val| print " #{hdr}: #{val} " } print "BODY: " print @response.body + " " raise # re-raise after showing the failing body. end end 7
  8. 8. RSS Validation • Using the Ruby builtin module def assert_rss_valid assert_not_nil @response.body # Ignore unknown elements because the built-in Ruby RSS # support doesn't fully understand extensions. RSS::Parser.parse(@response.body, true, true) # Make sure all the objects have been processed. assert_no_match /cannot be processed/, @response.body end 8
  9. 9. Get the code • Posted on the Spotstory Blog: http://blog.spotstory.com/2007/04/09/ automatic-markup-validation/ • • Email: aron@spotstory.com 9

×