bad_link_finder 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YTkzYzA3MDcwZjBkODJiN2VmZWM0OGRlODllMzFiZGJiMGQxNjc1Yg==
5
- data.tar.gz: !binary |-
6
- ZDNmNDg2NjYwODNmN2IwNGQyNTllZGQ3Yjc2ZTY0MjU4Y2JkMTBkMA==
2
+ SHA1:
3
+ metadata.gz: 1958650ee80f6111928153181b576b6e2964450b
4
+ data.tar.gz: 74cf1cdd49ee638a65d5759dd051ad32709a5693
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NWI0NGU1MTBiMzIyZDE2MTU0YmUxNTM5MWQyZTE3YTUwZjMyZThiYTcxNzA3
10
- MjEzYWYxOWE0NTBmZjg2ZGJiYmQxZmYwMWEzNzA1NWJjNjEwM2RhMGJmZmNi
11
- MzQ2NGU3NGMxNWI0MmFlYjdlNjYxODY5N2ExZjQ3OGQ3YThiZDk=
12
- data.tar.gz: !binary |-
13
- NWEzMmE1NGRlNmUwOGVkNmY3ZDNmMTNkZjc3MzVkMTZlOTY1ZGRjY2M2YWM5
14
- NDI0ZTYxNTg0MzVlYTcwZjUyNDMwNGE5OTcxYmFkMjJiMGUxOTUzZGIxODQ1
15
- NmEzNjM5OTBhZWE1ZTk4OTgzZTBjYTU5ZmViM2Y5N2M3Y2ZlZDI=
6
+ metadata.gz: 0dbf259bf6364c615f222ec5698bf3816212373ce12dc056a5edd9ac51ec2a4daedfbd37759d7a655f7320a041f0772a80f193f1fda9e4751cedaf58a659e06a
7
+ data.tar.gz: f3049d9b48675bdbf2eddfc35cda601fdb67b75321bb96ee78299a2cbccdeb840f865b97ee8488e82cb610c1df94c70ebaa5fa2adfd14eb5d1715a655ab4748c
data/README.md CHANGED
@@ -6,8 +6,10 @@ Crawls a mirrored site and checks that all links either return a successful resp
6
6
 
7
7
  Set environment variables:
8
8
 
9
- - `MIRROR_DIR`, to the location of your mirrored site.
9
+ - `MIRROR_DIR`, to the location of your mirrored site. Local files will be read in alphabetical order.
10
10
  - `REPORT_OUTPUT_FILE`, to the location you'd like the CSV saved to.
11
11
  - `SITE_HOST`, to the full host of the live site you'd like to test against, including protocol. For example, `https://www.example.com`
12
+ - `START_FROM`, optional, specify a file on disk from which to start, e.g. `example-folder/example.html`.
13
+ Will check this file and all following files. Useful for restarting aborted runs.
12
14
 
13
15
  Then execute `bad_link_finder`.
@@ -16,7 +16,7 @@ module BadLinkFinder
16
16
  csv_file = report_path.open('w')
17
17
  csv_builder = BadLinkFinder::CSVBuilder.new(csv_file)
18
18
 
19
- BadLinkFinder::SiteChecker.new(ENV['MIRROR_DIR'], ENV['SITE_HOST'], csv_builder).run
19
+ BadLinkFinder::SiteChecker.new(ENV['MIRROR_DIR'], ENV['SITE_HOST'], csv_builder, ENV['START_FROM']).run
20
20
 
21
21
  csv_file.close
22
22
 
@@ -5,13 +5,17 @@ module BadLinkFinder
5
5
  class Site
6
6
  include Enumerable
7
7
 
8
- def initialize(mirror_dir)
8
+ def initialize(mirror_dir, start_from = nil)
9
9
  @mirror_dir = mirror_dir.is_a?(String) ? Pathname.new(mirror_dir) : mirror_dir
10
+ @start_from = start_from
10
11
  end
11
12
 
12
13
  def each
13
14
  Dir.chdir(@mirror_dir) do
14
- Dir.glob('**/*').each do |path|
15
+ paths = Dir.glob('**/*').sort
16
+ paths = paths[paths.index(@start_from)..-1] if @start_from
17
+
18
+ paths.each do |path|
15
19
  next if File.directory?(path)
16
20
  yield BadLinkFinder::Page.new(@mirror_dir, path)
17
21
  end
@@ -4,15 +4,16 @@ require 'bad_link_finder/page_checker'
4
4
 
5
5
  module BadLinkFinder
6
6
  class SiteChecker
7
- def initialize(mirror_dir, host, csv_builder)
7
+ def initialize(mirror_dir, host, csv_builder, start_from = nil)
8
8
  @mirror_dir = File.expand_path(mirror_dir)
9
9
  @host = host
10
10
  @csv_builder = csv_builder
11
+ @start_from = start_from
11
12
  @result_cache = BadLinkFinder::ResultCache.new
12
13
  end
13
14
 
14
15
  def run
15
- BadLinkFinder::Site.new(@mirror_dir).each do |page|
16
+ BadLinkFinder::Site.new(@mirror_dir, @start_from).each do |page|
16
17
  page_checker = BadLinkFinder::PageChecker.new(@host, page, @result_cache)
