• Like
  • Save
Automatic Markup Validation
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Automatic Markup Validation

  • 2,778 views
Published

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

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

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,778
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Automatic Markup Validation Aron Atkins aron@spotstory.com 617.335.2871 Boston Ruby Group April 10, 2007 1
  • 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. 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. 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. 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. 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. 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. 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. Get the code • Posted on the Spotstory Blog: http://blog.spotstory.com/2007/04/09/ automatic-markup-validation/ • • Email: aron@spotstory.com 9