html-proofer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +26 -0
- data/LICENSE.txt +22 -0
- data/README.md +64 -0
- data/html-proofer.gemspec +22 -0
- data/lib/html/proofer.rb +50 -0
- data/lib/html/proofer/check.rb +111 -0
- data/lib/html/proofer/checks.rb +9 -0
- data/lib/html/proofer/checks/images.rb +24 -0
- data/lib/html/proofer/checks/links.rb +49 -0
- data/lib/html/proofer/version.rb +5 -0
- data/spec/html/proofer/fixtures/brokenHashExternal.html +11 -0
- data/spec/html/proofer/fixtures/brokenHashInternal.html +14 -0
- data/spec/html/proofer/fixtures/brokenLinkExternal.html +11 -0
- data/spec/html/proofer/fixtures/brokenLinkInternal.html +10 -0
- data/spec/html/proofer/fixtures/existingImageExternal.html +9 -0
- data/spec/html/proofer/fixtures/gpl.png +0 -0
- data/spec/html/proofer/fixtures/missingImageAlt.html +9 -0
- data/spec/html/proofer/fixtures/missingImageDirPrefix.html +9 -0
- data/spec/html/proofer/fixtures/missingImageExternal.html +9 -0
- data/spec/html/proofer/fixtures/missingImageInternal.html +9 -0
- data/spec/html/proofer/fixtures/missingImageSrc.html +9 -0
- data/spec/html/proofer/fixtures/missingLinkHref.html +9 -0
- data/spec/html/proofer/images_spec.rb +46 -0
- data/spec/html/proofer/links_spec.rb +40 -0
- data/spec/html/proofer/version_spec.rb +9 -0
- data/spec/spec_helper.rb +7 -0
- metadata +155 -0
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
|
15
|
+
out/
|
16
|
+
sample.rb
|
17
|
+
run_sample.rb
|
18
|
+
|
19
|
+
# YARD artifacts
|
20
|
+
.yardoc
|
21
|
+
_yardoc
|
22
|
+
doc/
|
23
|
+
.DS_Store
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
html-proofer (0.0.1)
|
5
|
+
nokogiri (~> 1.5.6)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.2.1)
|
11
|
+
nokogiri (1.5.6)
|
12
|
+
rspec (2.13.0)
|
13
|
+
rspec-core (~> 2.13.0)
|
14
|
+
rspec-expectations (~> 2.13.0)
|
15
|
+
rspec-mocks (~> 2.13.0)
|
16
|
+
rspec-core (2.13.1)
|
17
|
+
rspec-expectations (2.13.0)
|
18
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
19
|
+
rspec-mocks (2.13.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
html-proofer!
|
26
|
+
rspec (~> 2.13.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Garen Torikian
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# HTML::Proofer
|
2
|
+
|
3
|
+
Generate HTML files? Use them for documentation? Great, then this tool might be for you.
|
4
|
+
|
5
|
+
Here are a set of tests to validate your HTML output. These tests check if your image references are legitimate, if they have alt tags, if your internal links are working, and so on. It's intended to be an all-in-one checker for your documentation output.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'html-proofer'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install html-proofer
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Require the gem; generate some HTML; then `call` the `HTML::Proofer` on
|
24
|
+
your out folder:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'html/proofer'
|
28
|
+
require 'html/pipeline'
|
29
|
+
require 'find'
|
30
|
+
|
31
|
+
# make an out dir
|
32
|
+
Dir.mkdir("out") unless File.exists?("out")
|
33
|
+
|
34
|
+
pipeline = HTML::Pipeline.new [
|
35
|
+
HTML::Pipeline::MarkdownFilter,
|
36
|
+
HTML::Pipeline::TableOfContentsFilter
|
37
|
+
], :gfm => true
|
38
|
+
|
39
|
+
# iterate over files, and generate HTML from Markdown
|
40
|
+
Find.find("./docs") do |path|
|
41
|
+
if File.extname(path) == ".md"
|
42
|
+
contents = File.read(path)
|
43
|
+
result = pipeline.call(contents)
|
44
|
+
|
45
|
+
File.open("out/#{path.split("/").pop.sub('.md', '.html')}", 'w') { |file| file.write(result[:output].to_s) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# test your out dir!
|
50
|
+
tester = HTML::Proofer.new("./out")
|
51
|
+
tester.run
|
52
|
+
```
|
53
|
+
|
54
|
+
The `HTML::Proofer` constructor takes on optional hash of additional options:
|
55
|
+
|
56
|
+
* `:ext`: the extension (including the `.`) of your HTML files (default: `.html)
|
57
|
+
|
58
|
+
## What's Tested?
|
59
|
+
|
60
|
+
* Whether all your images have alt tags
|
61
|
+
* Whether your internal image references are not broken
|
62
|
+
* Whether external images are showing
|
63
|
+
* Whether your internal links are not broken; this includes hash references (`#linkToMe`)
|
64
|
+
* Whether external links are working
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/html/proofer/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "html-proofer"
|
6
|
+
gem.version = HTML::Proofer::VERSION
|
7
|
+
gem.authors = ["Garen Torikian"]
|
8
|
+
gem.email = ["gjtorikian@gmail.com"]
|
9
|
+
gem.description = %q{Test your rendered HTML files to make sure they're accurate.}
|
10
|
+
gem.summary = %q{A set of tests to validate your HTML output. These tests check if your image references are legitimate, if they have alt tags, if your internal links are working, and so on. It's intended to be an all-in-one checker for your documentation output.}
|
11
|
+
gem.homepage = "https://github.com/gjtorikian/html-proofer"
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($/)
|
14
|
+
gem.test_files = gem.files.grep(%r{^(spec)/})
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
|
17
|
+
gem.add_dependency "nokogiri", "~> 1.5.6"
|
18
|
+
gem.add_dependency "colored", "~> 1.2"
|
19
|
+
|
20
|
+
gem.add_development_dependency "html-pipeline", "~> 0.0.7"
|
21
|
+
gem.add_development_dependency "rspec", "~> 2.13.0"
|
22
|
+
end
|
data/lib/html/proofer.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'html/proofer/checks'
|
3
|
+
|
4
|
+
module HTML
|
5
|
+
class Proofer
|
6
|
+
def initialize(src, opts = {:ext => ".html"})
|
7
|
+
@srcDir = src
|
8
|
+
@options = opts
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
Find.find(@srcDir) do |path|
|
13
|
+
if File.extname(path) == @options[:ext]
|
14
|
+
html = HTML::Proofer.create_nokogiri(path)
|
15
|
+
issues = run_checks(path, html)
|
16
|
+
self.print_issues(issues)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.create_nokogiri(path)
|
22
|
+
Nokogiri::HTML(File.read(path))
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_checks
|
26
|
+
HTML::Proofer::Checks::Check.subclasses
|
27
|
+
end
|
28
|
+
|
29
|
+
def run_checks(path, html)
|
30
|
+
issues = []
|
31
|
+
|
32
|
+
get_checks.each do |klass|
|
33
|
+
puts "Running #{klass.name.split(/:/).pop()} check... "
|
34
|
+
|
35
|
+
check = klass.new(path, html)
|
36
|
+
check.run
|
37
|
+
|
38
|
+
issues.concat(check.issues)
|
39
|
+
end
|
40
|
+
issues
|
41
|
+
end
|
42
|
+
|
43
|
+
def print_issues(issues)
|
44
|
+
return if issues.empty?
|
45
|
+
issues.each do |issue|
|
46
|
+
$stderr.puts issue + "\n\n"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'timeout'
|
5
|
+
require 'uri'
|
6
|
+
require 'colored'
|
7
|
+
|
8
|
+
class HTML::Proofer::Checks
|
9
|
+
|
10
|
+
class Check
|
11
|
+
|
12
|
+
attr_reader :issues
|
13
|
+
|
14
|
+
def initialize(path, html)
|
15
|
+
@path = path
|
16
|
+
@html = html
|
17
|
+
@issues = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
raise NotImplementedError.new("HTML::Proofer::Check subclasses must implement #run")
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_issue(desc)
|
25
|
+
@issues << desc
|
26
|
+
end
|
27
|
+
|
28
|
+
def output_filenames
|
29
|
+
Dir[@site.config[:output_dir] + '/**/*'].select{ |f| File.file?(f) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def external_href?(href)
|
33
|
+
uri = URI.parse(href)
|
34
|
+
%w( http https ).include?(uri.scheme)
|
35
|
+
rescue URI::BadURIError
|
36
|
+
false
|
37
|
+
rescue URI::InvalidURIError
|
38
|
+
false
|
39
|
+
end
|
40
|
+
|
41
|
+
def validate_url(href)
|
42
|
+
# Parse
|
43
|
+
url = nil
|
44
|
+
begin
|
45
|
+
url = URI.parse(href)
|
46
|
+
rescue URI::InvalidURIError
|
47
|
+
return Result.new(href, 'invalid URI')
|
48
|
+
end
|
49
|
+
|
50
|
+
# Skip non-HTTP URLs
|
51
|
+
#return nil if url.scheme !~ /^https?$/
|
52
|
+
|
53
|
+
# Get status
|
54
|
+
res = nil
|
55
|
+
5.times do |i|
|
56
|
+
begin
|
57
|
+
Timeout::timeout(10) do
|
58
|
+
res = request_url(url)
|
59
|
+
end
|
60
|
+
rescue => e
|
61
|
+
return nil
|
62
|
+
end
|
63
|
+
|
64
|
+
if res.code =~ /^3..$/
|
65
|
+
if i == 4
|
66
|
+
return nil
|
67
|
+
end
|
68
|
+
|
69
|
+
# Find proper location
|
70
|
+
location = res['Location']
|
71
|
+
if location !~ /^https?:\/\//
|
72
|
+
base_url = url.dup
|
73
|
+
base_url.path = (location =~ /^\// ? '' : '/')
|
74
|
+
base_url.query = nil
|
75
|
+
base_url.fragment = nil
|
76
|
+
location = base_url.to_s + location
|
77
|
+
end
|
78
|
+
puts location
|
79
|
+
url = URI.parse(location)
|
80
|
+
elsif res.code == '200'
|
81
|
+
return true
|
82
|
+
else
|
83
|
+
return nil
|
84
|
+
end
|
85
|
+
end
|
86
|
+
raise 'should not have gotten here'
|
87
|
+
end
|
88
|
+
|
89
|
+
def request_url(url)
|
90
|
+
path = (url.path.nil? || url.path.empty? ? '/' : url.path)
|
91
|
+
req = Net::HTTP::Head.new(path)
|
92
|
+
http = Net::HTTP.new(url.host, url.port)
|
93
|
+
if url.instance_of? URI::HTTPS
|
94
|
+
http.use_ssl = true
|
95
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
96
|
+
end
|
97
|
+
res = http.request(req)
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.subclasses
|
101
|
+
classes = []
|
102
|
+
|
103
|
+
ObjectSpace.each_object(Class) do |c|
|
104
|
+
next unless c.superclass == self
|
105
|
+
classes << c
|
106
|
+
end
|
107
|
+
|
108
|
+
classes
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Images < ::HTML::Proofer::Checks::Check
|
4
|
+
|
5
|
+
def run
|
6
|
+
@html.css('img').each do |img|
|
7
|
+
src = img['src']
|
8
|
+
|
9
|
+
# check image sources
|
10
|
+
if src && src.length > 0
|
11
|
+
if !external_href?(src)
|
12
|
+
self.add_issue("#{@path}".blue + ": internal image #{src} does not exist") unless src[0] != "/" and File.exist?(File.join(File.dirname(@path), src))
|
13
|
+
else
|
14
|
+
self.add_issue("#{@path}".blue + ": external image #{src} does not exist") unless validate_url(src)
|
15
|
+
end
|
16
|
+
else
|
17
|
+
self.add_issue("#{@path}".blue + ": image has no src attribute")
|
18
|
+
end
|
19
|
+
|
20
|
+
# check alt tag
|
21
|
+
self.add_issue("#{@path}".blue + ": image #{src} does not have an alt attribute") unless img['alt']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Links < ::HTML::Proofer::Checks::Check
|
4
|
+
|
5
|
+
def run
|
6
|
+
@html.css('a').each do |a|
|
7
|
+
href = a['href']
|
8
|
+
|
9
|
+
if href && href.length > 0
|
10
|
+
if href.include? '#'
|
11
|
+
href_split = href.split('#')
|
12
|
+
end
|
13
|
+
if !external_href?(href)
|
14
|
+
# an internal link, with a hash
|
15
|
+
if href_split
|
16
|
+
href_file = href_split[0]
|
17
|
+
href_hash = href_split[1]
|
18
|
+
|
19
|
+
# it's not an internal hash; it's pointing to some other file
|
20
|
+
if href_file.length > 0
|
21
|
+
href_location = File.join(File.dirname(@path), href_file)
|
22
|
+
if !File.exist?(href_location)
|
23
|
+
self.add_issue("#{@path}".blue + ": internal link #{href_location} does not exist")
|
24
|
+
else
|
25
|
+
href_html = HTML::Proofer.create_nokogiri(href_location)
|
26
|
+
found_hash_match = false
|
27
|
+
unless href_html.search("[id=#{href_hash}]", "[name=#{href_hash}]").length > 0
|
28
|
+
self.add_issue("#{@path}".blue + ": linking to #{href}, but #{href_hash} does not exist")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
# it is an internal link, with an internal hash
|
32
|
+
else
|
33
|
+
unless @html.search("[id=#{href_hash}]", "[name=#{href_hash}]").length > 0
|
34
|
+
self.add_issue("#{@path}".blue + ": linking to an internal hash called #{href_hash} that does not exist")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
# internal link, no hash
|
38
|
+
else
|
39
|
+
self.add_issue("#{@path}".blue + ": linking to #{href}, which does not exist") unless File.exist?(File.join(File.dirname(@path), href))
|
40
|
+
end
|
41
|
+
else
|
42
|
+
self.add_issue("#{@path}".blue + ": linking to #{href}, which does not exist") unless validate_url(href)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
self.add_issue("#{@path}".blue + ": link has no href attribute") unless a['name'] || a['id']
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<html>
|
2
|
+
|
3
|
+
<body>
|
4
|
+
|
5
|
+
<p>Blah blah blah. <a href="./notarealhash.html#noHash">Not a real file, don't even bother with hash!</a></p>
|
6
|
+
<p>Blah blah blah. <a href="./missingImageAlt.html#asdfasfdkafl">A real file, not a real hash!</a></p>
|
7
|
+
<a href="./brokenLinkInternal.html#safeHash">At last, a real hash link.</a>
|
8
|
+
|
9
|
+
</body>
|
10
|
+
|
11
|
+
</html>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<html>
|
2
|
+
|
3
|
+
<body>
|
4
|
+
|
5
|
+
<p>Blah blah blah. <a href="#noHash">Not a real hash!</a></p>
|
6
|
+
<p>Blah blah blah. <a href="./brokenInternalLink.html#safeHash">A real link!</a></p>
|
7
|
+
<a href="#myID">Let's go to the header, though.</a>
|
8
|
+
|
9
|
+
|
10
|
+
<a id="myID"></a>
|
11
|
+
<h1>Fake header.</h1>
|
12
|
+
</body>
|
13
|
+
|
14
|
+
</html>
|
Binary file
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
include HTML::Proofer::Checks
|
3
|
+
|
4
|
+
describe "Image" do
|
5
|
+
it "passes for existing external images" do
|
6
|
+
externalImageFilepath = "#{FIXTURES_DIR}/existingImageExternal.html"
|
7
|
+
@imageCheck = ::HTML::Proofer::Checks::Check::Images.new(externalImageFilepath, HTML::Proofer.create_nokogiri(externalImageFilepath))
|
8
|
+
@imageCheck.run
|
9
|
+
@imageCheck.issues[0].should eq(nil)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "fails for image without alt attribute" do
|
13
|
+
missingAltFilepath = "#{FIXTURES_DIR}/missingImageAlt.html"
|
14
|
+
@imageCheck = ::HTML::Proofer::Checks::Check::Images.new(missingAltFilepath, HTML::Proofer.create_nokogiri(missingAltFilepath))
|
15
|
+
@imageCheck.run
|
16
|
+
@imageCheck.issues[0].should eq("In spec/html/proofer/fixtures/missingImageAlt.html, image ./gpl.png does not have an alt attribute")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "fails for image without a dir prefix" do
|
20
|
+
missingImageDirPrefixFilepath = "#{FIXTURES_DIR}/missingImageDirPrefix.html"
|
21
|
+
@imageCheck = ::HTML::Proofer::Checks::Check::Images.new(missingImageDirPrefixFilepath, HTML::Proofer.create_nokogiri(missingImageDirPrefixFilepath))
|
22
|
+
@imageCheck.run
|
23
|
+
@imageCheck.issues[0].should eq("In spec/html/proofer/fixtures/missingImageDirPrefix.html, internal image /gpl.png does not exist")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "fails for missing external images" do
|
27
|
+
externalImageFilepath = "#{FIXTURES_DIR}/missingImageExternal.html"
|
28
|
+
@imageCheck = ::HTML::Proofer::Checks::Check::Images.new(externalImageFilepath, HTML::Proofer.create_nokogiri(externalImageFilepath))
|
29
|
+
@imageCheck.run
|
30
|
+
@imageCheck.issues[0].should eq("In spec/html/proofer/fixtures/missingImageExternal.html, external image http://www.whatthehell does not exist")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "fails for missing internal images" do
|
34
|
+
internalImageFilepath = "#{FIXTURES_DIR}/missingImageInternal.html"
|
35
|
+
@imageCheck = ::HTML::Proofer::Checks::Check::Images.new(internalImageFilepath, HTML::Proofer.create_nokogiri(internalImageFilepath))
|
36
|
+
@imageCheck.run
|
37
|
+
@imageCheck.issues[0].should eq("In spec/html/proofer/fixtures/missingImageInternal.html, internal image ./doesnotexist.png does not exist")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "fails for image with no src" do
|
41
|
+
imageSrcFilepath = "#{FIXTURES_DIR}/missingImageSrc.html"
|
42
|
+
@imageCheck = ::HTML::Proofer::Checks::Check::Images.new(imageSrcFilepath, HTML::Proofer.create_nokogiri(imageSrcFilepath))
|
43
|
+
@imageCheck.run
|
44
|
+
@imageCheck.issues[0].should eq("In spec/html/proofer/fixtures/missingImageSrc.html, image has no src attribute")
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
include HTML::Proofer::Checks
|
3
|
+
|
4
|
+
describe "Links" do
|
5
|
+
|
6
|
+
it "fails for broken external hash (even if the file exists)" do
|
7
|
+
brokenHashExternalFilepath = "#{FIXTURES_DIR}/brokenHashExternal.html"
|
8
|
+
@linkCheck = ::HTML::Proofer::Checks::Check::Links.new(brokenHashExternalFilepath, HTML::Proofer.create_nokogiri(brokenHashExternalFilepath))
|
9
|
+
@linkCheck.run
|
10
|
+
@linkCheck.issues[1].should eq("spec/html/proofer/fixtures/brokenHashExternal.html is linking to ./missingImageAlt.html#asdfasfdkafl, but asdfasfdkafl does not exist")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "fails for broken internal hash" do
|
14
|
+
brokenHashInternalFilepath = "#{FIXTURES_DIR}/brokenHashInternal.html"
|
15
|
+
@linkCheck = ::HTML::Proofer::Checks::Check::Links.new(brokenHashInternalFilepath, HTML::Proofer.create_nokogiri(brokenHashInternalFilepath))
|
16
|
+
@linkCheck.run
|
17
|
+
@linkCheck.issues[0].should eq("spec/html/proofer/fixtures/brokenHashInternal.html is linking to an internal hash called noHash that does not exist")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "fails for broken external links" do
|
21
|
+
brokenLinkExternalFilepath = "#{FIXTURES_DIR}/brokenLinkExternal.html"
|
22
|
+
@linkCheck = ::HTML::Proofer::Checks::Check::Links.new(brokenLinkExternalFilepath, HTML::Proofer.create_nokogiri(brokenLinkExternalFilepath))
|
23
|
+
@linkCheck.run
|
24
|
+
@linkCheck.issues[0].should eq("spec/html/proofer/fixtures/brokenLinkExternal.html is linking to http://www.asdo3IRJ395295jsingrkrg4.com, which does not exist")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "fails for broken internal links" do
|
28
|
+
brokenLinkInternalFilepath = "#{FIXTURES_DIR}/brokenLinkInternal.html"
|
29
|
+
@linkCheck = ::HTML::Proofer::Checks::Check::Links.new(brokenLinkInternalFilepath, HTML::Proofer.create_nokogiri(brokenLinkInternalFilepath))
|
30
|
+
@linkCheck.run
|
31
|
+
@linkCheck.issues[0].should eq("spec/html/proofer/fixtures/brokenLinkInternal.html is linking to ./notreal.html, which does not exist")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "fails for link with no href" do
|
35
|
+
missingLinkHrefFilepath = "#{FIXTURES_DIR}/missingLinkHref.html"
|
36
|
+
@linkCheck = ::HTML::Proofer::Checks::Check::Links.new(missingLinkHrefFilepath, HTML::Proofer.create_nokogiri(missingLinkHrefFilepath))
|
37
|
+
@linkCheck.run
|
38
|
+
@linkCheck.issues[0].should eq("In spec/html/proofer/fixtures/missingLinkHref.html, link has no href attribute")
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: html-proofer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Garen Torikian
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.5.6
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.5.6
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: colored
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.2'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.2'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: html-pipeline
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.0.7
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.7
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.13.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.13.0
|
78
|
+
description: Test your rendered HTML files to make sure they're accurate.
|
79
|
+
email:
|
80
|
+
- gjtorikian@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- Gemfile.lock
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- html-proofer.gemspec
|
91
|
+
- lib/html/proofer.rb
|
92
|
+
- lib/html/proofer/check.rb
|
93
|
+
- lib/html/proofer/checks.rb
|
94
|
+
- lib/html/proofer/checks/images.rb
|
95
|
+
- lib/html/proofer/checks/links.rb
|
96
|
+
- lib/html/proofer/version.rb
|
97
|
+
- spec/html/proofer/fixtures/brokenHashExternal.html
|
98
|
+
- spec/html/proofer/fixtures/brokenHashInternal.html
|
99
|
+
- spec/html/proofer/fixtures/brokenLinkExternal.html
|
100
|
+
- spec/html/proofer/fixtures/brokenLinkInternal.html
|
101
|
+
- spec/html/proofer/fixtures/existingImageExternal.html
|
102
|
+
- spec/html/proofer/fixtures/gpl.png
|
103
|
+
- spec/html/proofer/fixtures/missingImageAlt.html
|
104
|
+
- spec/html/proofer/fixtures/missingImageDirPrefix.html
|
105
|
+
- spec/html/proofer/fixtures/missingImageExternal.html
|
106
|
+
- spec/html/proofer/fixtures/missingImageInternal.html
|
107
|
+
- spec/html/proofer/fixtures/missingImageSrc.html
|
108
|
+
- spec/html/proofer/fixtures/missingLinkHref.html
|
109
|
+
- spec/html/proofer/images_spec.rb
|
110
|
+
- spec/html/proofer/links_spec.rb
|
111
|
+
- spec/html/proofer/version_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
homepage: https://github.com/gjtorikian/html-proofer
|
114
|
+
licenses: []
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 1.8.23
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: A set of tests to validate your HTML output. These tests check if your image
|
137
|
+
references are legitimate, if they have alt tags, if your internal links are working,
|
138
|
+
and so on. It's intended to be an all-in-one checker for your documentation output.
|
139
|
+
test_files:
|
140
|
+
- spec/html/proofer/fixtures/brokenHashExternal.html
|
141
|
+
- spec/html/proofer/fixtures/brokenHashInternal.html
|
142
|
+
- spec/html/proofer/fixtures/brokenLinkExternal.html
|
143
|
+
- spec/html/proofer/fixtures/brokenLinkInternal.html
|
144
|
+
- spec/html/proofer/fixtures/existingImageExternal.html
|
145
|
+
- spec/html/proofer/fixtures/gpl.png
|
146
|
+
- spec/html/proofer/fixtures/missingImageAlt.html
|
147
|
+
- spec/html/proofer/fixtures/missingImageDirPrefix.html
|
148
|
+
- spec/html/proofer/fixtures/missingImageExternal.html
|
149
|
+
- spec/html/proofer/fixtures/missingImageInternal.html
|
150
|
+
- spec/html/proofer/fixtures/missingImageSrc.html
|
151
|
+
- spec/html/proofer/fixtures/missingLinkHref.html
|
152
|
+
- spec/html/proofer/images_spec.rb
|
153
|
+
- spec/html/proofer/links_spec.rb
|
154
|
+
- spec/html/proofer/version_spec.rb
|
155
|
+
- spec/spec_helper.rb
|