htmlruby-on-railsvalidationlocal

Are there any (local) HTML validators for Ruby on Rails that work?


I've looked around all day yesterday for a working HTML validator that I could use to check the code generated by my rails application. So far, I've tried several different strategies such as RailsTidy, which no longer works as of Rails 1.9, tidy_ffi, which I've had a hard time "require"-ing when running in rails console, and the FireFox's Total Validator, which always gives me the same error regardless of what I'm checking.

My goal is to check my code while not having to upload anything to the internet. It would be most helpful to be able to run tests from the terminal (I'm using RedHat Linux) or to run tests on a running localhost server.

To save myself another day (or possibly more) of frustration, I've brought this question here and I'd like to know if anyone else has successfully worked with a validator for Ruby on Rails.


Solution

  • Try out my gem, html_acceptance. It uses HTML Tidy to do the validation under the hood. I put it out a while ago, but so far it has mostly gone unnoticed. It has been useful to me, and if you report issues/have feature requests I'll happily look at them.

    In the samples, I have a custom RSpec matcher, so if you add that custom matcher, in your integration tests in spec/requests you can do:

    page.should have_valid_html
    

    The idea is you can use it within integration tests, and even if you get minor warnings/failures that you don't care about (TIDY complains about some IE specific hacks, for example), you can go in, accept them, and as long as the validation result is constant, the test will then pass.

    Also, you need to have tidy on the path. So on OS X: port install htmltidy or Ubuntu sudo apt-get install tidy.