RoR plugin/gem for html validation [closed]
-
05-07-2019 - |
Question
I am wondering if there is such a plugin or gem for Ruby on Rails that includes HTML validation (SGML or Tidy) in a testing cycle.
I am aware only about this plugin. Looking for alternatives...
Solution
I use be_valid_asset
with rspec and cucumber. It uses the public W3C validator. It does not have the link checking that html_test
has.
I use it in these two steps in cucumber's webrat_steps.rb:
Given /^(?:|I )am on (.+)$/ do |page_name|
visit path_to(page_name)
response.should be_valid_xhtml if ENV['VALIDATE_HTML']
end
When /^(?:|I )go to (.+)$/ do |page_name|
visit path_to(page_name)
response.should be_valid_xhtml if ENV['VALIDATE_HTML']
end
Then I can run rake VALIDATE_HTML=1 cucumber
to validate all pages visited by my cucumber feature files.
OTHER TIPS
Here's a Rack-based validator that can be used live: http://coderack.org/users/nerdEd/entries/95-rackvalidate
I am working on an all-in-one HTML/CSS validation gem for Ruby On Rails apps. It's name is Headhunter.
From the docs:
Headhunter is an HTML and CSS validation tool that injects itself into your Rails feature tests and automagically checks all your generated HTML and CSS for validity.
In addition, it also looks out for unused (and therefore superfluous) CSS selectors.
All you have to do is add gem 'headhunter'
to your Gemfile in test environment:
group :test do
gem 'headhunter'
end
The rest is all done automagically for you, and you'll get a statistic for your application's validness at the end of your tests, like this:
Validated 42 HTML pages.
41 pages are valid.
1 page is invalid.
Open .validation/results.html to view full results.
Validated 1 stylesheets.
1 stylesheet is invalid.
application.css:
- Invalid css: line 1: Property bla doesn't exist
Found 23 CSS selectors.
20 selectors are in use.
3 selectors are not in use: a img, #flash.failure, input[type='file']