html-proofer 1.6.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/README.md +74 -56
  4. data/Rakefile +4 -6
  5. data/bin/htmlproof +46 -36
  6. data/html-proofer.gemspec +22 -22
  7. data/lib/html/proofer/check_runner/issue.rb +62 -0
  8. data/lib/html/proofer/{check.rb → check_runner.rb} +11 -19
  9. data/lib/html/proofer/checkable.rb +42 -28
  10. data/lib/html/proofer/checks/favicon.rb +6 -6
  11. data/lib/html/proofer/checks/html.rb +11 -12
  12. data/lib/html/proofer/checks/images.rb +11 -11
  13. data/lib/html/proofer/checks/links.rb +30 -28
  14. data/lib/html/proofer/checks/scripts.rb +7 -8
  15. data/lib/html/proofer/log.rb +38 -0
  16. data/lib/html/proofer/url_validator.rb +135 -0
  17. data/lib/html/proofer/utils.rb +24 -0
  18. data/lib/html/proofer/version.rb +1 -1
  19. data/lib/html/proofer.rb +95 -199
  20. data/spec/html/proofer/command_spec.rb +82 -0
  21. data/spec/html/proofer/favicon_spec.rb +20 -20
  22. data/spec/html/proofer/fixtures/images/srcSetCheck.html +7 -0
  23. data/spec/html/proofer/fixtures/images/srcSetIgnorable.html +13 -0
  24. data/spec/html/proofer/fixtures/images/srcSetMissingAlt.html +7 -0
  25. data/spec/html/proofer/fixtures/images/srcSetMissingImage.html +7 -0
  26. data/spec/html/proofer/fixtures/links/erstiebegru/314/210/303/237ung.html +1 -0
  27. data/spec/html/proofer/fixtures/links/erstiebegr/303/274/303/237ung.html +1 -0
  28. data/spec/html/proofer/fixtures/links/file.foo +11 -0
  29. data/spec/html/proofer/fixtures/links/folder/multiples/catalog/file.html +8 -0
  30. data/spec/html/proofer/fixtures/links/folder/multiples/javadoc/file.html +8 -0
  31. data/spec/html/proofer/fixtures/links/nodupe.html +1 -1
  32. data/spec/html/proofer/fixtures/links/redirected_error.html +1 -0
  33. data/spec/html/proofer/fixtures/links/rootLink/rootLink.html +0 -1
  34. data/spec/html/proofer/fixtures/links/urlencoded-href.html +2 -0
  35. data/spec/html/proofer/fixtures/links/utf8Link.html +2 -0
  36. data/spec/html/proofer/fixtures/utils/lang-jp.html +1 -0
  37. data/spec/html/proofer/html_spec.rb +25 -25
  38. data/spec/html/proofer/images_spec.rb +59 -35
  39. data/spec/html/proofer/links_spec.rb +152 -109
  40. data/spec/html/proofer/scripts_spec.rb +17 -17
  41. data/spec/html/proofer/utils_spec.rb +14 -0
  42. data/spec/html/proofer_spec.rb +58 -38
  43. data/spec/spec_helper.rb +13 -6
  44. metadata +39 -7
  45. data/lib/html/proofer/checks.rb +0 -15
  46. data/lib/html/proofer/issue.rb +0 -21
@@ -1,51 +1,51 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- describe "Html test" do
4
- it "ignores an invalid tag by default" do
3
+ describe 'Html test' do
4
+ it 'ignores an invalid tag by default' do
5
5
  html = "#{FIXTURES_DIR}/html/invalid_tag.html"
6
- output = capture_stderr { HTML::Proofer.new(html).run }
7
- expect(output).to eq ""
6
+ proofer = run_proofer(html)
7
+ expect(proofer.failed_tests).to eq []
8
8
  end
9
9
 
10
10
  it "doesn't fail for html5 tags" do
11
11
  html = "#{FIXTURES_DIR}/html/html5_tags.html"
12
- output = capture_stderr { HTML::Proofer.new(html, {:validate_html => true}).run }
13
- expect(output).to eq ""
12
+ proofer = run_proofer(html, { :check_html => true })
13
+ expect(proofer.failed_tests).to eq []
14
14
  end
