site_checker 0.1.1 → 0.2.0.pre

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.
@@ -0,0 +1,22 @@
1
+ module IoSpecHelper
2
+ def webmock(uri, status, content)
3
+ stub_request(:get, uri).
4
+ with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
5
+ to_return(:status => status, :body => content)
6
+ end
7
+
8
+ def filesystemmock(uri, content)
9
+ FileUtils.mkdir_p(File.dirname(File.join(fs_test_path, uri)))
10
+ File.open(File.join(fs_test_path, uri), "w") do |f|
11
+ f.write(content)
12
+ end
13
+ end
14
+
15
+ def clean_fs_test_path
16
+ FileUtils.rm_rf(fs_test_path)
17
+ end
18
+
19
+ def fs_test_path
20
+ "test_data_public"
21
+ end
22
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe SiteChecker::LinkCollector do
4
+ context "#check" do
5
+ before(:each) do
6
+ @test_url = "http://localhost:4000"
7
+ @root = "http://localhost:4000"
8
+ @collector = SiteChecker::LinkCollector.new do |config|
9
+ config.visit_references = true
10
+ end
11
+ end
12
+
13
+ it "should check a link only once" do
14
+ content = "<html>text<a href=\"http://external.org/\"/><a href=\"http://external.org/\"/></html>"
15
+ content_reader = mock()
16
+ @collector.should_receive(:get_content_reader).and_return(content_reader)
17
+ localhost = create_link("http://localhost:4000")
18
+ external = create_link("http://external.org/")
19
+ content_reader.should_receive(:get).with(localhost).and_return(content)
20
+ content_reader.should_receive(:get).with(external)
21
+ @collector.check(@test_url, @root)
22
+ end
23
+
24
+ it "should stop recursion when configured depth is reached" do
25
+ @collector = SiteChecker::LinkCollector.new do |config|
26
+ config.max_recursion_depth = 2
27
+ end
28
+ content = "<html>text<a href=\"/one-level-down\"/></html>"
29
+ one_level_down_content = "<html><a href=\"/two-levels-down\"/></html>"
30
+ two_levels_down_content = "<html><a href=\"/three-levels-down\"/></html>"
31
+ three_levels_down_content = "<html></html>"
32
+ content_reader = mock()
33
+ @collector.should_receive(:get_content_reader).and_return(content_reader)
34
+ content_reader.should_receive(:get).with(create_link(@test_url)).and_return(content)
35
+ content_reader.should_receive(:get).with(create_link("/one-level-down")).and_return(one_level_down_content)
36
+ content_reader.should_receive(:get).with(create_link("/two-levels-down")).and_return(two_levels_down_content)
37
+ @collector.check(@test_url, @root)
38
+ @collector.problems.should be_empty
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe SiteChecker::Link do
4
+ context "#create" do
5
+ it "should create a link with attribute list" do
6
+ link = SiteChecker::Link.create({:kind => :page, :location => "location"})
7
+ link.kind.should eql(:page)
8
+ link.location.should eql("location")
9
+ end
10
+ end
11
+
12
+ context "#has_problem?" do
13
+ it "should return true if there are no problem with the link" do
14
+ SiteChecker::Link.create({}).has_problem?.should be_false
15
+ end
16
+
17
+ it "should return false if there are problems with the link" do
18
+ SiteChecker::Link.create({:problem => "grr"}).has_problem?.should be_true
19
+ end
20
+ end
21
+
22
+ context "#anchor?" do
23
+ it "should return true for an anchor" do
24
+ SiteChecker::Link.create({:kind => :anchor}).anchor?.should be_true
25
+ end
26
+
27
+ it "should return false for non anchor" do
28
+ SiteChecker::Link.create({:kind => :page}).anchor?.should be_false
29
+ end
30
+ end
31
+
32
+ context "#anchor_ref?" do
33
+ it "should return true for an anchor_ref" do
34
+ SiteChecker::Link.create({:kind => :anchor_ref}).anchor_ref?.should be_true
35
+ end
36
+
37
+ it "should return false for non anchor ref" do
38
+ SiteChecker::Link.create({:kind => :page}).anchor_ref?.should be_false
39
+ end
40
+ end
41
+
42
+ context "#anchor_related?" do
43
+ it "should return true for an anchor_ref" do
44
+ SiteChecker::Link.create({:kind => :anchor_ref}).anchor_related?.should be_true
45
+ SiteChecker::Link.create({:kind => :anchor}).anchor_related?.should be_true
46
+ end
47
+
48
+ it "should return false for non anchor ref" do
49
+ SiteChecker::Link.create({:kind => :page}).anchor_related?.should be_false
50
+ end
51
+ end
52
+
53
+ context "#local_page?" do
54
+ it "should return true if the page is local" do
55
+ SiteChecker::Link.create({:kind => :page, :location => :local}).local_page?.should be_true
56
+ end
57
+
58
+ it "should return false if the page is local or not a page at all" do
59
+ SiteChecker::Link.create({:kind => :page, :location => :remote}).local_page?.should be_false
60
+ SiteChecker::Link.create({:kind => :image, :location => :local}).local_page?.should be_false
61
+ end
62
+ end
63
+
64
+ context "#local_image?" do
65
+ it "should return true if the image is local" do
66
+ SiteChecker::Link.create({:kind => :image, :location => :local}).local_image?.should be_true
67
+ end
68
+
69
+ it "should return false if the image is local or not an image at all" do
70
+ SiteChecker::Link.create({:kind => :image, :location => :remote}).local_image?.should be_false
71
+ SiteChecker::Link.create({:kind => :page, :location => :local}).local_image?.should be_false
72
+ end
73
+ end
74
+
75
+ context "#eql" do
76
+ it "should return true if the urls are equal" do
77
+ link1 = SiteChecker::Link.create({:url => "url"})
78
+ link2 = SiteChecker::Link.create({:url => "url"})
79
+ link1.should eql(link2)
80
+ end
81
+
82
+ it "should find the link in a collection" do
83
+ link1 = SiteChecker::Link.create({:url => "url"})
84
+ link2 = SiteChecker::Link.create({:url => "url"})
85
+ [link1, link2].should include(link1)
86
+ end
87
+
88
+ it "should ignore trailing '/'" do
89
+ link1 = SiteChecker::Link.create({:url => "/url"})
90
+ link2 = SiteChecker::Link.create({:url => "url"})
91
+ link1.should eql(link2)
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+ require_relative 'parse_spec_helper'
3
+
4
+ describe SiteChecker::Parse::Page do
5
+ include ParseSpecHelper
6
+ context "#parse" do
7
+ before(:each) do
8
+ @root = "http://localhost:4000"
9
+ end
10
+
11
+ it "should return the containing local links" do
12
+ content = "<html><a href=\"link1\">link</a>text<a href=\"link2\">link</a></html>"
13
+ links = SiteChecker::Parse::Page.parse(content, [], @root)
14
+ links.should eql([create_link("link1"), create_link("link2")])
15
+ assert_link(links[0], :page, :local, false)
16
+ assert_link(links[1], :page, :local, false)
17
+ end
18
+
19
+ it "should return the containing local images" do
20
+ content = "<html><img src=\"image1\"></img>link</a>text<img src=\"image2\"></img></html>"
21
+ links = SiteChecker::Parse::Page.parse(content, [], @root)
22
+ links.should eql([create_link("image1"), create_link("image2")])
23
+ assert_link(links[0], :image, :local, false)
24
+ assert_link(links[1], :image, :local, false)
25
+ end
26
+
27
+ it "should return an anchor with its anchor reference" do
28
+ content = "<html><a href=\"#goto\">link</a>text<a id=\"goto\"></a></html>"
29
+ links = SiteChecker::Parse::Page.parse(content, [], @root)
30
+ links.should eql([create_link("#goto"), create_link("goto")])
31
+ assert_link(links[0], :anchor_ref, :local, false)
32
+ assert_link(links[1], :anchor, nil, false)
33
+ end
34
+
35
+ it "should mark an absolute link" do
36
+ content = "<html><a href=\"#{@root}/link1\">link</a>text</html>"
37
+ links = SiteChecker::Parse::Page.parse(content, [], @root)
38
+ links.should eql([create_link("#{@root}/link1")])
39
+ assert_link(links[0], :page, :local, true, "(absolute path)")
40
+ end
41
+
42
+ it "should return a remote link" do
43
+ content = "<html><a href=\"http://example.org\">link</a>text</html>"
44
+ links = SiteChecker::Parse::Page.parse(content, [], @root)
45
+ links.should eql([create_link("http://example.org")])
46
+ assert_link(links[0], :page, :remote, false)
47
+ end
48
+
49
+ it "should return all kinds of links" do
50
+ content = "<html><a href=\"link1\">link</a>text<img src=\"image2\"></img></html>"
51
+ links = SiteChecker::Parse::Page.parse(content, [], @root)
52
+ links.should eql([create_link("link1"), create_link("image2")])
53
+ assert_link(links[0], :page, :local, false)
54
+ assert_link(links[1], :image, :local, false)
55
+ end
56
+
57
+ it "should not return ignored links" do
58
+ content = "<html><a href=\"link1\">link</a>text<a href=\"link2\">link</a></html>"
59
+ links = SiteChecker::Parse::Page.parse(content, ["link2"], @root)
60
+ links.should eql([create_link("link1")])
61
+ assert_link(links[0], :page, :local, false)
62
+ end
63
+
64
+ it "should return a link only once" do
65
+ content = "<html><a href=\"link1\">link</a>text<a href=\"link1\">link</a></html>"
66
+ links = SiteChecker::Parse::Page.parse(content, [], @root)
67
+ links.should eql([create_link("link1")])
68
+ assert_link(links[0], :page, :local, false)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,8 @@
1
+ module ParseSpecHelper
2
+ def assert_link(link, kind, location, has_problem, problem=nil)
3
+ link.kind.should eql(kind)
4
+ link.location.should eql(location)
5
+ link.has_problem?.should eql(has_problem)
6
+ link.problem.should eql(problem) if problem
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ require 'rspec'
2
+ require 'debugger'
3
+ require 'webmock/rspec'
4
+
5
+ require File.expand_path('../../lib/site_checker', __FILE__)
6
+
7
+ # common
8
+ def create_link(url)
9
+ SiteChecker::Link.create({:url => url})
10
+ end
metadata CHANGED
@@ -1,96 +1,164 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: site_checker
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0.pre
5
+ prerelease: 6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Zsolt Fabok
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-07-18 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-12-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.12.0
22
+ type: :development
22
23
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.12.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: webmock
32
+ requirement: !ruby/object:Gem::Requirement
24
33
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 35
29
- segments:
30
- - 2
31
- - 11
32
- - 0
33
- version: 2.11.0
34
+ requirements:
35
+ - - '='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.9.0
34
38
  type: :development
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: nokogiri
38
39
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.9.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 10.0.3
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: 10.0.3
62
+ - !ruby/object:Gem::Dependency
63
+ name: yard
64
+ requirement: !ruby/object:Gem::Requirement
40
65
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 9
45
- segments:
46
- - 1
47
- - 5
48
- - 5
49
- version: 1.5.5
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.8.3
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: 0.8.3
78
+ - !ruby/object:Gem::Dependency
79
+ name: nokogiri
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - '='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.5.6
50
86
  type: :runtime
