Assert Valid Asset plugin

Plugin details

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.

Websitehttp://www.realityforge.org/articles/2006/03/15/rails-plugin-to-validate-x-html-and-css Repositoryhttp://www.realityforge.org/svn/public/code/assert-valid-asset/trunk/ Author Scott Raymond Tags validation LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://www.realityforge.org/svn/public/code/assert-valid-asset/trunk/

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 "Hello, world."
  end
end

# For the ultimate in convenience, use the class-level
# method to validate a number of actions in one line. 

class FooControllerTest < Test::Unit::TestCase
  assert_valid_markup :bar, :baz, :qux
end


HowTo Validate CSS

# Pass a string parameter to the assertion to validate 
# a css fragment. For example:

class FooControllerTest < Test::Unit::TestCase
  def test_bar_css
    filename = "#{RAILS_ROOT}/public/stylesheets/bar.css"
    assert_valid_css(File.open(filename ,'rb').read)
  end
end

# For the ultimate in convenience, use the class-level
# method to validate a bunch of css files in one line.
# Assumes that the CSS files are relative to 
# $RAILS_ROOT/public/stylesheets/ and end with '.css'. 
# The following example validates 
#  $RAILS_ROOT/public/stylesheets/layout.css, 
#  $RAILS_ROOT/public/stylesheets/standard.css and 
#  $RAILS_ROOT/public/stylesheets/theme.css

class FooControllerTest < Test::Unit::TestCase
  assert_valid_css_files 'layout', 'standard', 'theme'
end

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, about 1 year ago