Every repository with this icon (
Every repository with this icon (
tree 895a1b6db747414058a36a0332d014f366949850
parent 699c30418acce6b3cb59d53e41004ae474ebde87
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | ||
| |
README.rdoc | ||
| |
Rakefile | ||
| |
assert_valid_content.gemspec | ||
| |
lib/ | ||
| |
test/ |
assert_valid_content
assert_valid_content is a RubyGem which validates a variety content types (e.g. (X)HTML, CSS, XML) as part of your unit or functional tests. It is inspired by assert_valid_markup and assert_valid_assert with the following goals:
- Allow for offline use (i.e. not reliant on web services)
- Validate a wide variety of content types: HTML, JS, JPEG, PDF, MP3, ad infinitum
- Packaged as a RubyGem, instead of a Rails plugin
- Provide for specification of more-stringent validation checks (e.g. image properties)
Validation Modules
Currently supported:
Planned support:
Usage
Validation is performed primary through dynamic assertion functions, defined in AssertValidContent::Assertions (and automatically included into Test::Unit::TestCase, if it exists). The assertions are of the form:
assert_valid_TYPE( content )
where TYPE is a MIME type name (e.g. "html", "css", etc.), and content is a String, Pathname, or IO object, or any combination in an Array. If no content is specified, and the caller is a Rails functional test, the response body is used.
There are also a set of basic assertions:
assert_valid_content( type, content ) valid_content?( type, content ) # yields validator on invalid content
where type is a MIME type constant (e.g. "Mime::HTML").
Examples
require 'rubygems'
require 'assert_valid_content'
class ContentTest < Test::Unit::TestCase
# simple test
def test_html
html = "<html>...</html>"
# these are all equivalent
assert_valid_html html
assert_valid_html StringIO.new(html)
assert_valid_content Mime::HTML, html
assert valid_content?(Mime::HTML, html)
end
# Rails controller test
def test_index
get :index
assert_response :success
assert_valid_html
end
# static content test
assert_valid_css Dir.glob("#{RAILS_ROOT}/public/stylesheets/*.css")
end
| Author: | Steve Sloan (steve@finagle.org) |
| Website: | github.com/CodeMonkeySteve/assert_valid_content |
| Copyright: | Copyright © 2009 Steve Sloan |
| License: | MIT |