15
15
 
16
- it "fails for an invalid tag" do
16
+ it 'fails for an invalid tag' do
17
17
  html = "#{FIXTURES_DIR}/html/invalid_tag.html"
18
- output = capture_stderr { HTML::Proofer.new(html, {:validate_html => true}).run }
19
- expect(output).to match /Tag myfancytag invalid/
18
+ proofer = run_proofer(html, { :check_html => true })
19
+ expect(proofer.failed_tests.first).to match(/Tag myfancytag invalid/)
20
20
  end
21
21
 
22
- it "fails for an unmatched end tag" do
22
+ it 'fails for an unmatched end tag' do
23
23
  html = "#{FIXTURES_DIR}/html/unmatched_end_tag.html"
24
- output = capture_stderr { HTML::Proofer.new(html, {:validate_html => true}).run }
25
- expect(output).to match /Unexpected end tag : div/
24
+ proofer = run_proofer(html, { :check_html => true })
25
+ expect(proofer.failed_tests.first).to match(/Unexpected end tag : div/)
26
26
  end
27
27
 
28
- it "fails for an unescaped ampersand in attribute" do
28
+ it 'fails for an unescaped ampersand in attribute' do
29
29
  html = "#{FIXTURES_DIR}/html/unescaped_ampersand_in_attribute.html"
30
- output = capture_stderr { HTML::Proofer.new(html, {:validate_html => true}).run }
31
- expect(output).to match /htmlParseEntityRef: expecting ';'/
30
+ proofer = run_proofer(html, { :check_html => true })
31
+ expect(proofer.failed_tests.first).to match(/htmlParseEntityRef: expecting ';'/)
32
32
  end
33
33
 
34
- it "fails for mismatch between opening and ending tag" do
34
+ it 'fails for mismatch between opening and ending tag' do
35
35
  html = "#{FIXTURES_DIR}/html/opening_and_ending_tag_mismatch.html"
36
- output = capture_stderr { HTML::Proofer.new(html, {:validate_html => true}).run }
37
- expect(output).to match /Opening and ending tag mismatch: p and strong/
36
+ proofer = run_proofer(html, { :check_html => true })
37
+ expect(proofer.failed_tests.first).to match(/Opening and ending tag mismatch: p and strong/)
38
38
  end
39
39
 
40
- it "fails for div inside head" do
40
+ it 'fails for div inside head' do
41
41
  html = "#{FIXTURES_DIR}/html/div_inside_head.html"
42
- output = capture_stderr { HTML::Proofer.new(html, {:validate_html => true}).run }
43
- expect(output).to match /Unexpected end tag : head/
42
+ proofer = run_proofer(html, { :check_html => true })
43
+ expect(proofer.failed_tests.first).to match(/Unexpected end tag : head/)
44
44
  end
45
45
 
46
- it "fails for missing closing quotation mark in href" do
46
+ it 'fails for missing closing quotation mark in href' do
47
47
  html = "#{FIXTURES_DIR}/html/missing_closing_quotes.html"
