html-proofer 0.0.16 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb67833a18915e42dd102d396dae588ff9ece975
4
- data.tar.gz: 15a1a7c04a8557835b23aaffc03aeb26f0db1b06
3
+ metadata.gz: bb18390b6e8107e566191736a04b0bd6209ca1fe
4
+ data.tar.gz: b82303dfc0e7972ffd8145e6465cfa03a03d3397
5
5
  SHA512:
6
- metadata.gz: 1f9982a72dee460c4a9f24c98111973cfc50de06c8e76b249a94fd896c86349f1e3f8d4c409fa43282e9565366d3be9ae32b40e2f37fd35086cf021c8c9187d4
7
- data.tar.gz: 3484b0ee9558bd807432e7563543846771baca7e65428b76b1705329a9f252ef95fd4eb09740a8a9781ac33f3991aa2e4f12b17424c1a1b7300228e3d2849acc
6
+ metadata.gz: 1fff02cdf9e240950924f36ce0eef6333e82c58075dbaf17e83f52a7314fe2a18d42ce619a5b887d338312699a24df83eb5853142e4d7ed91c0fef00213005c2
7
+ data.tar.gz: 125e1869d4ca0b448f36a0c36da4e4f601e9c8a7c959d8b44fa8532a491b52815b7e941db7d7c9623ce7f6106f7ba2b6d19125510a4d773f8a7d883e0d7b4965
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- html-proofer (0.0.16)
4
+ html-proofer (0.1.0)
5
5
  colored (~> 1.2)
6
6
  nokogiri (= 1.6.0)
7
7
  typhoeus (~> 0.6.3)
data/lib/html/proofer.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'nokogiri'
2
+ require 'find'
3
+ require 'html/proofer/checkable'
2
4
  require 'html/proofer/checks'
3
5
 
4
6
  module HTML
@@ -16,7 +18,7 @@ module HTML
16
18
  Find.find(@srcDir) do |path|
17
19
  if File.extname(path) == @options[:ext]
18
20
  html = HTML::Proofer.create_nokogiri(path)
19
- check = klass.new(path, html, @options)
21
+ check = klass.new(@srcDir, path, html, @options)
20
22
  check.run
21
23
  check.hydra.run
22
24
  self.print_issues(klass, check.issues)
@@ -24,7 +26,10 @@ module HTML
24
26
  end
25
27
  end
26
28
 
27
- if !@failedTests.empty?
29
+ if @failedTests.empty?
30
+ puts "Tests executed sucesfully.".green
31
+ exit 0
32
+ else
28
33
  # make the hash default to 0 so that += will work correctly
29
34
  count = Hash.new(0)
30
35
 
@@ -41,7 +46,7 @@ module HTML
41
46
  end
42
47
 
43
48
  def self.create_nokogiri(path)
44
- path << "index.html" if File.directory? path #support for Jekyll-style links
49
+ path << "/index.html" if File.directory? path #support for Jekyll-style links
45
50
  Nokogiri::HTML(File.read(path))
46
51
  end
47
52
 
@@ -10,9 +10,10 @@ class HTML::Proofer::Checks
10
10
 
11
11
  class Check
12
12
 
13
- attr_reader :issues, :hydra
13
+ attr_reader :issues, :hydra, :src, :path, :options, :additional_href_ignores
14
14
 
15
- def initialize(path, html, opts={})
15
+ def initialize(src, path, html, opts={})
16
+ @src = src
16
17
  @path = path
17
18
  @html = html
18
19
  @options = opts
@@ -27,31 +28,13 @@ class HTML::Proofer::Checks
27
28
  end
28
29
 
29
30
  def add_issue(desc)
30
- @issues << desc
31
+ @issues << "#{@path.blue}: #{desc}"
31
32
  end
32
33
 
33
34
  def output_filenames
34
35
  Dir[@site.config[:output_dir] + '/**/*'].select{ |f| File.file?(f) }
35
36
  end
36
37
 