51
- version_requirements: *id002
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.5.6
52
94
  description: A simple tool for checking references on your website
53
95
  email: me@zsoltfabok.com
54
96
  executables: []
55
-
56
97
  extensions: []
57
-
58
98
  extra_rdoc_files: []
59
-
60
- files:
99
+ files:
100
+ - .rbenv-version
101
+ - .rspec
102
+ - History.md
103
+ - LICENSE
104
+ - README.md
105
+ - gem_tasks/rspec.rake
106
+ - gem_tasks/yard.rake
61
107
  - lib/site_checker.rb
108
+ - lib/site_checker/dsl.rb
109
+ - lib/site_checker/io/content_from_file_system.rb
110
+ - lib/site_checker/io/content_from_web.rb
111
+ - lib/site_checker/link.rb
112
+ - lib/site_checker/link_collector.rb
113
+ - lib/site_checker/parse/page.rb
114
+ - site_checker.gemspec
115
+ - spec/dsl_spec.rb
116
+ - spec/integration_spec.rb
117
+ - spec/site_checker/io/content_from_file_system_spec.rb
118
+ - spec/site_checker/io/content_from_web_spec.rb
119
+ - spec/site_checker/io/io_spec_helper.rb
120
+ - spec/site_checker/link_collector_spec.rb
121
+ - spec/site_checker/link_spec.rb
122
+ - spec/site_checker/parse/page_spec.rb
123
+ - spec/site_checker/parse/parse_spec_helper.rb
124
+ - spec/spec_helper.rb
62
125
  homepage: https://github.com/ZsoltFabok/site_checker
