railint.rb

Path: lib/railint.rb
Last Update: Fri Sep 07 23:22:03 -0400 2007

RaiLint: Lint for Rails Output

Rails does a great job of providing an integrated test framework for its various components. However, Rails programs ultimately produce output (HTML, CSS, JS) for consumption by other programs. In order to ensure maximum compatibility, every effort should be made to ensure Rails program output is valid output for whatever type it may be.

The original lint program validated the syntax and structure of source code written in the C language. Since then, numerous lint programs have arisen to validate the correctness of all types of files. The RaiLint plugin for Rails aims to be a "Lint for Rails Output". Under the ‘test’ environment (where RAILS_ENV == ‘test’) it validates Rails program output using a number of freely available tools:

The W3C CSS Validator (written in Java):for validating CSS output
The OpenSP/OpenJade ‘onsgmls’ utility:for validating (X)HTML output
JavaScript Lint by Matthias Miller:for validating Javascript output

These three tools are required in order for RaiLint to work properly. Although these tools are freely available, configuring them all to work together to validate Rails app output can be a chore. RaiLint takes care of 90% of the work, by tying all the apps together and providing default configuration settings (which can be overridden).

In order for RaiLint to function, the following must be on the path:

java:version 1.4 or later should work
onsgmls:from the OpenJade package
jsl:the JavaScript Lint executable

Getting Started

To get started using RaiLint, install the plugin into your $RAILS_HOME/plugins directory—from $RAILS_HOME, run

script/plugin install http://railint.rubyforge.org/svn/tags/railint_current

and run rake —tasks within $RAILS_HOME/plugins/railint to see the available tasks. RaiLint includes a number of rake tasks for determining if the environment is setup correctly. Run

rake test_config

to check to see that all required dependencies are correctly configured.

Once rake test_config runs successfully, try running

rake examples:failing_js

or any of the other rake examples:failing* tasks to see examples of failed CSS/JS/(X)HTML validation in RaiLint.

After RaiLint is successfully configured, run rake —tasks in $RAILS_HOME and take note of the additional tasks (prefixed with railint or test:railint) added by RaiLint.

WATiR Support

RaiLint supports running Rails in WeBrick in order to automate WATiR tests as part of a test suite. See the watir:example for code which requires the RaiLint test_suite_extension file to startup and shutdown WeBrick as part of the test suite.

Platform Notes

RaiLint has been developed using MacOS X (10.4) and various Linux distributions. It has been developed and tested using Rails 1.2.3 under Ruby 1.8.6.

RaiLint uses a number of process-forking Ruby API which most likely do not work under Windows. RaiLint has not been tested against non-UNIX-like operating systems and support for such is not currently planned.

Copyright: (c) 2007 by Dane G. Avilla

Version: 0.1.0

Licence: Ruby‘s license

Thanks to the Rails community, Matthias Miller, the W3C, and the OpenJade team.

[Validate]