37
- def external_href?(href)
38
- uri = URI.parse(href)
39
- %w( http https ).include?(uri.scheme)
40
- rescue URI::BadURIError
41
- false
42
- rescue URI::InvalidURIError
43
- false
44
- end
45
-
46
- def ignore_href?(href)
47
- uri = URI.parse(href)
48
- %w( mailto ).include?(uri.scheme) || @additional_href_ignores.include?(href)
49
- rescue URI::BadURIError
50
- false
51
- rescue URI::InvalidURIError
52
- false
53
- end
54
-
55
38
  def validate_url(href, issue_text)
56
39
  request = Typhoeus::Request.new(href, {:followlocation => true})
57
40
  request.on_complete do |response|
@@ -91,5 +74,6 @@ class HTML::Proofer::Checks
91
74
 
92
75
  classes
93
76
  end
77
+
94
78
  end
95
79
  end
@@ -0,0 +1,106 @@
1
+ module HTML
2
+ class Proofer
3
+ class Checkable
4
+
5
+ def initialize(obj, check)
6
+ @src = obj['src']
7
+ @href = obj['href']
8
+ @alt = obj['alt']
9
+ @name = obj['name']
10
+ @id = obj['id']
11
+ @check = check
12
+
13
+ if @href && @check.options[:href_swap]
14
+ @options[:href_swap].each do |link, replace|
15
+ @href = @href.gsub(link, replace)
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ def url
22
+ @src || @href || ""
23
+ end
24
+
25
+ def valid?
26
+ begin
27
+ URI.parse url
28
+ rescue
29
+ false
30
+ end
31
+ end
32
+
33
+ def parts
34
+ URI.parse url
35
+ end
36
+
37
+ def path
38
+ parts.path
39
+ end
40
+
41
+ def hash
42
+ parts.fragment
43
+ end
44
+
45
+ # path is to an external server
46
+ def remote?
47
+ uri = URI.parse url
48
+ %w( http https ).include?(uri.scheme)
49
+ rescue URI::BadURIError
50
+ false
51
+ rescue URI::InvalidURIError
52
+ false
53
+ end
54
+
55
+ def ignore?
56
+ uri = URI.parse url
57
+ %w( mailto ).include?(uri.scheme) || @check.additional_href_ignores.include?(href)
58
+ rescue URI::BadURIError
59
+ false
60
+ rescue URI::InvalidURIError
61
+ false
62
+ end
63
+
64
+ # path is external to the file
65
+ def external?
66
+ !internal?
67
+ end
68
+
69
+ # path is an anchor
70
+ def internal?
71
+ url[0] == "#"
72
+ end
73
+
74
+ def file_path
75
+
76
+ return if path.nil?
77
+
78
+ if path =~ /^\// #path relative to root
79
+ base = @check.src
80
+ elsif File.exist? File.expand_path path, @check.src #relative links, path is a file
81
+ base = File.dirname @check.path
82
+ else #relative link, path is a directory
83
+ base = @check.path
84
+ end
85
+
86
+ file = File.join base, path
87
+
88
+ # implicit /index.html support, with support for tailing slashes
89
+ file = File.join path, "index.html" if File.directory? File.expand_path file, @check.src
90
+
91
+ file
92
+ end
93
+
94
+ # checks if a file exists relative to the current pwd
95
+ def exists?
96
+ File.exist? absolute_path
97
+ end
98
+
99
+ def absolute_path
100
+ path = file_path || @check.path
101
+ File.expand_path path, Dir.pwd
102
+ end
103
+
104
+ end
105
+ end
106
+ end
@@ -1,30 +1,50 @@
1
1
  # encoding: utf-8
2
2
 
3
+ class Image < ::HTML::Proofer::Checkable
4
+
5
+ SCREEN_SHOT_REGEX = /Screen(?: |%20)Shot(?: |%20)\d+-\d+-\d+(?: |%20)at(?: |%20)\d+.\d+.\d+/
6
+
7
+ def valid_alt_tag?
8
+ @alt and !@alt.empty?
9
+ end
10
+
11
+ def terrible_filename?
12
+ @src =~ SCREEN_SHOT_REGEX
13
+ end
14
+
15
+ def src
16
+ @src unless @src.nil? || @src.empty?
17
+ end
18
+
19
+ def missing_src?
20
+ !src
21
+ end
22
+
23
+ end
24
+
3
25
  class Images < ::HTML::Proofer::Checks::Check
