www.SmarteGuru.com
  Home | Blogs | Recipe | Find a Friend | Discussion Board | Resources | Developers Area | Articles | Health |  Login | Register Now 

Rails Plugin to Validate (X)HTML and CSS

Something I have wanted to do for a long time is automatically validate content such as (X)HTML, CSS, atom feeds etc that is generated by the web application. A while ago I put together the assert-valid-asset plugin that allowed you to assert (in functional tests) that the content generated is valid. However you still had to explicitly call the assert.

So recently I enhanced the plugin so that it can automatically validate generated content when configured to do so. To configure auto validation you need to set a class variable in Test::Unit::TestCase via code such as;


class Test::Unit::TestCase
self.auto_validate = true
end

Then anytime content is generated in tests (such as via get and post methods) it will check the mime type of the content. If the content has a mime type of ‘text/html’ or ‘text/xhtml’ it will pass it to the ‘assert_valid_markup’ method. If the content is ‘text/css’ then it will be validated by the ‘assert_valid_css’ method.

Of course you may have tests that generate invalid (X)HTML or CSS (to work with specific unnamed browsers) and you may want to exclude these tests from the automatic content validation. This can be done by adding the test symbol to the exclude list or alternatively by adding the desired test symbols to an include list. Both of the following examples have identical behavior;
Example 1:


class FooControllerTest < Test::Unit::TestCase
...
self.auto_validate_excludes = [:test_foo,:test_bar]

def test_foo; ... ; end
def test_bar; ... ; end
def test_baz; ... ; end
end

Example 2:

class FooControllerTest < Test::Unit::TestCase
...
self.auto_validate_includes = [:test_baz]

def test_foo; ... ; end
def test_bar; ... ; end
def test_baz; ... ; end
end

You can grab it from subversion at;

svn checkout http://assert-valid-asset.googlecode.com/svn/trunk/

The original article describing the plugin is here .

Social Bookmarks: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit
  • Webnews
  • Y!GG
  • Google Bookmarks
  • SEOigg
  • YahooMyWeb
  • Live-MSN
  • DZone
  • Facebook
  • Technorati
  • Ask
  • Furl
  • Spurl
  • Webbrille

Related Posts

Tags: , , ,

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Viewed: 384 views

Leave a Reply

Twitter Users!
Enter your personal information in the form or sign in with your Twitter account by clicking the button below.

Home - About Us - Help - Terms and Conditions - Site Map - Link to Us - Resources - Contact Us
Google Rank Calculator | Suggest developer resource | Suggest Article
All rights reserved © 2007 SmarteGuru.com.