Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 487
boka Avatar asked Jul 12 '12 18:07

boka


People also ask

What is the difference between validate and validates in rails?

So remember folks, validates is for Rails validators (and custom validator classes ending with Validator if that's what you're into), and validate is for your custom validator methods.

What is an html5 code validator?

An HTML validator is a specialized program or application used to check the validity of HTML markup in a Web page for any syntax and lexical errors.

Why are HTML validators used?

An HTML validator is a quality assurance program used to check Hypertext Markup Language ( HTML ) markup elements for syntax errors. A validator can be a useful tool for an HTML user who receives data electronically from a variety of input sources.


1 Answers

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.

like image 185
ebeland Avatar answered Sep 28 '22 08:09

ebeland