You can build XHTML and CSS validation right into your Ruby on Rails Rspec tests - thanks to a plugin called be_valid_asset.
Combine this with autotest and voila - you can be alerted the moment you change something in the view code that breaks your site’s valid markup.
Take this one step further and add your tests into your Capistrano deployment script - and you literally cannot deploy your site when it is in a state that is not standards-compliant.
Get started by installing the be_valid_asset gem (or plugin), and inserting the following line into your Rspec spec_helper.rb file:
config.include BeValidAsset
Then you can use be_valid assertions within your view tests in the following way:
describe "/index.html" do
it "should be valid XHTML" do
render 'home/index', :layout => true
response.should be_valid_xhtml
end
end
You can test your CSS the following way:
it "should be valid CSS" do css = File.read(File.join(RAILS_ROOT, %w(public stylesheets main.css))) css.should be_valid_css end
I would like to find a way expand on this solution and be able to automatically run all CSS includes of a particular view through the checker, instead of having to manually specify each one.
I am also aware that there is another plugin that performs a similar function called assert_valid_asset - it might be more suited to those of you who use Test::Unit.

