Class: Railscheck::Test::HtmlAndCss

Inherits:
Railscheck::TestCase show all
Includes:
W3CValidators
Defined in:
lib/test/tc_html_and_css.rb

Constant Summary collapse

MAX_VALIDATION_ERRORS =

Filter for how many errors to show.

3
MAX_VALIDATION_WARNINGS =

Filter for how many warnings to show.

3

Instance Method Summary collapse

Methods inherited from Railscheck::TestCase

#default_test

Instance Method Details

#test_all_css_validatesObject

Test that static CSS files validates using W3C online service.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/test/tc_html_and_css.rb', line 13

def test_all_css_validates
  @validator = CSSValidator.new
     
  (Dir["#{RAILS_ROOT}/public/**/*.css", "#{RAILS_ROOT}/doc/**/*.css"]-version_control_excludes).each do |fname|
    results = @validator.validate_file(fname)
    
    validation_errors = results.errors.length
    validation_errors_to_show = [results.errors.length, MAX_VALIDATION_ERRORS].min
    
    validation_warnings = results.warnings.length
    validation_warnings_to_show = [results.warnings.length, MAX_VALIDATION_WARNINGS].min
    
    assert_equal 0, results.errors.length, "#{validation_errors} validation error(s) in \"#{fname}\". Showing #{validation_errors_to_show}: "+results.errors[0..validation_errors_to_show-1].join("\n")
    
    if (validation_warnings!=0)
     warn "#{validation_warnings} validation warning(s) in \"#{fname}\". Showing #{validation_warnings_to_show}: "+results.warnings[0..validation_warnings_to_show-1].join("\n")
    end
  end
end

#test_all_html_validatesObject

Test that static HTML files validates using W3C online service.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/test/tc_html_and_css.rb', line 34

def test_all_html_validates
  @validator = MarkupValidator.new
     
  (Dir["#{RAILS_ROOT}/public/**/*.html", "#{RAILS_ROOT}/public/**/*.xhtml", "#{RAILS_ROOT}/doc/**/*.html", "#{RAILS_ROOT}/doc/**/*.xhtml"]-version_control_excludes).each do |fname|
    results = @validator.validate_file(fname)
    
    validation_errors = results.errors.length
    validation_errors_to_show = [results.errors.length, MAX_VALIDATION_ERRORS].min
    
    validation_warnings = results.warnings.length
    validation_warnings_to_show = [results.warnings.length, MAX_VALIDATION_WARNINGS].min
    
    assert_equal 0, results.errors.length, "#{validation_errors} validation error(s) in \"#{fname}\". Showing #{validation_errors_to_show}: "+results.errors[0..validation_errors_to_show-1].join("\n")
    
    if (validation_warnings!=0)
     warn "#{validation_warnings} validation warning(s) in \"#{fname}\". Showing #{validation_warnings_to_show}: "+results.warnings[0..validation_warnings_to_show-1].join("\n")
    end
  end
end