63
- licenses: []
64
-
126
+ licenses:
127
+ - BSD
65
128
  post_install_message:
66
129
  rdoc_options: []
67
-
68
- require_paths:
130
+ require_paths:
69
131
  - lib
70
- required_ruby_version: !ruby/object:Gem::Requirement
132
+ required_ruby_version: !ruby/object:Gem::Requirement
71
133
  none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ segments:
77
139
  - 0
78
- version: "0"
79
- required_rubygems_version: !ruby/object:Gem::Requirement
140
+ hash: 3689641992990100431
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
142
  none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- hash: 3
85
- segments:
86
- - 0
87
- version: "0"
143
+ requirements:
144
+ - - ! '>'
145
+ - !ruby/object:Gem::Version
146
+ version: 1.3.1
88
147
  requirements: []
89
-
90
148
  rubyforge_project:
91
- rubygems_version: 1.8.15
149
+ rubygems_version: 1.8.23
92
150
  signing_key:
93
151
  specification_version: 3
94
- summary: site_checker-0.1.1
95
- test_files: []
96
-
152
+ summary: site_checker-0.2.0.pre
153
+ test_files:
154
+ - spec/dsl_spec.rb
155
+ - spec/integration_spec.rb
156
+ - spec/site_checker/io/content_from_file_system_spec.rb
157
+ - spec/site_checker/io/content_from_web_spec.rb
158
+ - spec/site_checker/io/io_spec_helper.rb
159
+ - spec/site_checker/link_collector_spec.rb
160
+ - spec/site_checker/link_spec.rb
161
+ - spec/site_checker/parse/page_spec.rb
162
+ - spec/site_checker/parse/parse_spec_helper.rb
163
+ - spec/spec_helper.rb
164
+ has_rdoc: