html-proofer 2.3.0 → 3.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 (171) hide show
  1. checksums.yaml +4 -4
  2. data/bin/htmlproofer +85 -0
  3. data/lib/html-proofer/cache.rb +153 -0
  4. data/lib/html-proofer/check/favicon.rb +15 -0
  5. data/lib/html-proofer/check/html.rb +21 -0
  6. data/lib/html-proofer/check/images.rb +47 -0
  7. data/lib/html-proofer/check/links.rb +120 -0
  8. data/lib/html-proofer/check/scripts.rb +28 -0
  9. data/lib/html-proofer/check.rb +63 -0
  10. data/lib/html-proofer/configuration.rb +56 -0
  11. data/lib/html-proofer/element.rb +165 -0
  12. data/lib/{html/proofer/check_runner → html-proofer}/issue.rb +8 -10
  13. data/lib/html-proofer/log.rb +49 -0
  14. data/lib/html-proofer/runner.rb +160 -0
  15. data/lib/html-proofer/url_validator.rb +218 -0
  16. data/lib/html-proofer/utils.rb +40 -0
  17. data/lib/html-proofer/version.rb +3 -0
  18. data/lib/html-proofer.rb +47 -0
  19. metadata +64 -289
  20. data/.gitignore +0 -26
  21. data/.travis.yml +0 -12
  22. data/Gemfile +0 -3
  23. data/LICENSE.txt +0 -22
  24. data/README.md +0 -265
  25. data/Rakefile +0 -21
  26. data/bin/htmlproof +0 -71
  27. data/html-proofer.gemspec +0 -31
  28. data/lib/html/proofer/check_runner.rb +0 -62
  29. data/lib/html/proofer/checkable.rb +0 -164
  30. data/lib/html/proofer/checks/favicon.rb +0 -21
  31. data/lib/html/proofer/checks/html.rb +0 -40
  32. data/lib/html/proofer/checks/images.rb +0 -57
  33. data/lib/html/proofer/checks/links.rb +0 -107
  34. data/lib/html/proofer/checks/scripts.rb +0 -39
  35. data/lib/html/proofer/log.rb +0 -38
  36. data/lib/html/proofer/url_validator.rb +0 -135
  37. data/lib/html/proofer/utils.rb +0 -24
  38. data/lib/html/proofer/version.rb +0 -6
  39. data/lib/html/proofer.rb +0 -189
  40. data/script/bootstrap +0 -5
  41. data/spec/html/proofer/checkable_spec.rb +0 -47
  42. data/spec/html/proofer/command_spec.rb +0 -88
  43. data/spec/html/proofer/favicon_spec.rb +0 -47
  44. data/spec/html/proofer/fixtures/favicon/favicon_absent.html +0 -4
  45. data/spec/html/proofer/fixtures/favicon/favicon_absent_apple.html +0 -7
  46. data/spec/html/proofer/fixtures/favicon/favicon_broken.html +0 -7
  47. data/spec/html/proofer/fixtures/favicon/favicon_broken_but_ignored.html +0 -7
  48. data/spec/html/proofer/fixtures/favicon/favicon_present.html +0 -7
  49. data/spec/html/proofer/fixtures/favicon/favicon_present_shortcut.html +0 -7
  50. data/spec/html/proofer/fixtures/html/div_inside_head.html +0 -6
  51. data/spec/html/proofer/fixtures/html/html5_tags.html +0 -9
  52. data/spec/html/proofer/fixtures/html/invalid_tag.html +0 -3
  53. data/spec/html/proofer/fixtures/html/missing_closing_quotes.html +0 -5
  54. data/spec/html/proofer/fixtures/html/opening_and_ending_tag_mismatch.html +0 -7
  55. data/spec/html/proofer/fixtures/html/svg_elements.html +0 -729
  56. data/spec/html/proofer/fixtures/html/unescaped_ampersand_in_attribute.html +0 -4
  57. data/spec/html/proofer/fixtures/html/unmatched_end_tag.html +0 -5
  58. data/spec/html/proofer/fixtures/images/emptyImageAltText.html +0 -10
  59. data/spec/html/proofer/fixtures/images/existingImageExternal.html +0 -9
  60. data/spec/html/proofer/fixtures/images/gpl.png +0 -0
  61. data/spec/html/proofer/fixtures/images/ignorableAltViaOptions.html +0 -13
  62. data/spec/html/proofer/fixtures/images/ignorableImages.html +0 -10
  63. data/spec/html/proofer/fixtures/images/ignoreAltButNotLink.html +0 -13
  64. data/spec/html/proofer/fixtures/images/image_missing_protocol_invalid.html +0 -9
  65. data/spec/html/proofer/fixtures/images/image_missing_protocol_valid.html +0 -9
  66. data/spec/html/proofer/fixtures/images/missingImageAlt.html +0 -9
  67. data/spec/html/proofer/fixtures/images/missingImageAltText.html +0 -9
  68. data/spec/html/proofer/fixtures/images/missingImageExternal.html +0 -9
  69. data/spec/html/proofer/fixtures/images/missingImageInternal.html +0 -9
  70. data/spec/html/proofer/fixtures/images/missingImageSrc.html +0 -9
  71. data/spec/html/proofer/fixtures/images/relativeToSelf.html +0 -2
  72. data/spec/html/proofer/fixtures/images/rootRelativeImages.html +0 -2
  73. data/spec/html/proofer/fixtures/images/srcSetCheck.html +0 -7
  74. data/spec/html/proofer/fixtures/images/srcSetIgnorable.html +0 -13
  75. data/spec/html/proofer/fixtures/images/srcSetMissingAlt.html +0 -7
  76. data/spec/html/proofer/fixtures/images/srcSetMissingImage.html +0 -7
  77. data/spec/html/proofer/fixtures/images/terribleImageName.html +0 -9
  78. data/spec/html/proofer/fixtures/images/workingDataURIImage.html +0 -3
  79. data/spec/html/proofer/fixtures/links/_site/folder.html/index.html +0 -1
  80. data/spec/html/proofer/fixtures/links/anchors_in_pre.html +0 -12
  81. data/spec/html/proofer/fixtures/links/attributeWithDash.html +0 -8
  82. data/spec/html/proofer/fixtures/links/blank_mailto_link.html +0 -9
  83. data/spec/html/proofer/fixtures/links/blank_tel_link.html +0 -9
  84. data/spec/html/proofer/fixtures/links/brokenHashExternal.html +0 -11
  85. data/spec/html/proofer/fixtures/links/brokenHashInternal.html +0 -14
  86. data/spec/html/proofer/fixtures/links/brokenHashOnTheWeb.html +0 -2
  87. data/spec/html/proofer/fixtures/links/brokenInternalLink.html +0 -0
  88. data/spec/html/proofer/fixtures/links/brokenLinkExternal.html +0 -11
  89. data/spec/html/proofer/fixtures/links/brokenLinkInternal.html +0 -10
  90. data/spec/html/proofer/fixtures/links/brokenLinkWithNumber.html +0 -8
  91. data/spec/html/proofer/fixtures/links/brokenUnixLinks.html +0 -5
  92. data/spec/html/proofer/fixtures/links/broken_hash_with_query.html +0 -9
  93. data/spec/html/proofer/fixtures/links/checkSSLLinks.html +0 -1
  94. data/spec/html/proofer/fixtures/links/ensure_typhoeus_options.html +0 -1
  95. data/spec/html/proofer/fixtures/links/erstiebegr%C3%BC%C3%9Fung.html +0 -0
  96. data/spec/html/proofer/fixtures/links/erstiebegr/303/274/303/237ung.html +0 -0
  97. data/spec/html/proofer/fixtures/links/escape_pipes.html +0 -9
  98. data/spec/html/proofer/fixtures/links/file.foo +0 -11
  99. data/spec/html/proofer/fixtures/links/folder/anchorLink.html +0 -0
  100. data/spec/html/proofer/fixtures/links/folder/assets/barrel.png +0 -0
  101. data/spec/html/proofer/fixtures/links/folder/index.html +0 -0
  102. data/spec/html/proofer/fixtures/links/folder/multiples/catalog/file.html +0 -8
  103. data/spec/html/proofer/fixtures/links/folder/multiples/javadoc/file.html +0 -8
  104. data/spec/html/proofer/fixtures/links/folder/relativeImage.html +0 -2
  105. data/spec/html/proofer/fixtures/links/folder-php/index.php +0 -2
  106. data/spec/html/proofer/fixtures/links/githubHash.html +0 -1
  107. data/spec/html/proofer/fixtures/links/gpl.png +0 -0
  108. data/spec/html/proofer/fixtures/links/hashReferringToSelf.html +0 -44
  109. data/spec/html/proofer/fixtures/links/head_link_href.html +0 -7
  110. data/spec/html/proofer/fixtures/links/head_link_href_absent.html +0 -7
  111. data/spec/html/proofer/fixtures/links/head_link_href_empty.html +0 -7
  112. data/spec/html/proofer/fixtures/links/ignorableLinks.html +0 -13
  113. data/spec/html/proofer/fixtures/links/ignorableLinksViaOptions.html +0 -13
  114. data/spec/html/proofer/fixtures/links/invalid_mailto_link.html +0 -9
  115. data/spec/html/proofer/fixtures/links/javascript_link.html +0 -9
  116. data/spec/html/proofer/fixtures/links/linkToFolder.html +0 -9
  117. data/spec/html/proofer/fixtures/links/linkTranslatedViaHrefSwap.html +0 -9
  118. data/spec/html/proofer/fixtures/links/linkWithHttps.html +0 -9
  119. data/spec/html/proofer/fixtures/links/linkWithRedirect.html +0 -12
  120. data/spec/html/proofer/fixtures/links/link_directory_without_slash.html +0 -1
  121. data/spec/html/proofer/fixtures/links/link_missing_protocol_invalid.html +0 -9
  122. data/spec/html/proofer/fixtures/links/link_missing_protocol_valid.html +0 -9
  123. data/spec/html/proofer/fixtures/links/link_pointing_to_directory.html +0 -1
  124. data/spec/html/proofer/fixtures/links/links_in_pre.html +0 -13
  125. data/spec/html/proofer/fixtures/links/mailto_link.html +0 -9
  126. data/spec/html/proofer/fixtures/links/missingLinkHref.html +0 -9
  127. data/spec/html/proofer/fixtures/links/multipleProblems.html +0 -11
  128. data/spec/html/proofer/fixtures/links/nodupe.html +0 -1
  129. data/spec/html/proofer/fixtures/links/non_standard_characters.html +0 -10
  130. data/spec/html/proofer/fixtures/links/notarealhash.html +0 -0
  131. data/spec/html/proofer/fixtures/links/other_protocols.html +0 -4
  132. data/spec/html/proofer/fixtures/links/placeholder_with_empty_id.html +0 -1
  133. data/spec/html/proofer/fixtures/links/placeholder_with_id.html +0 -1
  134. data/spec/html/proofer/fixtures/links/placeholder_with_name.html +0 -1
  135. data/spec/html/proofer/fixtures/links/redirected_error.html +0 -1
  136. data/spec/html/proofer/fixtures/links/relativeLinks.html +0 -4
  137. data/spec/html/proofer/fixtures/links/rootLink/folder/index.html +0 -1
  138. data/spec/html/proofer/fixtures/links/rootLink/index.html +0 -1
  139. data/spec/html/proofer/fixtures/links/rootLink/rootLink.html +0 -9
  140. data/spec/html/proofer/fixtures/links/tel_link.html +0 -9
  141. data/spec/html/proofer/fixtures/links/urlencoded-href.html +0 -2
  142. data/spec/html/proofer/fixtures/links/utf8Link.html +0 -2
  143. data/spec/html/proofer/fixtures/resources/Screen Shot 2012-08-09 at 7.51.18 AM.png +0 -0
  144. data/spec/html/proofer/fixtures/resources/books/assets/getting-good-with-git.jpg +0 -0
  145. data/spec/html/proofer/fixtures/resources/books/assets/pro-git.jpg +0 -0
  146. data/spec/html/proofer/fixtures/resources/books/assets/version-control-with-git.jpg +0 -0
  147. data/spec/html/proofer/fixtures/resources/books/nestedRelativeImages.html +0 -5
  148. data/spec/html/proofer/fixtures/resources/gpl.png +0 -0
  149. data/spec/html/proofer/fixtures/scripts/ignorableLinksViaOptions.html +0 -4
  150. data/spec/html/proofer/fixtures/scripts/script.js +0 -1
  151. data/spec/html/proofer/fixtures/scripts/script_broken_external.html +0 -9
  152. data/spec/html/proofer/fixtures/scripts/script_content.html +0 -9
  153. data/spec/html/proofer/fixtures/scripts/script_content_absent.html +0 -9
  154. data/spec/html/proofer/fixtures/scripts/script_in_pre.html +0 -5
  155. data/spec/html/proofer/fixtures/scripts/script_missing_internal.html +0 -9
  156. data/spec/html/proofer/fixtures/scripts/script_valid_internal.html +0 -9
  157. data/spec/html/proofer/fixtures/sorting/issue/broken_image_one.html +0 -1
  158. data/spec/html/proofer/fixtures/sorting/issue/broken_image_two.html +0 -4
  159. data/spec/html/proofer/fixtures/sorting/path/multiple_issues.html +0 -11
  160. data/spec/html/proofer/fixtures/sorting/path/single_issue.html +0 -1
  161. data/spec/html/proofer/fixtures/sorting/status/a_404.html +0 -1
  162. data/spec/html/proofer/fixtures/sorting/status/broken_link.html +0 -3
  163. data/spec/html/proofer/fixtures/sorting/status/missing_redirect.html +0 -1
  164. data/spec/html/proofer/fixtures/utils/lang-jp.html +0 -1
  165. data/spec/html/proofer/html_spec.rb +0 -57
  166. data/spec/html/proofer/images_spec.rb +0 -147
  167. data/spec/html/proofer/links_spec.rb +0 -364
  168. data/spec/html/proofer/scripts_spec.rb +0 -47
  169. data/spec/html/proofer/utils_spec.rb +0 -14
  170. data/spec/html/proofer_spec.rb +0 -122
  171. data/spec/spec_helper.rb +0 -52
