utterson 0.2.0 → 0.3.2

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
- SHA1:
3
- metadata.gz: b284cf9e9272e1093bd7c4172ef0036750de59e8
4
- data.tar.gz: 512987cf376f785eb0621c7e374a002c3385cdb8
2
+ SHA256:
3
+ metadata.gz: f068f678f7ad3eace6ba4083e1fab800e571165483fd366b80807620776063ed
4
+ data.tar.gz: d20d1495a36de95ae1212e11b18f06b926da37351ef72cf06fa6ccabb7ebf20f
5
5
  SHA512:
6
- metadata.gz: e1aec6ceb0f9748d1f5e378592159e322335214a6f96987bd253e38f2c4c42b6fe9a6c52791a0b9402228e71b5653bd9dfa0760360f3bab733e3a439eeb520c3
7
- data.tar.gz: 64d65499f25e4c614995eced88b5a052c4623dbd8bbba7024abdfd512b696ecbe4d124b919eca19775e78ffaf2961e8281b2d17147732b5dbfaa9793e84131e4
6
+ metadata.gz: 424f2cdbdfa9f56bbb92b64baff326b3722ca1ec8d6c97db0f176c70ad5066918696595364544f6cf283a616f38eabdb2d4a69d68beb5235eced8ed703727234
7
+ data.tar.gz: a5ee5b1682da10e1953f5de0addc9231179d3d00fc4fd5f9877b0352d2cd1615fcf91d73b87afa74081d47f4ee76e0a9866a66450c618de990f15603ad471ba1
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  Simple utility to traverse directory of html files and check links in them.
2
2
 