4
26
 
5
27
  def run
6
28
  @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
- validate_url(src, "#{@path}".blue + ": external image #{src} does not exist")
15
- end
29
+
30
+ img = Image.new img, self
31
+
32
+ # screenshot filenames, return because invalid URL
33
+ return self.add_issue "image has a terrible filename (#{img.src})" if img.terrible_filename?
34
+
35
+ # does the image exist?
36
+ if img.missing_src?
37
+ self.add_issue "image has no src attribute"
38
+ elsif img.remote?
39
+ validate_url img.src, "external image #{img.src} does not exist"
16
40
  else
17
- self.add_issue("#{@path}".blue + ": image has no src attribute")
41
+ self.add_issue("internal image #{img.src} does not exist") unless img.exists?
18
42
  end
19
43
 
20
44
  # check alt tag
21
- self.add_issue("#{@path}".blue + ": image #{src} does not have an alt attribute") unless img['alt'] and !img['alt'].empty?
22
-
23
- screenShotRegExp = /Screen(?: |%20)Shot(?: |%20)\d+-\d+-\d+(?: |%20)at(?: |%20)\d+.\d+.\d+/
45
+ self.add_issue "image #{img.src} does not have an alt attribute" unless img.valid_alt_tag?
46
+
24
47
 
25
- if src =~ screenShotRegExp
26
- self.add_issue("#{@path}".blue + ": image has a terrible filename (#{src})")
27
- end
28
48
  end
29
49
  end
30
50
  end
@@ -1,57 +1,48 @@
1
1
  # encoding: utf-8
2
2
 
3
+ class Link < ::HTML::Proofer::Checkable
4
+
5
+ def href
6
+ @href unless @href.nil? || @href.empty?
7
+ end
8
+
9
+ def missing_href?
10
+ href.nil? and @name.nil? and @id.nil?
11
+ end
12
+
13
+ end
14
+
3
15
  class Links < ::HTML::Proofer::Checks::Check
4
16
 
5
17
  def run
6
- @html.css('a').each do |a|
7
- href = a['href']
18
+ @html.css('a').each do |link|
8
19
 
9
- if href && href.length > 0
10
- if @options[:href_swap]
11
- @options[:href_swap].each do |link, replace|
12
- href = href.gsub(link, replace)
13
- end
14
- end
20
+ link = Link.new link, self
21
+ return if link.ignore?
15
22
 
16
- return if ignore_href?(href)
23
+ # is there even a href?
24
+ return self.add_issue("link has no href attribute") if link.missing_href?
17
25
 
18
- if href.include? '#'
19
- href_split = href.split('#')
20
- end
21
- if !external_href?(href)
22
- # an internal link, with a hash
23
- if href_split && !href_split.empty?
24
- href_file = href_split[0]
25
- href_hash = href_split[1]
26
+ # is it even a valid URL?
27
+ return self.add_issue "#{link.href} is an invalid URL" unless link.valid?
26
28
 
27
- # it's not an internal hash; it's pointing to some other file
28
- if href_file.length > 0
29
- href_location = resolve_path File.join(File.dirname(@path), href_file)
30
- if !File.exist?(href_location)
31
- self.add_issue("#{@path}".blue + ": internal link #{href_location} does not exist")
32
- else
33
- href_html = HTML::Proofer.create_nokogiri(href_location)
34
- found_hash_match = false
35
- unless hash_check(href_html, href_hash)
36
- self.add_issue("#{@path}".blue + ": linking to #{href}, but #{href_hash} does not exist")
37
- end
38
- end
39
- # it is an internal link, with an internal hash
40
- else
41
- unless hash_check(@html, href_hash)
42
- self.add_issue("#{@path}".blue + ": linking to an internal hash called #{href_hash} that does not exist")
43
- end
44
- end
45
- # internal link, no hash
46
- else
47
- href_location = resolve_path File.join(File.dirname(@path), href)
48
- self.add_issue("#{@path}".blue + ": internally linking to #{href_location}, which does not exist") unless File.exist?(href_location)
49
- end
50
- else
51
- validate_url(href, "#{@path}".blue + ": externally linking to #{href}, which does not exist")
52
- end
29
+ # does the file even exist?
30
+ if link.remote?
31
+ validate_url link.href, "externally linking to #{link.href}, which does not exist"
53
32
  else