@@ -1,364 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Links test' do
4
-
5
- it 'fails for broken internal hash (even if the file exists)' do
6
- brokenHashExternalFilepath = "#{FIXTURES_DIR}/links/brokenHashExternal.html"
7
- proofer = run_proofer(brokenHashExternalFilepath)
8
- expect(proofer.failed_tests.last).to match(%r{linking to ../images/missingImageAlt.html#asdfasfdkafl, but asdfasfdkafl does not exist})
9
- end
10
-
11
- it 'fails for broken hashes on the web when asked (even if the file exists)' do
12
- brokenHashOnTheWeb = "#{FIXTURES_DIR}/links/brokenHashOnTheWeb.html"
13
- proofer = run_proofer(brokenHashOnTheWeb, { :check_external_hash => true} )
14
- expect(proofer.failed_tests.first).to match(/but the hash 'no' does not/)
15
- end
16
-
17
- it 'passes for broken hashes on the web when ignored (even if the file exists)' do
18
- brokenHashOnTheWeb = "#{FIXTURES_DIR}/links/brokenHashOnTheWeb.html"
19
- proofer = run_proofer(brokenHashOnTheWeb)
20
- expect(proofer.failed_tests).to eq []
21
- end
22
-
23
- it 'passes for GitHub hashes on the web when asked' do
24
- githubHash = "#{FIXTURES_DIR}/links/githubHash.html"
25
- proofer = run_proofer(githubHash)
26
- expect(proofer.failed_tests).to eq []
27
- end
28
-
29
- it 'passes for broken hashes on the web (when we look only for 4xx)' do
30
- options = { :only_4xx => true }
31
- brokenHashOnTheWeb = "#{FIXTURES_DIR}/links/brokenHashOnTheWeb.html"
32
- proofer = run_proofer(brokenHashOnTheWeb, options)
33
- expect(proofer.failed_tests).to eq []
34
- end
35
-
36
- it 'fails for broken internal hash' do
37
- brokenHashInternalFilepath = "#{FIXTURES_DIR}/links/brokenHashInternal.html"
38
- proofer = run_proofer(brokenHashInternalFilepath)
39
- expect(proofer.failed_tests.first).to match(/linking to internal hash #noHash that does not exist/)
40
- end
41
-
42
- it 'fails for broken external links' do
43
- brokenLinkExternalFilepath = "#{FIXTURES_DIR}/links/brokenLinkExternal.html"
44
- proofer = run_proofer(brokenLinkExternalFilepath)
45
- expect(proofer.failed_tests.first).to match(/failed: 0 Couldn't resolve host name/)
46
- end
47
-
48
- it 'passes for different filename without option' do
49
- brokenLinkExternalFilepath = "#{FIXTURES_DIR}/links/file.foo"
50
- proofer = run_proofer(brokenLinkExternalFilepath)
51
- expect(proofer.failed_tests).to eq []
52
- end
53
-
54
- it 'fails for different filenames' do
55
- options = { :ext => '.foo' }
56
- brokenLinkExternalFilepath = "#{FIXTURES_DIR}/links/file.foo"
57
- proofer = run_proofer(brokenLinkExternalFilepath, options)
58
- expect(proofer.failed_tests.first).to match(/failed: 0 Couldn't resolve host name/)
59
- end
60
-
61
- it 'fails for broken internal links' do
62
- brokenLinkInternalFilepath = "#{FIXTURES_DIR}/links/brokenLinkInternal.html"
63
- proofer = run_proofer(brokenLinkInternalFilepath)
64
- expect(proofer.failed_tests.first).to match(/internally linking to .\/notreal.html, which does not exist/)
65
- end
66
-
67
- it 'fails for link with no href' do
68
- missingLinkHrefFilepath = "#{FIXTURES_DIR}/links/missingLinkHref.html"
69
- proofer = run_proofer(missingLinkHrefFilepath)
70
- expect(proofer.failed_tests.first).to match(/anchor has no href attribute/)
71
- end
72
-
73
- it 'should follow redirects' do
74
- linkWithRedirectFilepath = "#{FIXTURES_DIR}/links/linkWithRedirect.html"
75
- proofer = run_proofer(linkWithRedirectFilepath)
76
- expect(proofer.failed_tests).to eq []
77
- end
78
-
79
- it 'fails on redirects if not following' do
80
- linkWithRedirectFilepath = "#{FIXTURES_DIR}/links/linkWithRedirect.html"
81
- proofer = run_proofer(linkWithRedirectFilepath, :typhoeus => { :followlocation => false })
82
- expect(proofer.failed_tests.first).to match(/failed: 301 No error/)
83
- end
84
-
85
- it "does not fail on redirects we're not following" do
86
- # this test should emit a 301--see above--but we're intentionally supressing it
87
- linkWithRedirectFilepath = "#{FIXTURES_DIR}/links/linkWithRedirect.html"
88
- proofer = run_proofer(linkWithRedirectFilepath, { :only_4xx => true, :typhoeus => { :followlocation => false } })
89
- expect(proofer.failed_tests).to eq []
90
- end
91
-
92
- it 'should understand https' do
93
- linkWithHttpsFilepath = "#{FIXTURES_DIR}/links/linkWithHttps.html"
94
- proofer = run_proofer(linkWithHttpsFilepath)
95
- expect(proofer.failed_tests).to eq []
96
- end
97
-
98
- it 'fails for broken hash links with status code numbers' do
99
- brokenLinkWithNumberFilepath = "#{FIXTURES_DIR}/links/brokenLinkWithNumber.html"
100
- proofer = run_proofer(brokenLinkWithNumberFilepath)
101
- expect(proofer.failed_tests.first).to match(/linking to internal hash #25-method-not-allowed that does not exist/)
102
- end
103
-
104
- it 'properly resolves implicit /index.html in link paths' do
105
- linkToFolder = "#{FIXTURES_DIR}/links/linkToFolder.html"
106
- proofer = run_proofer(linkToFolder)
107
- expect(proofer.failed_tests).to eq []
108
- end
109
-
110
- it 'properly checks links to root' do
111
- rootLink = "#{FIXTURES_DIR}/links/rootLink/rootLink.html"
112
- proofer = run_proofer(rootLink)
113
- expect(proofer.failed_tests).to eq []
114
- end
115
-
116
- it 'properly checks relative links' do
117
- relativeLinks = "#{FIXTURES_DIR}/links/relativeLinks.html"
118
- proofer = run_proofer(relativeLinks)
119
- expect(proofer.failed_tests).to eq []
120
- end
121
-
122
- it 'properly checks ssl links' do
123
- checkSSLLinks = "#{FIXTURES_DIR}/links/checkSSLLinks.html"
124
- proofer = run_proofer(checkSSLLinks)
125
- expect(proofer.failed_tests).to eq []
126
- end
127
-
128
- it 'ignores links marked as ignore data-proofer-ignore' do
129
- ignorableLinks = "#{FIXTURES_DIR}/links/ignorableLinks.html"
130
- proofer = run_proofer(ignorableLinks)
131
- expect(proofer.failed_tests).to eq []
132
- end
133
-
134
- it 'ignores links via href_ignore' do
135
- ignorableLinks = "#{FIXTURES_DIR}/links/ignorableLinksViaOptions.html"
136
- proofer = run_proofer(ignorableLinks, { :href_ignore => [%r{^http://}, /sdadsad/, '../whaadadt.html'] })
137
- expect(proofer.failed_tests).to eq []
138
- end
139
-
140
- it 'translates links via href_swap' do
141
- translatedLink = "#{FIXTURES_DIR}/links/linkTranslatedViaHrefSwap.html"
142
- proofer = run_proofer(translatedLink, { :href_swap => { %r{\A/articles/([\w-]+)} => "\\1.html" } })
143
- expect(proofer.failed_tests).to eq []
144
- end
145
-
146
- it 'translates links via href_swap for list of links' do
147
- proofer = run_proofer(['www.garbalarba.com'], { :href_swap => { /garbalarba/ => 'github' } })
148
- expect(proofer.failed_tests).to eq []
149
- end
150
-
151
- it 'finds a mix of broken and unbroken links' do
152
- multipleProblems = "#{FIXTURES_DIR}/links/multipleProblems.html"
153
- proofer = run_proofer(multipleProblems)
154
- expect(proofer.failed_tests.first).to match(/linking to internal hash #anadaasdadsadschor that does not exist/)
155
- end
156
-
157
- it 'ignores valid mailto links' do
158
- ignorableLinks = "#{FIXTURES_DIR}/links/mailto_link.html"
159
- proofer = run_proofer(ignorableLinks)
160
- expect(proofer.failed_tests).to eq []
161
- end
162
-
163
- it 'fails for blank mailto links' do
164
- blankMailToLink = "#{FIXTURES_DIR}/links/blank_mailto_link.html"
165
- proofer = run_proofer(blankMailToLink)
166
- expect(proofer.failed_tests.first).to match(/mailto: contains no email address/)
167
- end
168
-
169
- it 'fails for invalid mailto links' do
170
- invalidMailToLink = "#{FIXTURES_DIR}/links/invalid_mailto_link.html"
171
- proofer = run_proofer(invalidMailToLink)
172
- expect(proofer.failed_tests.first).to match(/mailto:octocat contains an invalid email address/)
173
- end
174
-
175
- it 'ignores valid tel links' do
176
- ignorableLinks = "#{FIXTURES_DIR}/links/tel_link.html"
177
- proofer = run_proofer(ignorableLinks)
178
- expect(proofer.failed_tests).to eq []
179
- end
180
-
181
- it 'fails for blank tel links' do
182
- blankTelLink = "#{FIXTURES_DIR}/links/blank_tel_link.html"
183
- proofer = run_proofer(blankTelLink)
184
- expect(proofer.failed_tests.first).to match(/tel: contains no phone number/)
185
- end
186
-
187
- it 'ignores javascript links' do
188
- javascriptLink = "#{FIXTURES_DIR}/links/javascript_link.html"
189
- proofer = run_proofer(javascriptLink)
190
- expect(proofer.failed_tests).to eq []
191
- end
192
-
193
- it 'works for valid links missing the protocol' do
194
- missingProtocolLink = "#{FIXTURES_DIR}/links/link_missing_protocol_valid.html"
195
- proofer = run_proofer(missingProtocolLink)
196
- expect(proofer.failed_tests).to eq []
197
- end
198
-
199
- it 'fails for invalid links missing the protocol' do
200
- missingProtocolLink = "#{FIXTURES_DIR}/links/link_missing_protocol_invalid.html"
201
- proofer = run_proofer(missingProtocolLink)
202
- expect(proofer.failed_tests.first).to match(/Couldn't resolve host name/)
203
- end
204
-
205
- it 'works for valid href within link elements' do
206
- head_link = "#{FIXTURES_DIR}/links/head_link_href.html"
207
- proofer = run_proofer(head_link)
208
- expect(proofer.failed_tests).to eq []
209
- end
210
-
211
- it 'fails for empty href within link elements' do
212
- head_link = "#{FIXTURES_DIR}/links/head_link_href_empty.html"
213
- proofer = run_proofer(head_link)
214
- expect(proofer.failed_tests.first).to match(/anchor has no href attribute/)
215
- end
216
-
217
- it 'fails for absent href within link elements' do
218
- head_link = "#{FIXTURES_DIR}/links/head_link_href_absent.html"
219
- proofer = run_proofer(head_link)
220
- expect(proofer.failed_tests.first).to match(/anchor has no href attribute/)
221
- end
222
-
223
- it 'fails for internal linking to a directory without trailing slash' do
224
- options = { :typhoeus => { :followlocation => false } }
225
- internal = "#{FIXTURES_DIR}/links/link_directory_without_slash.html"
226
- proofer = run_proofer(internal, options)
227
- expect(proofer.failed_tests.first).to match(/without trailing slash/)
228
- end
229
-
230
- it 'ignores external links when asked' do
231
- options = { :disable_external => true }
232
- external = "#{FIXTURES_DIR}/links/brokenLinkExternal.html"
233
- proofer = run_proofer(external, options)
234
- expect(proofer.failed_tests).to eq []
235
- end
236
-
237
- it 'works for array of links' do
238
- proofer = run_proofer(['www.github.com', 'foofoofoo.biz'])
239
- expect(proofer.failed_tests.first).to match(/failed: 0 Couldn't resolve host name/)
240
- end
241
-
242
- it 'works for broken anchors within pre' do
243
- anchor_pre = "#{FIXTURES_DIR}/links/anchors_in_pre.html"
244
- proofer = run_proofer(anchor_pre)
245
- expect(proofer.failed_tests).to eq []
246
- end
247
-
248
- it 'works for broken link within pre' do
249
- link_pre = "#{FIXTURES_DIR}/links/links_in_pre.html"
250
- proofer = run_proofer(link_pre)
251
- expect(proofer.failed_tests).to eq []
252
- end
253
-
254
- it 'works for pipes in the URL' do
255
- escape_pipes = "#{FIXTURES_DIR}/links/escape_pipes.html"
256
- proofer = run_proofer(escape_pipes)
257
- expect(proofer.failed_tests).to eq []
258
- end
259
-
260
- it 'fails for broken hash with query' do
261
- broken_hash = "#{FIXTURES_DIR}/links/broken_hash_with_query.html"
262
- proofer = run_proofer(broken_hash)
263
- expect(proofer.failed_tests.first).to match(/linking to internal hash #example that does not exist/)
264
- end
265
-
266
- it 'works for directory index file' do
267
- options = { :directory_index_file => "index.php" }
268
- link_pointing_to_directory = "#{FIXTURES_DIR}/links/link_pointing_to_directory.html"
269
- proofer = run_proofer(link_pointing_to_directory, options)
270
- expect(proofer.failed_tests).to eq []
271
- end
272
-
273
- it "fails if directory index file doesn't exist" do
274
- options = { :directory_index_file => "README.md" }
275
- link_pointing_to_directory = "#{FIXTURES_DIR}/links/link_pointing_to_directory.html"
276
- proofer = run_proofer(link_pointing_to_directory, options)
277
- expect(proofer.failed_tests.first).to match "internally linking to folder-php/, which does not exist"
278
- end
279
-
280
- it 'ensures Typhoeus options are passed' do
281
- options = { :typhoeus => { :ssl_verifypeer => false } }
282
- typhoeus_options_link = "#{FIXTURES_DIR}/links/ensure_typhoeus_options.html"
283
- proofer = run_proofer(typhoeus_options_link, options)
284
- expect(proofer.failed_tests).to eq []
285
- end
286
-
287
- it 'works if subdirectory ends with .html' do
288
- with_subdirectory_html = "#{FIXTURES_DIR}/links/_site"
289
- proofer = run_proofer(with_subdirectory_html)
290
- expect(proofer.failed_tests).to eq []
291
- end
292
-
293
- it 'works for hash referring to itself' do
294
- hashReferringToSelf = "#{FIXTURES_DIR}/links/hashReferringToSelf.html"
295
- proofer = run_proofer(hashReferringToSelf)
296
- expect(proofer.failed_tests).to eq []
297
- end
298
-
299
- it 'ignores placeholder with name' do
300
- placeholder_with_name = "#{FIXTURES_DIR}/links/placeholder_with_name.html"
301
- proofer = run_proofer(placeholder_with_name)
302
- expect(proofer.failed_tests).to eq []
303
- end
304
-
305
- it 'ignores placeholder with id' do
306
- placeholder_with_id = "#{FIXTURES_DIR}/links/placeholder_with_id.html"
307
- proofer = run_proofer(placeholder_with_id)
308
- expect(proofer.failed_tests).to eq []
309
- end
310
-
311
- it 'fails for placeholder with empty id' do
312
- empty_id = "#{FIXTURES_DIR}/links/placeholder_with_empty_id.html"
313
- proofer = run_proofer(empty_id)
314
- expect(proofer.failed_tests.first).to match(/anchor has no href attribute/)
315
- end
316
-
317
- it 'ignores non-http(s) protocols' do
318
- other_protocols = "#{FIXTURES_DIR}/links/other_protocols.html"
319
- proofer = run_proofer(other_protocols)
320
- expect(proofer.failed_tests).to eq []
321
- end
322
-
323
- it 'passes non-standard characters' do
324
- fixture = "#{FIXTURES_DIR}/links/non_standard_characters.html"
325
- proofer = run_proofer(fixture)
326
- expect(proofer.failed_tests).to eq []
327
- end
328
-
329
- it 'does not dupe errors' do
330
- fixture = "#{FIXTURES_DIR}/links/nodupe.html"
331
- proofer = run_proofer(fixture)
332
- expect(proofer.failed_tests.length).to eq 1
333
- end
334
-
335
- it 'passes for broken *nix links' do
336
- fixture = "#{FIXTURES_DIR}/links/brokenUnixLinks.html"
337
- proofer = run_proofer(fixture)
338
- expect(proofer.failed_tests).to eq []
339
- end
340
-
341
- it 'passes for external UTF-8 links' do
342
- fixture = "#{FIXTURES_DIR}/links/utf8Link.html"
343
- proofer = run_proofer(fixture)
344
- expect(proofer.failed_tests).to eq []
345
- end
346
-
347
- it 'passes for urlencoded href' do
348
- fixture = "#{FIXTURES_DIR}/links/urlencoded-href.html"
349
- proofer = run_proofer(fixture)
350
- expect(proofer.failed_tests).to eq []
351
- end
352
-
353
- it 'reports failures for the original link, not the redirection' do
354
- fixture = "#{FIXTURES_DIR}/links/redirected_error.html"
355
- proofer = run_proofer(fixture)
356
- expect(proofer.failed_tests.first).to match(/post.htm\?id=63009224 failed: 404 No error/)
357
- end
358
-
359
- it 'does not complain for files with attributes containing dashes' do
360
- fixture = "#{FIXTURES_DIR}/links/attributeWithDash.html"
361
- proofer = run_proofer(fixture)
362
- expect(proofer.failed_tests).to eq []
363
- end
364
- end
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Scripts test' do
4
-
5
- it 'fails for broken external src' do
6
- file = "#{FIXTURES_DIR}/scripts/script_broken_external.html"
7
- proofer = run_proofer(file)
8
- expect(proofer.failed_tests.first).to match(/failed: 0 Couldn't resolve host name/)
9
- end
10
-
11
- it 'works for valid internal src' do
12
- file = "#{FIXTURES_DIR}/scripts/script_valid_internal.html"
13
- proofer = run_proofer(file)
14
- expect(proofer.failed_tests).to eq []
15
- end
16
-
17
- it 'fails for missing internal src' do
18
- file = "#{FIXTURES_DIR}/scripts/script_missing_internal.html"
19
- proofer = run_proofer(file)
20
- expect(proofer.failed_tests.first).to match(/doesnotexist.js does not exist \(line 5\)/)
21
- end
22
-
23
- it 'works for present content' do
24
- file = "#{FIXTURES_DIR}/scripts/script_content.html"
25
- proofer = run_proofer(file)
26
- expect(proofer.failed_tests).to eq []
27
- end
28
-
29
- it 'fails for absent content' do
30
- file = "#{FIXTURES_DIR}/scripts/script_content_absent.html"
31
- proofer = run_proofer(file)
32
- expect(proofer.failed_tests.first).to match(/script is empty and has no src attribute/)
33
- end
34
-
35
- it 'works for broken script within pre' do
36
- script_pre = "#{FIXTURES_DIR}/scripts/script_in_pre.html"
37
- proofer = run_proofer(script_pre)
38
- expect(proofer.failed_tests).to eq []
39
- end
40
-
41
- it 'ignores links via url_ignore' do
42
- ignorableLinks = "#{FIXTURES_DIR}/scripts/ignorableLinksViaOptions.html"
43
- proofer = run_proofer(ignorableLinks, { :url_ignore => [/\/assets\/.*(js|css|png|svg)/] })
44
- expect(proofer.failed_tests).to eq []
45
- end
46
-
47
- end
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe HTML::Utils do
4
- describe '::create_nokogiri' do
5
- it 'passes for a string' do
6
- noko = HTML::Utils::create_nokogiri '<html lang="jp">'
7
- expect(noko.css('html').first['lang']).to eq 'jp'
8
- end
9
- it 'passes for a file' do
10
- noko = HTML::Utils::create_nokogiri "#{FIXTURES_DIR}/utils/lang-jp.html"
11
- expect(noko.css('html').first['lang']).to eq 'jp'
12
- end
13
- end
14
- end
@@ -1,122 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe HTML::Proofer do
4
-
5
- describe '#failed_tests' do
6
- it 'is a list of the formatted errors' do
7
- brokenLinkInternalFilepath = "#{FIXTURES_DIR}/links/brokenLinkInternal.html"
8
- proofer = run_proofer(brokenLinkInternalFilepath)
9
- expect(proofer.failed_tests).to eq(["spec/html/proofer/fixtures/links/brokenLinkInternal.html: internally linking to ./notreal.html, which does not exist (line 5)", "spec/html/proofer/fixtures/links/brokenLinkInternal.html: internally linking to ./missingImageAlt.html, which does not exist (line 6)"])
10
- end
11
- end
12
-
13
- describe '#files' do
14
- it 'works for directory that ends with .html' do
15
- folder = "#{FIXTURES_DIR}/links/_site/folder.html"
16
- proofer = HTML::Proofer.new folder
17
- expect(proofer.files).to eq(["#{folder}/index.html"])
18
- end
19
- end
20
-
21
- describe '#options' do
22
- it 'strips out undesired Typhoeus options' do
23
- folder = "#{FIXTURES_DIR}/links/_site/folder.html"
24
- proofer = HTML::Proofer.new folder, :verbose => true
25
- expect(proofer.options[:verbose]).to eq(true)
26
- expect(proofer.typhoeus_opts[:verbose]).to eq(nil)
27
- end
28
-
29
- it 'takes options for Parallel' do
30
- folder = "#{FIXTURES_DIR}/links/_site/folder.html"
31
- proofer = HTML::Proofer.new folder, :parallel => { :in_processes => 3 }
32
- expect(proofer.parallel_opts[:in_processes]).to eq(3)
33
- expect(proofer.typhoeus_opts[:in_processes]).to eq(nil)
34
- expect(proofer.options[:parallel]).to eq(nil)
35
- end
36
-
37
- describe 'sorting' do
38
- it 'understands sorting by path' do
39
- output = send_proofer_output("#{FIXTURES_DIR}/sorting/path")
40
-
41
- expect(output.strip).to eq('''
42
- - spec/html/proofer/fixtures/sorting/path/multiple_issues.html
43
- * image gpl.png does not have an alt attribute (line 7)
44
- * internal image gpl.png does not exist (line 7)
45
- * tel: contains no phone number (line 5)
46
- - spec/html/proofer/fixtures/sorting/path/single_issue.html
47
- * image has a terrible filename (./Screen Shot 2012-08-09 at 7.51.18 AM.png) (line 1)
48
- '''.strip)
49
- end
50
-
51
- it 'understands sorting by issue' do
52
- output = send_proofer_output("#{FIXTURES_DIR}/sorting/issue", :error_sort => :desc)
53
- expect(output.strip).to eq('''
54
- - image ./gpl.png does not have an alt attribute
55
- * spec/html/proofer/fixtures/sorting/issue/broken_image_one.html (line 1)
56
- * spec/html/proofer/fixtures/sorting/issue/broken_image_two.html (line 1)
57
- - internal image ./gpl.png does not exist
58
- * spec/html/proofer/fixtures/sorting/issue/broken_image_one.html (line 1)
59
- * spec/html/proofer/fixtures/sorting/issue/broken_image_two.html (line 1)
60
- - internal image NOT_AN_IMAGE does not exist
61
- * spec/html/proofer/fixtures/sorting/issue/broken_image_two.html (line 4)
62
- '''.strip)
63
- end
64
-
65
-
66
- it 'understands sorting by status' do
67
- output = send_proofer_output("#{FIXTURES_DIR}/sorting/status", :typhoeus => { :followlocation => false }, :error_sort => :status)
68
- expect(output.strip).to eq('''
69
- - -1
70
- * spec/html/proofer/fixtures/sorting/status/broken_link.html: internally linking to nowhere.fooof, which does not exist (line 3)
71
- - 301
72
- * spec/html/proofer/fixtures/sorting/status/a_404.html: External link http://upload.wikimedia.org/wikipedia/en/thumb/not_here.png failed: 301 No error
73
- * spec/html/proofer/fixtures/sorting/status/broken_link.html: External link http://upload.wikimedia.org/wikipedia/en/thumb/fooooof.png failed: 301 No error
74
- '''.strip)
75
- end
76
- end
77
-
78
- describe 'file ignores' do
79
- it 'knows how to ignore a file by string' do
80
- options = { :file_ignore => ["#{FIXTURES_DIR}/links/brokenHashInternal.html"] }
81
- brokenHashInternalFilepath = "#{FIXTURES_DIR}/links/brokenHashInternal.html"
82
- proofer = run_proofer(brokenHashInternalFilepath, options)
83
- expect(proofer.failed_tests).to eq []
84
- end
85
-
86
- it 'knows how to ignore a file by regexp' do
87
- options = { :file_ignore => [/brokenHash/] }
88
- brokenHashInternalFilepath = "#{FIXTURES_DIR}/links/brokenHashInternal.html"
89
- proofer = run_proofer(brokenHashInternalFilepath, options)
90
- expect(proofer.failed_tests).to eq []
91
- end
92
-
93
- it 'knows how to ignore multiple files by regexp' do
94
- options = { :file_ignore => [%r{.*/javadoc/.*}, %r{.*/catalog/.*}] }
95
- brokenFolders = "#{FIXTURES_DIR}/links/folder/multiples"
96
- proofer = run_proofer(brokenFolders, options)
97
- expect(proofer.failed_tests).to eq []
98
- end
99
-
100
- it 'knows how to ignore a directory by regexp' do
101
- options = { :file_ignore => [/\S\.html/] }
102
- linksDir = "#{FIXTURES_DIR}/links"
103
- proofer = run_proofer(linksDir, options)
104
- expect(proofer.failed_tests).to eq []
105
- end
106
- end
107
- end
108
-
109
- describe 'ignored checks' do
110
- it 'knows how to ignore checks' do
111
- options = { :checks_to_ignore => ['ImageRunner'] }
112
- proofer = make_proofer('', options)
113
- expect(proofer.checks).to_not include 'ImageRunner'
114
- end
115
-
116
- it 'does not care about phoney ignored checks' do
117
- options = { :checks_to_ignore => ['This is nothing.'] }
118
- proofer = make_proofer('', options)
119
- expect(proofer.checks.length).to eq 3
120
- end
121
- end
122
- end
data/spec/spec_helper.rb DELETED
@@ -1,52 +0,0 @@
1
- require 'bundler/setup'
2
- require_relative "../lib/html/proofer"
3
-
4
- FIXTURES_DIR = "spec/html/proofer/fixtures"
5
-
6
- RSpec.configure do |config|
7
- # Use color in STDOUT
8
- config.color = true
9
-
10
- # Use color not only in STDOUT but also in pagers and files
11
- config.tty = true
12
-
13
- # Use the specified formatter
14
- config.formatter = :documentation # :progress, :html, :textmate
15
-
16
- # Run in a random order
17
- config.order = :random
18
- end
19
-
20
- def capture_stderr(*)
21
- original_stderr = $stderr
22
- original_stdout = $stdout
23
- $stderr = fake_err = StringIO.new
24
- $stdout = fake_out = StringIO.new
25
- begin
26
- yield
27
- rescue RuntimeError
28
- ensure
29
- $stderr = original_stderr
30
- $stdout = original_stdout
31
- end
32
- fake_err.string
33
- end
34
-
35
- def make_proofer(file, opts)
36
- HTML::Proofer.new(file, opts)
37
- end
38
-
39
- def run_proofer(file, opts = {})
40
- proofer = make_proofer(file, opts)
41
- capture_stderr { proofer.run }
42
- proofer
43
- end
44
-
45
- def send_proofer_output(file, opts = {})
46
- proofer = make_proofer(file, opts)
47
- capture_stderr { proofer.run }
48
- end
49
-
50
- def make_bin(cmd, path=nil)
51
- `bin/htmlproof #{cmd} #{path}`
52
- end