48
- output = capture_stderr { HTML::Proofer.new(html, {:validate_html => true}).run }
49
- expect(output).to match /Couldn't find end of Start Tag a/
48
+ proofer = run_proofer(html, { :check_html => true })
49
+ expect(proofer.failed_tests.to_s).to match(/Couldn't find end of Start Tag a/)
50
50
  end
51
51
  end
@@ -1,98 +1,122 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- describe "Images test" do
4
- it "passes for existing external images" do
3
+ describe 'Images test' do
4
+ it 'passes for existing external images' do
5
5
  externalImageFilepath = "#{FIXTURES_DIR}/images/existingImageExternal.html"
6
- proofer = make_proofer(externalImageFilepath)
6
+ proofer = run_proofer(externalImageFilepath)
7
7
  expect(proofer.failed_tests).to eq []
8
8
  end
9
9
 
10
- it "fails for image without alt attribute" do
10
+ it 'fails for image without alt attribute' do
11
11
  missingAltFilepath = "#{FIXTURES_DIR}/images/missingImageAlt.html"
12
- proofer = make_proofer(missingAltFilepath)
13
- expect(proofer.failed_tests.first).to match /gpl.png does not have an alt attribute/
12
+ proofer = run_proofer(missingAltFilepath)
13
+ expect(proofer.failed_tests.first).to match(/gpl.png does not have an alt attribute/)
14
14
  end
15
15
 
16
- it "fails for image with an empty alt attribute" do
16
+ it 'fails for image with an empty alt attribute' do
17
17
  missingAltFilepath = "#{FIXTURES_DIR}/images/missingImageAltText.html"
18
- proofer = make_proofer(missingAltFilepath)
19
- expect(proofer.failed_tests.first).to match /gpl.png does not have an alt attribute/
18
+ proofer = run_proofer(missingAltFilepath)
19
+ expect(proofer.failed_tests.first).to match(/gpl.png does not have an alt attribute/)
20
20
  end
21
21
 
22
- it "fails for missing external images" do
22
+ it 'fails for missing external images' do
23
23
  externalImageFilepath = "#{FIXTURES_DIR}/images/missingImageExternal.html"
24
- proofer = make_proofer(externalImageFilepath)
25
- expect(proofer.failed_tests.first).to match /External link http:\/\/www.whatthehell\/? failed: 0 Couldn't resolve host/
24
+ proofer = run_proofer(externalImageFilepath)
25
+ expect(proofer.failed_tests.first).to match(/failed: 0 Couldn't resolve host/)
26
26
  end
27
27
 
28
- it "fails for missing internal images" do
28
+ it 'fails for missing internal images' do
29
29
  internalImageFilepath = "#{FIXTURES_DIR}/images/missingImageInternal.html"
30
- proofer = make_proofer(internalImageFilepath)
31
- expect(proofer.failed_tests.first).to match /doesnotexist.png does not exist/
30
+ proofer = run_proofer(internalImageFilepath)
31
+ expect(proofer.failed_tests.first).to match(/doesnotexist.png does not exist/)
32
32
  end
33
33
 
34
- it "fails for image with no src" do
34
+ it 'fails for image with no src' do
35
35
  imageSrcFilepath = "#{FIXTURES_DIR}/images/missingImageSrc.html"
36
- proofer = make_proofer(imageSrcFilepath)
37
- expect(proofer.failed_tests.first).to match /image has no src attribute/
36
+ proofer = run_proofer(imageSrcFilepath)
37
+ expect(proofer.failed_tests.first).to match(/image has no src or srcset attribute/)
38
38
  end
39
39
 
40
- it "fails for image with default mac filename" do
40
+ it 'fails for image with default mac filename' do
41
41
  terribleImageName = "#{FIXTURES_DIR}/images/terribleImageName.html"
42
- proofer = make_proofer(terribleImageName)
43
- expect(proofer.failed_tests.first).to match /image has a terrible filename/
42
+ proofer = run_proofer(terribleImageName)
43
+ expect(proofer.failed_tests.first).to match(/image has a terrible filename/)
44
44
  end
45
45
 
46
46
  it 'ignores images marked as ignore data-proofer-ignore' do
47
47
  ignorableImages = "#{FIXTURES_DIR}/images/ignorableImages.html"
48
- proofer = make_proofer(ignorableImages)
48
+ proofer = run_proofer(ignorableImages)
49
49
  expect(proofer.failed_tests).to eq []
50
50
  end
51
51
 
52
52
  it 'properly checks relative images' do
53
53
  relativeImages = "#{FIXTURES_DIR}/images/rootRelativeImages.html"
54
- proofer = make_proofer(relativeImages)
54
+ proofer = run_proofer(relativeImages)
55
55
  expect(proofer.failed_tests).to eq []
56
56
 
57
57
  relativeImages = "#{FIXTURES_DIR}/resources/books/nestedRelativeImages.html"
58
- proofer = make_proofer(relativeImages)
58
+ proofer = run_proofer(relativeImages)
59
59
  expect(proofer.failed_tests).to eq []
60
60
  end
61
61
 
62
62
  it 'properly ignores data URI images' do
63
63
  dataURIImage = "#{FIXTURES_DIR}/images/workingDataURIImage.html"
64
- proofer = make_proofer(dataURIImage)
64
+ proofer = run_proofer(dataURIImage)
65
65
  expect(proofer.failed_tests).to eq []
66
66
  end
67
67
 
68
- it "works for valid images missing the protocol" do
68
+ it 'works for valid images missing the protocol' do
69
69
  missingProtocolLink = "#{FIXTURES_DIR}/images/image_missing_protocol_valid.html"
70
- proofer = make_proofer(missingProtocolLink)
70
+ proofer = run_proofer(missingProtocolLink)
71
71
  expect(proofer.failed_tests).to eq []
72
72
  end
73
73
 
74
- it "fails for invalid images missing the protocol" do
74
+ it 'fails for invalid images missing the protocol' do
75
75
  missingProtocolLink = "#{FIXTURES_DIR}/images/image_missing_protocol_invalid.html"
76
- proofer = make_proofer(missingProtocolLink)
77
- expect(proofer.failed_tests.first).to match /404 No error/
76
+ proofer = run_proofer(missingProtocolLink)
77
+ expect(proofer.failed_tests.first).to match(/404 No error/)
78
78
  end
79
79
 
80
80
  it 'properly checks relative links' do
81
81
  relativeLinks = "#{FIXTURES_DIR}/images/relativeToSelf.html"
82
- proofer = make_proofer(relativeLinks)
82
+ proofer = run_proofer(relativeLinks)
83
83
  expect(proofer.failed_tests).to eq []
84
84
  end
85
85
 
86
86
  it 'properly ignores missing alt tags when asked' do
87
87
  ignorableLinks = "#{FIXTURES_DIR}/images/ignorableAltViaOptions.html"
88
- proofer = make_proofer(ignorableLinks, {:alt_ignore => [/wikimedia/, "gpl.png"]})
88
+ proofer = run_proofer(ignorableLinks, {:alt_ignore => [/wikimedia/, "gpl.png"]})
89
89
  expect(proofer.failed_tests).to eq []
90
90
  end
91
91
 
92
92
  it 'properly ignores missing alt tags, but not all URLs, when asked' do
93
93
  ignorableLinks = "#{FIXTURES_DIR}/images/ignoreAltButNotLink.html"
94
- proofer = make_proofer(ignorableLinks, {:alt_ignore => [/.*/]})
95
- expect(proofer.failed_tests.first).to match /Couldn't resolve host name/
94
+ proofer = run_proofer(ignorableLinks, {:alt_ignore => [/.*/]})
95
+ expect(proofer.failed_tests.first).to match(/Couldn't resolve host name/)
96
96
  expect(proofer.failed_tests.first).to_not match /does not have an alt attribute/
97
97
  end
98
+
99
+ it 'works for images with a srcset' do
100
+ srcSetCheck = "#{FIXTURES_DIR}/images/srcSetCheck.html"
101
+ proofer = run_proofer(srcSetCheck)
102
+ expect(proofer.failed_tests).to eq []
103
+ end
104
+
105
+ it 'fails for images with a srcset but missing alt' do
106
+ srcSetMissingAlt = "#{FIXTURES_DIR}/images/srcSetMissingAlt.html"
107
+ proofer = run_proofer(srcSetMissingAlt)
108
+ expect(proofer.failed_tests.first).to match(/image gpl.png does not have an alt attribute/)
109
+ end
110
+
111
+ it 'fails for images with an alt but missing src or srcset' do
112
+ srcSetMissingAlt = "#{FIXTURES_DIR}/images/srcSetMissingImage.html"
113
+ proofer = run_proofer(srcSetMissingAlt)
114
+ expect(proofer.failed_tests.first).to match(/internal image notreal.png does not exist/)
115
+ end
116
+
117
+ it 'properly ignores missing alt tags when asked for srcset' do
118
+ ignorableLinks = "#{FIXTURES_DIR}/images/srcSetIgnorable.html"
119
+ proofer = run_proofer(ignorableLinks, {:alt_ignore => [/wikimedia/, "gpl.png"]})
120
+ expect(proofer.failed_tests).to eq []
121
+ end
98
122
  end