3
- [![Build Status](https://travis-ci.org/iiska/utterson.png)](https://travis-ci.org/iiska/utterson) [![Dependency Status](https://gemnasium.com/iiska/utterson.png)](https://gemnasium.com/iiska/utterson)
3
+ [![Gem Version](https://badge.fury.io/rb/utterson.png)](http://badge.fury.io/rb/utterson)
4
+ [![Tests](https://github.com/iiska/utterson/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/iiska/utterson/actions/workflows/ci.yml)
5
+
4
6
 
5
7
  ## Getting started
6
8
 
@@ -27,4 +29,4 @@ Hyde](https://en.wikipedia.org/wiki/Strange_Case_of_Dr_Jekyll_and_Mr_Hyde).
27
29
 
28
30
  ## License
29
31
 
30
- Released under the [MIT License](http://www.opensource.org/licenses/MIT)
32
+ Released under the [MIT License](http://www.opensource.org/licenses/MIT)
data/bin/utterson CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  $:.unshift File.join(File.dirname(__FILE__), *%w{ .. lib })
4
4
 
5
- require 'trollop'
5
+ require 'optimist'
6
6
  require 'utterson'
7
7
 
8
- opts = Trollop::options do
8
+ opts = Optimist::options do
9
9
  opt :root, "Root directory for the site if it differs from target dir", type: :string
10
10
  end
11
11
 
data/lib/utterson/base.rb CHANGED
@@ -1,6 +1,10 @@
1
+ require 'ruby-progressbar'
2
+
1
3
  require 'utterson/html_check'
2
4
 
3
5
  module Utterson
6
+ # Base implements initialization of the checking process and handles
7
+ # outputting final results.
4
8
  class Base
5
9
  attr_reader :errors
6
10
 
@@ -13,15 +17,16 @@ module Utterson
13
17
  end
14
18
 
15
19
  def check
20
+ bar = ProgressBar.create
16
21
  threads = []
17
22
  Dir.glob(File.join(@dir, '**/*.{html,htm}')) do |f|
18
23
  @stats[:files] += 1
19
- puts "Checking file #{f}"
24
+ bar.total = @stats[:files]
20
25
  c = HtmlCheck.new(file: f, root: @root)
21
26
  c.when_done do |r|
27
+ bar.increment
22
28
  @stats[:urls] = r[:urls]
23
29
  @errors.merge! r[:errors]
24
- puts "Check done with #{f}"
25
30
  end
26
31
  threads << c.run
27
32
  end
@@ -42,7 +47,8 @@ module Utterson
42
47
  if count == 0
43
48
  puts "#{@stats[:files]} files with #{@stats[:urls]} urls checked."
44
49
  else
45
- puts "#{@stats[:files]} files with #{@stats[:urls]} urls checked and #{count} errors found."
50
+ puts "Q{#{@stats[:files]} files with #{@stats[:urls]} urls checked "+
51
+ "and #{count} errors found."
46
52
  end
47
53
  end
48
54
  end
@@ -5,6 +5,8 @@ require 'timeout'
5
5
  require 'thread'
6
6
 
7
7
  module Utterson
8
+ # Handle collecting URIs from HTML documents and both remote and
9
+ # local checking of them.
8
10
  class HtmlCheck
9
11
  attr_reader :errors
10
12
 
@@ -61,23 +63,18 @@ module Utterson
61
63
  end
62
64
 
63
65
  def check_remote_uri(url, file)
64
- begin
65
- uri = URI(url.gsub(/^\/\//, 'http://'))
66
- rescue URI::InvalidURIError => e
67
- return add_error(file, uri.to_s, e.message)
66
+ uri = URI(url.gsub(/^\/\//, 'http://'))
67
+
68
+ response = Net::HTTP.start(uri.host, uri.port,
69
+ :use_ssl => uri.scheme == 'https') do |http|
70
+ http.head uri.path.empty? ? "/" : uri.path
68
71
  end
69
- begin
70
- response = Net::HTTP.start(uri.host, uri.port,
71
- :use_ssl => uri.scheme == 'https') do |http|
72
- p = uri.path.empty? ? "/" : uri.path
73
- http.head(p)
74
- end
75
- if response.code =~ /^[^23]/
76
- add_error(file, uri.to_s, response)
77
- end
78
- rescue => e
79
- add_error(file, uri.to_s, e.message)
72
+ if response.code =~ /^[^23]/
73
+ add_error(file, uri.to_s, response)
80
74
  end
75
+
76
+ rescue => e
77
+ add_error(file, uri.to_s, e.message)
81
78
  end
82
79
 
83
80
  def check_local_uri(url, file)
@@ -87,7 +84,7 @@ module Utterson
87
84
  else
88
85
  path = File.expand_path(url, File.dirname(file))
89
86
  end
90
- add_error(file, url, "File not found") unless File.exists? path
87
+ add_error(file, url, "File not found") unless File.exist? path
91
88
  end
92
89
 
93
90
  def add_error(file, url, response)
@@ -1,3 +1,3 @@
1
1
  module Utterson
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.2'
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'webmock/rspec'
4
4
 
5
5
  require 'simplecov'
6
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
6
7
  SimpleCov.start
7
8
 
8
9
  require 'utterson'
@@ -11,7 +11,7 @@ module Utterson
11
11
  "spec/fixtures/dir-structure/2.html",
12
12
  "spec/fixtures/dir-structure/a/3.htm",
13
13
  "spec/fixtures/dir-structure/a/b/4.html"].each do |file|
14
- HtmlCheck.should_receive(:new).with(file: file, root: dir)
14
+ expect(HtmlCheck).to receive(:new).with(file: file, root: dir)
15
15
  end
16
16
 
17
17
  u.check
@@ -23,7 +23,7 @@ module Utterson
23
23
  output = capture_stdout do
24
24
  u.check
25
25
  end
26
- output.should match(/4 files with 0 urls checked/)
26
+ expect(output).to match(/4 files with 0 urls checked/)
27
27
  end
28
28
 
29
29
  it "should output error information" do
@@ -34,11 +34,12 @@ module Utterson
34
34
  output = capture_stdout do
35
35
  u.check
36
36
  end
37
- output.should match("spec/fixtures/sample.html\n\tstyle.css\n\t\tFile not found")
38
- output.should match("script.js\n\t\tFile not found")
39
- output.should match("image.jpg\n\t\tFile not found")
40
- output.should match("http://example.com\n\t\tHTTP 404")
41
- output.should match("5 files with 4 urls checked and 4 errors found")
37
+ expect(output).to match("spec/fixtures/sample.html\n\tstyle.css\n"+
38
+ "\t\tFile not found")
39
+ expect(output).to match("script.js\n\t\tFile not found")
40
+ expect(output).to match("image.jpg\n\t\tFile not found")
41
+ expect(output).to match("http://example.com\n\t\tHTTP 404")
42
+ expect(output).to match("5 files with 4 urls checked and 4 errors found")
42
43
  end
43
44
  end
44
45
  end
@@ -18,10 +18,10 @@ module Utterson
18
18
  it "should find all uris from sample document" do
19
19
  h = HtmlCheck.new(file: sample_file)
20
20
  uris = h.collect_uris_from(sample_file)
21
- uris.should include("script.js")
22
- uris.should include("style.css")
23
- uris.should include("http://example.com")
24
- uris.should include("image.jpg")
21
+ expect(uris).to include("script.js")
22
+ expect(uris).to include("style.css")
23
+ expect(uris).to include("http://example.com")
24
+ expect(uris).to include("image.jpg")
25
25
  end
26
26
 
27
27
  describe "#check_uri" do
@@ -65,36 +65,36 @@ module Utterson
65
65
  end
66
66
  end
67
67
 
68
- describe "#check_local_uri" do
68
+ describe "#check_relative_uri" do
69
69
  let(:h) {HtmlCheck.new(root: "spec/fixtures/dir-structure")}
70
70
  let(:html_file) {"spec/fixtures/dir-structure/1.htm"}
71
71
 
72
72
  it "should not assign error info if file exists" do
73
73
  h.check_local_uri("../sample.html", html_file)
74
- h.errors.should be_empty
74
+ expect(h.errors).to be_empty
75
75
  end
76
76
 
77
77
  it "should assign error info if file doesn't exist" do
78
78
  url = "../sample_not_found.html"
79
79
  h.check_local_uri(url, html_file)
80
- h.errors[html_file].should == {url => "File not found"}
80
+ expect(h.errors[html_file]).to eq({url => "File not found"})
81
81
  end
82
82
 
83
83
  it "should use root directory when urls start with /" do
84
84
  h2 = HtmlCheck.new(file: html_file,
85
85
  root: "spec/fixtures")
86
86
  h2.check_local_uri("/sample.html", html_file)
87
- h2.errors.should be_empty
87
+ expect(h2.errors).to be_empty
88
88
  end
89
89
 
90
- it "should handle target directory as root for urls starting with / if root is no available" do
90
+ it "uses target directory as root if undefined when url starts with /" do
91
91
  h.check_local_uri("/2.html", html_file)
92
- h.errors.should be_empty
92
+ expect(h.errors).to be_empty
93
93
  end
94
94
 
95
95
  it "should ignore query string when checking local files" do
96
96
  h.check_local_uri("2.html?queryparam=value", html_file)
97
- h.errors.should be_empty
97
+ expect(h.errors).to be_empty
98
98
  end
99
99
  end
100
100
 
@@ -108,7 +108,7 @@ module Utterson
108
108
  with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
109
109
  to_return(:status => 200, :body => "", :headers => {})
110
110
  h.check_remote_uri(url, html_file)
111
- h.errors.should be_empty
111
+ expect(h.errors).to be_empty
112
112
  end
113
113
 
114
114
  it "should assign error info if there is error response" do
@@ -116,40 +116,38 @@ module Utterson
116
116
  with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
117
117
  to_return(:status => 404, :body => "", :headers => {})
118
118
  h.check_remote_uri(url, html_file)
119
- puts h.errors.inspect
120
- h.errors[html_file].should_not be_empty
121
- h.errors[html_file][url].instance_of?(Net::HTTPNotFound).should be_true
119
+ expect(h.errors[html_file]).not_to be_empty
120
+ expect(h.errors[html_file][url].instance_of?(Net::HTTPNotFound)).to be_truthy
122
121
  end
123
122
 
124
123
  it "should add error status from buffer timeouts" do
125
124
  stub_request(:head, url).to_timeout
126
125
  h.check_remote_uri(url, html_file)
127
- h.errors.should_not be_empty
126
+ expect(h.errors).not_to be_empty
128
127
  end
129
128
 
130
129
  it "should add error status from connection timeouts" do
131
130
  stub_request(:head, url).to_raise(Errno::ETIMEDOUT)
132
131
  h.check_remote_uri(url, html_file)
133
- h.errors.should_not be_empty
132
+ expect(h.errors).not_to be_empty
134
133
  end
135
134
 
136
135
  it "should add error status from 'No route to host' errors" do
137
136
  stub_request(:head, url).to_raise(Errno::EHOSTUNREACH)
138
137
  h.check_remote_uri(url, html_file)
139
- h.errors.should_not be_empty
138
+ expect(h.errors).not_to be_empty
140
139
  end
141
140
 
142
141
  it "shoud add error status from name resolution errors" do
143
142
  stub_request(:head, url).
144
143
  to_raise(SocketError.new('getaddrinfo: Name or service not known'))
145
144
  h.check_remote_uri(url, html_file)
146
- h.errors.should_not be_empty
145
+ expect(h.errors).not_to be_empty
147
146
  end
148
147
 
149
148
  it "shoud add error status when invalid URI" do
150
- URI.stub(:new).and_raise(URI::InvalidURIError)
151
- h.check_remote_uri("http://invalid_uri", html_file)
152
- h.errors.should_not be_empty
149
+ h.check_remote_uri(":", html_file)
150
+ expect(h.errors).not_to be_empty
153
151
  end
154
152
  end
155
153
  end
metadata CHANGED
@@ -1,99 +1,127 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utterson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juhamatti Niemelä
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-07 00:00:00.000000000 Z
11
+ date: 2023-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: trollop
14
+ name: optimist
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 1.14.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 1.14.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby-progressbar
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.13.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.13.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '1.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '1.12'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rake
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - '>='
73
+ - - ">="
46
74
  - !ruby/object:Gem::Version
47
75
  version: '0'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - '>='
80
+ - - ">="
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rspec
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
- - - '>='
87
+ - - ">="
60
88
  - !ruby/object:Gem::Version
61
89
  version: '0'
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - '>='
94
+ - - ">="
67
95
  - !ruby/object:Gem::Version
68
96
  version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: simplecov
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
- - - '>='
101
+ - - ">="
74
102
  - !ruby/object:Gem::Version
75
103
  version: '0'
76
104
  type: :development
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
- - - '>='
108
+ - - ">="
81
109
  - !ruby/object:Gem::Version
82
110
  version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: webmock
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
- - - ~>
115
+ - - "~>"
88
116
  - !ruby/object:Gem::Version
89
- version: 1.15.2
117
+ version: 3.18.0
90
118
  type: :development
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
- - - ~>
122
+ - - "~>"
95
123
  - !ruby/object:Gem::Version
96
- version: 1.15.2
124
+ version: 3.18.0
97
125
  description: Traverses all HTML files from given directory and checks links found
98
126
  in them.
99
127
  email: iiska@iki.fi
@@ -102,20 +130,20 @@ executables:
102
130
  extensions: []
103
131
  extra_rdoc_files: []
104
132
  files:
133
+ - README.md
105
134
  - bin/utterson
135
+ - lib/utterson.rb
136
+ - lib/utterson/base.rb
106
137
  - lib/utterson/html_check.rb
107
138
  - lib/utterson/version.rb
108
- - lib/utterson/base.rb
109
- - lib/utterson.rb
110
- - README.md
111
- - spec/utterson/base_spec.rb
112
- - spec/utterson/html_check_spec.rb
113
- - spec/spec_helper.rb
139
+ - spec/fixtures/dir-structure/1.htm
140
+ - spec/fixtures/dir-structure/2.html
114
141
  - spec/fixtures/dir-structure/a/3.htm
115
142
  - spec/fixtures/dir-structure/a/b/4.html
116
- - spec/fixtures/dir-structure/2.html
117
- - spec/fixtures/dir-structure/1.htm
118
143
  - spec/fixtures/sample.html
144
+ - spec/spec_helper.rb
145
+ - spec/utterson/base_spec.rb
146
+ - spec/utterson/html_check_spec.rb
119
147
  homepage: https://github.com/iiska/utterson
120
148
  licenses:
121
149
  - MIT
@@ -126,27 +154,25 @@ require_paths:
126
154
  - lib
127
155
  required_ruby_version: !ruby/object:Gem::Requirement
128
156
  requirements:
129
- - - '>='
157
+ - - ">="
130
158
  - !ruby/object:Gem::Version
131
- version: 1.9.3
159
+ version: 2.7.0
132
160
  required_rubygems_version: !ruby/object:Gem::Requirement
133
161
  requirements:
134
- - - '>='
162
+ - - ">="
135
163
  - !ruby/object:Gem::Version
136
164
  version: '0'
137
165
  requirements: []
138
- rubyforge_project:
139
- rubygems_version: 2.0.3
166
+ rubygems_version: 3.4.10
140
167
  signing_key:
141
168
  specification_version: 4
142
169
  summary: Friendly HTML crawler and url checker
143
170
  test_files:
144
- - spec/utterson/base_spec.rb
145
- - spec/utterson/html_check_spec.rb
146
- - spec/spec_helper.rb
171
+ - spec/fixtures/dir-structure/1.htm
172
+ - spec/fixtures/dir-structure/2.html
147
173
  - spec/fixtures/dir-structure/a/3.htm
148
174
  - spec/fixtures/dir-structure/a/b/4.html
149
- - spec/fixtures/dir-structure/2.html
150
- - spec/fixtures/dir-structure/1.htm
151
175
  - spec/fixtures/sample.html
152
- has_rdoc:
176
+ - spec/spec_helper.rb
177
+ - spec/utterson/base_spec.rb
178
+ - spec/utterson/html_check_spec.rb