17
18
  puts "Checking page #{page.path} as #{page_checker.page_url}"
18
19
 
@@ -1,3 +1,3 @@
1
1
  module BadLinkFinder
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require 'test_helper'
2
2
  require 'webmock/minitest'
3
3
  require 'bad_link_finder'
4
+ require 'tempfile'
4
5
 
5
6
  describe BadLinkFinder do
6
7
 
@@ -11,17 +12,27 @@ describe BadLinkFinder do
11
12
  stub_request(:any, 'http://www.example.com/example/?test=true&redirect=http://www.example.com/in-param-url/index.html').to_return(status: 404)
12
13
 
13
14
  ENV['MIRROR_DIR'] = (FIXTURES_ROOT+'www.example.com').to_s
14
- ENV['REPORT_OUTPUT_FILE'] = (TMP_ROOT+'bad_links.csv').to_s
15
15
  ENV['SITE_HOST'] = 'http://www.example.com/'
16
+
17
+ @tempfile = Tempfile.new('bad_links.csv')
18
+ ENV['REPORT_OUTPUT_FILE'] = @tempfile.path
19
+ end
20
+
21
+ after do
22
+ @tempfile.close
23
+ @tempfile.unlink
24
+
25
+ ['MIRROR_DIR', 'REPORT_OUTPUT_FILE', 'SITE_HOST', 'START_FROM'].each { |k| ENV.delete(k) }
16
26
  end
17
27
 
18
28
  it "finds all broken links and exports to a CSV" do
19
29
  BadLinkFinder.run
20
30
 
21
- csv_string = File.read(ENV['REPORT_OUTPUT_FILE'])
31
+ csv_string = @tempfile.read
22
32
 
23
33
  assert_match 'http://www.example.com/example/relative-example', csv_string
24
34
  assert_match 'correct-article-id', csv_string
35
+ assert_match 'https://www.example.net/external-example.html', csv_string
25
36
  end
26
37
 
27
38
  it "complains if key variables are missing" do
@@ -42,4 +53,16 @@ describe BadLinkFinder do
42
53
  end
43
54
  end
44
55
 
56
+ it "starts from a specific page if requested" do
57
+ ENV['START_FROM'] = 'example/relative-example.html'
58
+
59
+ BadLinkFinder.run
60
+
61
+ csv_string = @tempfile.read
62
+
63
+ assert_match 'http://www.example.com/example/relative-example', csv_string
64
+ assert_match 'correct-article-id', csv_string
65
+ refute_match 'https://www.example.net/external-example.html', csv_string
66
+ end
67
+
45
68
  end
@@ -17,6 +17,16 @@ describe BadLinkFinder::Site do
17
17
 
18
18
  assert_same_elements site_map, BadLinkFinder::Site.new(@site_mirror).map { |page| page.path.to_s }
19
19
  end
20
+
21
+ it "starts from a specific path if given" do
22
+ site_map = [
23
+ 'example/relative-example',
24
+ ''
25
+ ]
26
+
27
+ site = BadLinkFinder::Site.new(@site_mirror, 'example/relative-example.html')
28
+ assert_equal site_map, site.map { |page| page.path.to_s }
29
+ end
20
30
  end
21
31
 
22
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bad_link_finder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elliot Crosby-McCullough
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-04 00:00:00.000000000 Z
11
+ date: 2014-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -30,40 +30,54 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '1.6'
33
+ version: '1.5'
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: '1.6'
40
+ version: '1.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: webmock
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
@@ -103,7 +117,10 @@ executables:
103
117
  extensions: []
104
118
  extra_rdoc_files: []
105
119
  files:
120
+ - LICENCE.txt
121
+ - README.md
106
122
  - bin/bad_link_finder
123
+ - lib/bad_link_finder.rb
107
124
  - lib/bad_link_finder/csv_builder.rb
108
125
  - lib/bad_link_finder/link.rb
109
126
  - lib/bad_link_finder/page.rb
@@ -112,9 +129,6 @@ files:
112
129
  - lib/bad_link_finder/site.rb
113
130
  - lib/bad_link_finder/site_checker.rb
114
131
  - lib/bad_link_finder/version.rb
115
- - lib/bad_link_finder.rb
116
- - README.md
117
- - LICENCE.txt
118
132
  - test/fixtures/www.example.com/example/index.html
119
133
  - test/fixtures/www.example.com/example/relative-example.html
120
134
  - test/fixtures/www.example.com/index.html
@@ -137,17 +151,17 @@ require_paths:
137
151
  - lib
138
152
  required_ruby_version: !ruby/object:Gem::Requirement
139
153
  requirements:
140
- - - ! '>='
154
+ - - '>='
141
155
  - !ruby/object:Gem::Version
142
156
  version: '0'
143
157
  required_rubygems_version: !ruby/object:Gem::Requirement
144
158
  requirements:
145
- - - ! '>='
159
+ - - '>='
146
160
  - !ruby/object:Gem::Version
147
161
  version: '0'
148
162
  requirements: []
149
163
  rubyforge_project:
150
- rubygems_version: 2.1.11
164
+ rubygems_version: 2.2.0
151
165
  signing_key:
152
166
  specification_version: 4
153
167
  summary: Tests links in static site mirrors