= assert_valid_asset plugin for Rails assert_valid_asset is a plugin to validate your (X)HTML and CSS using the W3C Validator web service (http://validator.w3.org/) and the W3C CSS Validation Service (http://jigsaw.w3.org/css-validator) as part of your functional or unit tests. The css and html fragments are cached in $RAILS_ROOT/tmp/test/assets as are the results from the web service. This means that your tests will not be slowed down unless the output has changed. The code started life as a few modifications to Scott Raymond's assert_valid_markup (http://redgreenblu.com/svn/projects/assert_valid_markup/) and evolved to cache fragments and results in $RAILS_ROOT/tmp/test/assets rather than the system temp directory. Then the ability to validate CSS files was added. I also added the ability to skip checks if the "NONET" environment variable is set to "true". A more recent version made it possible to display the content with the line numbers by adding a line such as "self.display_invalid_content = true" into test_helper.rb in the Test::Unit::TestCase class. The ability to automatically validate content generated as a result of a action can be enabled by adding the line "self.auto_validate = true" into test_helper.rb in the Test::Unit::TestCase class. This will generate content according to the mime type of content. (x)html will be passed to assert_valid_markup and css will be passed to assert_valid_css. You can also exclude specific tests by putting them into an an auto_validate_excludes or instead can choose to only include tests in list auto_validate_includes. i.e. The following will automatically validate content generated in the test_foo and test_bar tests. class Test::Unit::TestCase self.auto_validate = true end class FooControllerTest < Test::Unit::TestCase self.auto_validate_excludes = [:test_baz] def test_foo; ... ; end def test_bar; ... ; end def test_baz; ... ; end end i.e. The following will automatically validate content generated in the test_baz test. class Test::Unit::TestCase self.auto_validate = true end class FooControllerTest < Test::Unit::TestCase self.auto_validate_includes = [:test_baz] def test_foo; ... ; end def test_bar; ... ; end def test_baz; ... ; end end == HowTo Validate (X)HTML # Calling the assertion with no parameters validates whatever is in @request.body, # which is automatically set by the existing get/post/etc helpers. For example: class FooControllerTest < Test::Unit::TestCase def test_bar_markup get :bar assert_valid_markup end end # Add a string parameter to the assertion to validate any random fragment. For example: class FooControllerTest < Test::Unit::TestCase def test_bar_markup assert_valid_markup "