54
- self.add_issue("#{@path}".blue + ": link has no href attribute") unless a['name'] || a['id']
33
+ self.add_issue "internally linking to #{link.href}, which does not exist" unless link.exists?
34
+ end
35
+
36
+ # verify the target hash
37
+ if link.hash
38
+ if link.remote?
39
+ #not yet checked
40
+ elsif link.internal?
41
+ self.add_issue "linking to internal hash ##{link.hash} that does not exist" unless hash_check @html, link.hash
42
+ elsif link.external?
43
+ target_html = HTML::Proofer.create_nokogiri link.absolute_path
44
+ self.add_issue "linking to #{link.href}, but #{link.hash} does not exist" unless hash_check target_html, link.hash
45
+ end
55
46
  end
56
47
  end
57
48
  end
@@ -60,9 +51,4 @@ class Links < ::HTML::Proofer::Checks::Check
60
51
  html.xpath("//*[@id='#{href_hash}']", "//*[@name='#{href_hash}']").length > 0
61
52
  end
62
53
 
63
- #support for implicit /index.html in URLs
64
- def resolve_path(path)
65
- path << "index.html" if File.directory? path
66
- path
67
- end
68
54
  end
@@ -1,5 +1,5 @@
1
1
  module HTML
2
2
  class Proofer
3
- VERSION = "0.0.16"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  <body>
4
4
 
5
- <p>Blah blah blah. <a name="25-method-not-allowed" class="anchor" href="#25-method-not-allowed"><span class="mini-icon mini-icon-link"></span></a>25 Method not allowed</h4></p>
5
+ <p>Blah blah blah. <a class="anchor" href="#25-method-not-allowed"><span class="mini-icon mini-icon-link"></span></a>25 Method not allowed</h4></p>
6
6
  </body>
7
7
 
8
- </html>
8
+ </html>
File without changes
@@ -1 +1 @@
1
- root.
1
+ <h1 id="anchor">root.</a>
File without changes
@@ -0,0 +1,4 @@
1
+ <a href="/index.html">Relative to root</a>
2
+ <a href="index.html">Relative to self</a>
3
+ <a href="folder/">Folder relative to self</a>
4
+ <a href="index.html#anchor">Anchor relative to self</a>
@@ -3,6 +3,7 @@
3
3
  <body>
4
4
 
5
5
  <p>Blah blah blah. <a href="/">I am root.</a></p>
6
+ <p>Blah blah blah. <a href="/folder">I am relative to root.</a></p>
6
7
 
7
8
  </body>
8
9
 
@@ -3,35 +3,28 @@ require "spec_helper"
3
3
  describe "Image tests" do
4
4
  it "passes for existing external images" do
5
5
  externalImageFilepath = "#{FIXTURES_DIR}/existingImageExternal.html"
6
- @imageCheck = Images.new(externalImageFilepath, HTML::Proofer.create_nokogiri(externalImageFilepath))
6
+ @imageCheck = Images.new("#{FIXTURES_DIR}", externalImageFilepath, HTML::Proofer.create_nokogiri(externalImageFilepath))
7
7
  @imageCheck.run
8
8
  @imageCheck.issues[0].should eq(nil)
9
9
  end
10
10
 
11
11
  it "fails for image without alt attribute" do
12
12
  missingAltFilepath = "#{FIXTURES_DIR}/missingImageAlt.html"
13
- @imageCheck = Images.new(missingAltFilepath, HTML::Proofer.create_nokogiri(missingAltFilepath))
13
+ @imageCheck = Images.new("#{FIXTURES_DIR}", missingAltFilepath, HTML::Proofer.create_nokogiri(missingAltFilepath))
14
14
  @imageCheck.run
15
15
  @imageCheck.issues[0].should eq("spec/html/proofer/fixtures/missingImageAlt.html".blue + ": image ./gpl.png does not have an alt attribute")
16
16
  end
17
17
 
