HTML_TEST because RailsTidy drives me crazy

The functionality of RailsTidy is great, but it can drive you crazy, all the senceless warnings, wich as far as i looked cannot be turned off. Aditionally it cannot validate all requests, only the last one (if you followed my previouse post).

html_test features:

  • validating ALL requests
  • validating with up to 3 different validators (ok.. 1 is enought for me)
  • killing senceless warnings
  • checking all URLs (returnes :success or :redirect?)

Grab here: ruby script/plugin install http://htmltest.googlecode.com/svn/trunk/html_test

And put this into your test_helper.rb:

#--------html_test plugin
#validate every request
ApplicationController.validate_all = true
ApplicationController.validators = [:tidy]

#ignore common warnings
Html::Test::Validator.tidy_ignore_list = [
  /<table> lacks "summary" attribute/,
  /trimming empty <fieldset>/,#erros_on missing -> empty fieldset
  /line 1.*Warning: inserting missing 'title' element/,#redirect html has no title....
  /Warning: replacing invalid character code 130/, #€ has a very bad character
]

#check urls
ApplicationController.check_urls = true
ApplicationController.check_redirects = true

If you always see an extra line like 0 tests, 0 assertions, 0 failures, 0 errors, go to vendor/plugins/html_test/lib/html_test.rb and move the first 3 reuire lines into the if block

Install RailsTidy Plugin by Script

I try to keep some script to do everything, just in case i get to lazy to do it again by hand, which is … always 🙂

This will install RailsTidy from your Rails directory:
(Ubuntu 7.10) change the paths according to your system

sudo apt-get install tidy
sudo gem install tidy

wget http://www.cosinux.org/~dam/projects/rails-tidy/rails_tidy-0.2/tidy.patch
sudo patch /var/lib/gems/1.8/gems/tidy-1.1.2/lib/tidy/tidybuf.rb < tidy.patch
rm tidy.patch

#script/plugin/install fails with strange warnings and does not install anything...
cd vendor/plugins/
wget http://www.cosinux.org/~dam/projects/rails-tidy/rails_tidy-0.2.tar.bz2
tar -xf rails_tidy-0.2.tar.bz2
rm rails_tidy-0.2.tar.bz2
 
 
 

In case you see something like “tidybuf.rb:39: [BUG] Segmentation fault” downgrade to the last stable version:
apt-get install libtidy-0.99.0/20051018-1 (Ubuntu 8.0.4)

now, inside test_helper.rb you can put this:

class Test::Unit::TestCase
  def teardown
    assert_tidy if @request
  end
end

happy nagging 🙂

PS:
If this is still not enought validating fun for you, you can go a step further with html_test (requires RailsTidy) a project that combines html validation with url checking(do all my links return :success or :redirect?)(Project).