18
18
  it "fails for image with an empty alt attribute" do
19
19
  missingAltFilepath = "#{FIXTURES_DIR}/missingImageAltText.html"
20
- @imageCheck = Images.new(missingAltFilepath, HTML::Proofer.create_nokogiri(missingAltFilepath))
20
+ @imageCheck = Images.new("#{FIXTURES_DIR}", missingAltFilepath, HTML::Proofer.create_nokogiri(missingAltFilepath))
21
21
  @imageCheck.run
22
22
  @imageCheck.issues[0].should eq("spec/html/proofer/fixtures/missingImageAltText.html".blue + ": image ./gpl.png does not have an alt attribute")
23
23
  end
24
24
 
25
- it "fails for image without a dir prefix" do
26
- missingImageDirPrefixFilepath = "#{FIXTURES_DIR}/missingImageDirPrefix.html"
27
- @imageCheck = Images.new(missingImageDirPrefixFilepath, HTML::Proofer.create_nokogiri(missingImageDirPrefixFilepath))
28
- @imageCheck.run
29
- @imageCheck.issues[0].should eq("spec/html/proofer/fixtures/missingImageDirPrefix.html".blue + ": internal image /gpl.png does not exist")
30
- end
31
-
32
25
  it "fails for missing external images" do
33
26
  externalImageFilepath = "#{FIXTURES_DIR}/missingImageExternal.html"
34
- @imageCheck = Images.new(externalImageFilepath, HTML::Proofer.create_nokogiri(externalImageFilepath))
27
+ @imageCheck = Images.new("#{FIXTURES_DIR}", externalImageFilepath, HTML::Proofer.create_nokogiri(externalImageFilepath))
35
28
  @imageCheck.run
36
29
  @imageCheck.hydra.run
37
30
  @imageCheck.issues[0].sub!(/ #<Typhoeus::Response:[\w]+>/, "")
@@ -40,21 +33,21 @@ describe "Image tests" do
40
33
 
41
34
  it "fails for missing internal images" do
42
35
  internalImageFilepath = "#{FIXTURES_DIR}/missingImageInternal.html"
43
- @imageCheck = Images.new(internalImageFilepath, HTML::Proofer.create_nokogiri(internalImageFilepath))
36
+ @imageCheck = Images.new("#{FIXTURES_DIR}", internalImageFilepath, HTML::Proofer.create_nokogiri(internalImageFilepath))
44
37
  @imageCheck.run
45
38
  @imageCheck.issues[0].should eq("spec/html/proofer/fixtures/missingImageInternal.html".blue + ": internal image ./doesnotexist.png does not exist")
46
39
  end
47
40
 
48
41
  it "fails for image with no src" do
49
42
  imageSrcFilepath = "#{FIXTURES_DIR}/missingImageSrc.html"
50
- @imageCheck = Images.new(imageSrcFilepath, HTML::Proofer.create_nokogiri(imageSrcFilepath))
43
+ @imageCheck = Images.new("#{FIXTURES_DIR}", imageSrcFilepath, HTML::Proofer.create_nokogiri(imageSrcFilepath))
51
44
  @imageCheck.run
52
45
  @imageCheck.issues[0].should eq("spec/html/proofer/fixtures/missingImageSrc.html".blue + ": image has no src attribute")
53
46
  end
54
47
 
55
48
  it "fails for image with default mac filename" do
56
49
  terribleImageName = "#{FIXTURES_DIR}/terribleImageName.html"
57
- @imageCheck = Images.new(terribleImageName, HTML::Proofer.create_nokogiri(terribleImageName))
50
+ @imageCheck = Images.new("#{FIXTURES_DIR}", terribleImageName, HTML::Proofer.create_nokogiri(terribleImageName))
58
51
  @imageCheck.run
59
52
  @imageCheck.issues[0].should eq("spec/html/proofer/fixtures/terribleImageName.html".blue + ": image has a terrible filename (./Screen Shot 2012-08-09 at 7.51.18 AM.png)")
60
53
  end
@@ -4,21 +4,21 @@ describe "Links tests" do
4
4
 
5
5
  it "fails for broken external hash (even if the file exists)" do
6
6
  brokenHashExternalFilepath = "#{FIXTURES_DIR}/brokenHashExternal.html"
7
- @linkCheck = Links.new(brokenHashExternalFilepath, HTML::Proofer.create_nokogiri(brokenHashExternalFilepath))
7
+ @linkCheck = Links.new("#{FIXTURES_DIR}", brokenHashExternalFilepath, HTML::Proofer.create_nokogiri(brokenHashExternalFilepath))
8
8
  @linkCheck.run
9
9
  @linkCheck.issues[1].should eq("spec/html/proofer/fixtures/brokenHashExternal.html".blue + ": linking to ./missingImageAlt.html#asdfasfdkafl, but asdfasfdkafl does not exist")
10
10
  end
11
11
 
12
12
  it "fails for broken internal hash" do
13
13
  brokenHashInternalFilepath = "#{FIXTURES_DIR}/brokenHashInternal.html"
14
- @linkCheck = Links.new(brokenHashInternalFilepath, HTML::Proofer.create_nokogiri(brokenHashInternalFilepath))
14
+ @linkCheck = Links.new("#{FIXTURES_DIR}", brokenHashInternalFilepath, HTML::Proofer.create_nokogiri(brokenHashInternalFilepath))
15
15
  @linkCheck.run
16
- @linkCheck.issues[0].should eq("spec/html/proofer/fixtures/brokenHashInternal.html".blue + ": linking to an internal hash called noHash that does not exist")
16
+ @linkCheck.issues[0].should eq("spec/html/proofer/fixtures/brokenHashInternal.html".blue + ": linking to internal hash #noHash that does not exist")
17
17
  end
18
18
 
19
19
  it "fails for broken external links" do
20
20
  brokenLinkExternalFilepath = "#{FIXTURES_DIR}/brokenLinkExternal.html"
21
- @linkCheck = Links.new(brokenLinkExternalFilepath, HTML::Proofer.create_nokogiri(brokenLinkExternalFilepath))
21
+ @linkCheck = Links.new("#{FIXTURES_DIR}", brokenLinkExternalFilepath, HTML::Proofer.create_nokogiri(brokenLinkExternalFilepath))
22
22
  @linkCheck.run
23
23
  @linkCheck.hydra.run
24
24
  @linkCheck.issues[0].sub!(/ #<Typhoeus::Response:[\w]+>/, "")
@@ -27,49 +27,56 @@ describe "Links tests" do
27
27
 
28
28
  it "fails for broken internal links" do
29
29
  brokenLinkInternalFilepath = "#{FIXTURES_DIR}/brokenLinkInternal.html"
30
- @linkCheck = Links.new(brokenLinkInternalFilepath, HTML::Proofer.create_nokogiri(brokenLinkInternalFilepath))
30
+ @linkCheck = Links.new("#{FIXTURES_DIR}", brokenLinkInternalFilepath, HTML::Proofer.create_nokogiri(brokenLinkInternalFilepath))
31
31
  @linkCheck.run
32
- @linkCheck.issues[0].should eq("spec/html/proofer/fixtures/brokenLinkInternal.html".blue + ": internally linking to spec/html/proofer/fixtures/./notreal.html, which does not exist")
32
+ @linkCheck.issues[0].should eq("spec/html/proofer/fixtures/brokenLinkInternal.html".blue + ": internally linking to ./notreal.html, which does not exist")
33
33
  end
34
34
 
35
35
  it "fails for link with no href" do
36
36
  missingLinkHrefFilepath = "#{FIXTURES_DIR}/missingLinkHref.html"
37
- @linkCheck = Links.new(missingLinkHrefFilepath, HTML::Proofer.create_nokogiri(missingLinkHrefFilepath))
37
+ @linkCheck = Links.new("#{FIXTURES_DIR}", missingLinkHrefFilepath, HTML::Proofer.create_nokogiri(missingLinkHrefFilepath))
38
38
  @linkCheck.run
39
39
  @linkCheck.issues[0].should eq("spec/html/proofer/fixtures/missingLinkHref.html".blue + ": link has no href attribute")
40
40
  end
41
41
 
42
42
  it "should follow redirects" do
43
43
  linkWithRedirectFilepath = "#{FIXTURES_DIR}/linkWithRedirect.html"
44
- @linkCheck = Links.new(linkWithRedirectFilepath, HTML::Proofer.create_nokogiri(linkWithRedirectFilepath))
44
+ @linkCheck = Links.new("#{FIXTURES_DIR}", linkWithRedirectFilepath, HTML::Proofer.create_nokogiri(linkWithRedirectFilepath))
45
45
  @linkCheck.run
46
46
  @linkCheck.issues[0].should eq(nil)
47
47
  end
48
48
 
49
49
  it "should understand https" do
50
50
  linkWithHttpsFilepath = "#{FIXTURES_DIR}/linkWithHttps.html"
51
- @linkCheck = Links.new(linkWithHttpsFilepath, HTML::Proofer.create_nokogiri(linkWithHttpsFilepath))
51
+ @linkCheck = Links.new("#{FIXTURES_DIR}", linkWithHttpsFilepath, HTML::Proofer.create_nokogiri(linkWithHttpsFilepath))
52
52
  @linkCheck.run
53
53
  @linkCheck.issues[0].should eq(nil)
54
54
  end
55
55
 
56
56
  it "fails for broken hash links with status code numbers" do
57
57
  brokenLinkWithNumberFilepath = "#{FIXTURES_DIR}/brokenLinkWithNumber.html"
58
- @linkCheck = Links.new(brokenLinkWithNumberFilepath, HTML::Proofer.create_nokogiri(brokenLinkWithNumberFilepath))
58
+ @linkCheck = Links.new("#{FIXTURES_DIR}", brokenLinkWithNumberFilepath, HTML::Proofer.create_nokogiri(brokenLinkWithNumberFilepath))
59
59
  @linkCheck.run
60
- @linkCheck.issues[0].should eq(nil)
60
+ @linkCheck.issues[0].should eq("\e[34mspec/html/proofer/fixtures/brokenLinkWithNumber.html\e[0m: linking to internal hash #25-method-not-allowed that does not exist")
61
61
  end
62
62
 
63
63
  it 'properly resolves implicit /index.html in link paths' do
64
64
  linkToFolder = "#{FIXTURES_DIR}/linkToFolder.html"
65
- @linkCheck = Links.new(linkToFolder, HTML::Proofer.create_nokogiri(linkToFolder))
65
+ @linkCheck = Links.new("#{FIXTURES_DIR}", linkToFolder, HTML::Proofer.create_nokogiri(linkToFolder))
66
66
  @linkCheck.run
67
67
  @linkCheck.issues[0].should eq(nil)
68
68
  end
69
69
 
70
70
  it 'properly checks links to root' do
71
71
  rootLink = "#{FIXTURES_DIR}/rootLink.html"
72
- @linkCheck = Links.new(rootLink, HTML::Proofer.create_nokogiri(rootLink))
72
+ @linkCheck = Links.new("#{FIXTURES_DIR}", rootLink, HTML::Proofer.create_nokogiri(rootLink))
73
+ @linkCheck.run
74
+ @linkCheck.issues[0].should eq(nil)
75
+ end
76
+
77
+ it 'properly checks relative links' do
78
+ relativeLinks = "#{FIXTURES_DIR}/relativeLinks.html"
79
+ @linkCheck = Links.new("#{FIXTURES_DIR}", relativeLinks, HTML::Proofer.create_nokogiri(relativeLinks))
73
80
  @linkCheck.run
74
81
  @linkCheck.issues[0].should eq(nil)
75
82
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-proofer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-09 00:00:00.000000000 Z
11
+ date: 2013-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -112,6 +112,7 @@ files:
112
112
  - lib/html-proofer.rb
113
113
  - lib/html/proofer.rb
114
114
  - lib/html/proofer/check.rb
115
+ - lib/html/proofer/checkable.rb
115
116
  - lib/html/proofer/checks.rb
116
117
  - lib/html/proofer/checks/images.rb
117
118
  - lib/html/proofer/checks/links.rb
@@ -119,10 +120,12 @@ files:
119
120
  - spec/html/proofer/fixtures/Screen Shot 2012-08-09 at 7.51.18 AM.png
120
121
  - spec/html/proofer/fixtures/brokenHashExternal.html
121
122
  - spec/html/proofer/fixtures/brokenHashInternal.html
123
+ - spec/html/proofer/fixtures/brokenInternalLink.html
122
124
  - spec/html/proofer/fixtures/brokenLinkExternal.html
123
125
  - spec/html/proofer/fixtures/brokenLinkInternal.html
124
126
  - spec/html/proofer/fixtures/brokenLinkWithNumber.html
125
127
  - spec/html/proofer/fixtures/existingImageExternal.html
128
+ - spec/html/proofer/fixtures/folder/anchorLink.html
126
129
  - spec/html/proofer/fixtures/folder/index.html
127
130
  - spec/html/proofer/fixtures/gpl.png
128
131
  - spec/html/proofer/fixtures/index.html
@@ -131,11 +134,12 @@ files:
131
134
  - spec/html/proofer/fixtures/linkWithRedirect.html
132
135
  - spec/html/proofer/fixtures/missingImageAlt.html
133
136
  - spec/html/proofer/fixtures/missingImageAltText.html
134
- - spec/html/proofer/fixtures/missingImageDirPrefix.html
135
137
  - spec/html/proofer/fixtures/missingImageExternal.html
136
138
  - spec/html/proofer/fixtures/missingImageInternal.html
137
139
  - spec/html/proofer/fixtures/missingImageSrc.html
138
140
  - spec/html/proofer/fixtures/missingLinkHref.html
141
+ - spec/html/proofer/fixtures/notarealhash.html
142
+ - spec/html/proofer/fixtures/relativeLinks.html
139
143
  - spec/html/proofer/fixtures/rootLink.html
140
144
  - spec/html/proofer/fixtures/terribleImageName.html
141
145
  - spec/html/proofer/images_spec.rb
@@ -172,10 +176,12 @@ test_files:
172
176
  - spec/html/proofer/fixtures/Screen Shot 2012-08-09 at 7.51.18 AM.png
173
177
  - spec/html/proofer/fixtures/brokenHashExternal.html
174
178
  - spec/html/proofer/fixtures/brokenHashInternal.html
179
+ - spec/html/proofer/fixtures/brokenInternalLink.html
175
180
  - spec/html/proofer/fixtures/brokenLinkExternal.html
176
181
  - spec/html/proofer/fixtures/brokenLinkInternal.html
177
182
  - spec/html/proofer/fixtures/brokenLinkWithNumber.html
178
183
  - spec/html/proofer/fixtures/existingImageExternal.html
184
+ - spec/html/proofer/fixtures/folder/anchorLink.html
179
185
  - spec/html/proofer/fixtures/folder/index.html
180
186
  - spec/html/proofer/fixtures/gpl.png
181
187
  - spec/html/proofer/fixtures/index.html
@@ -184,11 +190,12 @@ test_files:
184
190
  - spec/html/proofer/fixtures/linkWithRedirect.html
185
191
  - spec/html/proofer/fixtures/missingImageAlt.html
186
192
  - spec/html/proofer/fixtures/missingImageAltText.html
187
- - spec/html/proofer/fixtures/missingImageDirPrefix.html
188
193
  - spec/html/proofer/fixtures/missingImageExternal.html
189
194
  - spec/html/proofer/fixtures/missingImageInternal.html
190
195
  - spec/html/proofer/fixtures/missingImageSrc.html
191
196
  - spec/html/proofer/fixtures/missingLinkHref.html
197
+ - spec/html/proofer/fixtures/notarealhash.html
198
+ - spec/html/proofer/fixtures/relativeLinks.html
192
199
  - spec/html/proofer/fixtures/rootLink.html
193
200
  - spec/html/proofer/fixtures/terribleImageName.html
194
201
  - spec/html/proofer/images_spec.rb
@@ -1,9 +0,0 @@
1
- <html>
2
-
3
- <body>
4
-
5
- <p>Blah blah blah. <img alt="A broken image, due to dir prefix" src="/gpl.png" /> </p>
6
-
7
- </body>
8
-
9
- </html>