magellan 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 1
3
- :patch: 0
3
+ :patch: 1
4
4
  :major: 0
@@ -13,7 +13,7 @@ module Magellan
13
13
  failed = result.status_code.starts_with?("5") || result.status_code.starts_with?("4")
14
14
  @broken_links << result if failed
15
15
  changed
16
- notify_observers(Time.now, !failed)
16
+ notify_observers(Time.now, !failed, broken_link_message(result))
17
17
  result.absolute_linked_resources.each do |linked_resource|
18
18
  @first_linked_from[linked_resource] = result.url if !@first_linked_from.has_key?(linked_resource)
19
19
  end
@@ -24,7 +24,11 @@ module Magellan
24
24
  end
25
25
 
26
26
  def failure_message
27
- @broken_links.map{|broken_link| "#{broken_link.url} first linked from: #{@first_linked_from[broken_link.url]} returned: #{broken_link.status_code}"}.join("\n")
27
+ @broken_links.map{|broken_link| broken_link_message(broken_link)}.join("\n")
28
+ end
29
+
30
+ def broken_link_message(broken_link)
31
+ "#{broken_link.url} first linked from: #{@first_linked_from[broken_link.url]} returned: #{broken_link.status_code}"
28
32
  end
29
33
  end
30
34
  end
@@ -14,8 +14,9 @@ module Magellan
14
14
  patterns_that_apply(result).each do |pattern,expectation|
15
15
  passed = result.linked_resources.include?(expectation)
16
16
  changed
17
- notify_observers(Time.now, passed)
18
- @errors << "#{result.url} did not contain a link to #{expectation}" unless passed
17
+ message = "#{result.url} did not contain a link to #{expectation}"
18
+ notify_observers(Time.now, passed, message)
19
+ @errors << message unless passed
19
20
  end
20
21
  end
21
22
  end
@@ -43,7 +44,7 @@ module Magellan
43
44
  end
44
45
 
45
46
  def unmet_expecations_messages
46
- message = "\n\n"
47
+ message = ""
47
48
  unmet_expecations.each {|pattern,unmet_expecation| message << "#{pattern} was never evaluted during the crawl\n"}
48
49
  message
49
50
  end
@@ -34,7 +34,7 @@ module Magellan
34
34
  rescue WWW::Mechanize::ResponseCodeError => the_error
35
35
  Explorer.create_result(url, url, the_error.response_code, [],UNKNOWN_CONTENT)
36
36
  rescue Timeout::Error
37
- Explorer.create_result(url, url, "505", [],UNKNOWN_CONTENT)
37
+ Explorer.create_result(url, url, "504", [],UNKNOWN_CONTENT)
38
38
  end
39
39
  end
40
40
 
@@ -1,8 +1,13 @@
1
1
  module Magellan
2
2
  class Logger
3
- def update(time,result)
4
- $stdout.putc(result ? '.' : 'F')
3
+ def initialize(file_name=nil)
4
+ @file_name = file_name
5
+ end
6
+
7
+ def update(time,passed,message)
8
+ $stdout.putc(passed ? '.' : 'F')
5
9
  $stdout.flush
10
+ File.open(@file_name, 'a') {|f| f.write(message + "\n") } if @file_name && !passed
6
11
  end
7
12
  end
8
13
  end
@@ -6,7 +6,10 @@ module Magellan
6
6
  attr_accessor :origin_url
7
7
  attr_accessor :explore_depth
8
8
  attr_accessor :ignored_urls
9
-
9
+ attr_accessor :links_to_explore
10
+ attr_accessor :success_message
11
+ attr_accessor :failure_log
12
+
10
13
  def initialize(name)
11
14
  @ignored_urls = []
12
15
  @name=name
@@ -21,11 +24,11 @@ module Magellan
21
24
  :ignored_urls =>ignored_urls, :links_to_explore => links_to_explore, :trace => ENV['TRACE']}
22
25
  cartographer = Magellan::Cartographer.new(settings)
23
26
  observer = create_observer
24
- observer.add_observer(Magellan::Logger.new)
27
+ observer.add_observer(Magellan::Logger.new(failure_log))
25
28
  cartographer.add_observer(observer)
26
29
  cartographer.crawl
27
30
  if observer.failed?
28
- STDERR.puts observer.failure_message
31
+ STDERR.puts "\n" + observer.failure_message
29
32
  exit 1
30
33
  else
31
34
  $stdout.puts "\n" + success_message
@@ -8,6 +8,8 @@ module Magellan
8
8
 
9
9
  class BrokenLinkTask < BaseMagellanTask
10
10
  def initialize(name="magellan:explore")
11
+ @links_to_explore = [["a","href"],["script","src"],["img","src"]]
12
+ @success_message = "No broken links were found!"
11
13
  super(name)
12
14
  end
13
15
 
@@ -15,18 +17,9 @@ module Magellan
15
17
  Magellan::BrokenLinkTracker.new
16
18
  end
17
19
 
18
- def links_to_explore
19
- [["a","href"],["script","src"],["img","src"]]
20
- end
21
-
22
20
  def description
23
21
  "explore #{@origin_url} for broken links"
24
- end
25
-
26
- def success_message
27
- "No broken links were found!"
28
- end
29
-
22
+ end
30
23
  end
31
24
 
32
25
  end
@@ -10,25 +10,18 @@ module Magellan
10
10
  attr_accessor :patterns_and_expected_links
11
11
 
12
12
  def initialize(name="magellan:check_links")
13
+ @success_message = "All expected links found!"
14
+ @links_to_explore = [["a","href"]]
13
15
  super(name)
14
16
  end
15
17
 
16
18
  def description
17
19
  "Explore #{@origin_url} and find check if all given patterns are matched"
18
20
  end
19
-
20
- def links_to_explore
21
- [["a","href"]]
22
- end
23
21
 
24
22
  def create_observer
25
23
  Magellan::ExpectedLinksTracker.new(@patterns_and_expected_links)
26
24
  end
27
-
28
- def success_message
29
- "All expected links found!"
30
- end
31
-
32
25
  end
33
26
 
34
27
  end
@@ -1,5 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
  require 'rake'
3
+ require 'fileutils'
3
4
 
4
5
  describe "Magellan BrokenLinkTask" do
5
6
 
@@ -22,7 +23,7 @@ describe "Magellan BrokenLinkTask" do
22
23
  Magellan::Rake::BrokenLinkTask.new
23
24
  tasks.include?("magellan:explore").should be_true
24
25
  end
25
-
26
+
26
27
  it "should explore when task is invoked" do
27
28
  Magellan::Rake::BrokenLinkTask.new("invoke_task") do |t|
28
29
  t.explore_depth = 1
@@ -42,17 +43,36 @@ describe "Magellan BrokenLinkTask" do
42
43
  Magellan::Explorer.any_instance.stubs(:explore_a).once.with("http://canrailsscale.com").returns(create_result("http://canrailsscale.com","500"))
43
44
  lambda {@rake.invoke_task("exception_task")}.should raise_error
44
45
  end
45
-
46
+
47
+ it "should create a log file if one was specified" do
48
+ begin
49
+ log = File.dirname(__FILE__) + "/log.txt"
50
+ FileUtils.rm(log,:force => true)
51
+ File.exists?(log).should be_false
52
+ Magellan::Rake::BrokenLinkTask.new("failure_log") do |t|
53
+ t.explore_depth = 1
54
+ t.failure_log = log
55
+ t.origin_url = "http://canrailsscale.com"
56
+ end
57
+ $stderr.expects(:puts)
58
+ Magellan::Explorer.any_instance.stubs(:explore_a).once.with("http://canrailsscale.com").returns(create_result("http://canrailsscale.com","504"))
59
+ lambda {@rake.invoke_task("failure_log")}.should raise_error
60
+ File.exists?(log).should be_true
61
+ ensure
62
+ FileUtils.rm(log,:force => true)
63
+ end
64
+ end
65
+
46
66
  it "should attach logger" do
47
- Magellan::Rake::BrokenLinkTask.new("logger_test") do |t|
48
- t.explore_depth = 1
49
- t.origin_url = "http://canrailsscale.com"
50
- end
51
- $stderr.stubs(:puts)
52
- Magellan::Logger.any_instance.expects(:update)
53
- Magellan::Explorer.any_instance.stubs(:explore_a).once.with("http://canrailsscale.com").returns(create_result("http://canrailsscale.com","500"))
54
- lambda {@rake.invoke_task("logger_test")}.should raise_error
55
- end
67
+ Magellan::Rake::BrokenLinkTask.new("logger_test") do |t|
68
+ t.explore_depth = 1
69
+ t.origin_url = "http://canrailsscale.com"
70
+ end
71
+ $stderr.stubs(:puts)
72
+ Magellan::Logger.any_instance.expects(:update)
73
+ Magellan::Explorer.any_instance.stubs(:explore_a).once.with("http://canrailsscale.com").returns(create_result("http://canrailsscale.com","500"))
74
+ lambda {@rake.invoke_task("logger_test")}.should raise_error
75
+ end
56
76
 
57
77
  def create_result(url,status_code)
58
78
  Magellan::Explorer.create_result(url,url,status_code, [],"foo")
@@ -61,4 +81,4 @@ describe "Magellan BrokenLinkTask" do
61
81
  def tasks
62
82
  @rake.tasks.collect{|task| task.name }
63
83
  end
64
- end
84
+ end
@@ -11,7 +11,7 @@ describe Magellan::Explorer do
11
11
  it "should foo" do
12
12
  WWW::Mechanize.any_instance.expects(:get).raises(Timeout::Error)
13
13
  result = Magellan::Explorer.new(['http://canrailsscale.com/'],links_to_explore).explore
14
- result.first.status_code.should eql('505')
14
+ result.first.status_code.should eql('504')
15
15
  result.first.url.should eql('http://canrailsscale.com/')
16
16
  end
17
17
 
@@ -5,11 +5,36 @@ describe Magellan::Logger do
5
5
  it "should put a . for a pass" do
6
6
  logger = Magellan::Logger.new
7
7
  $stdout.expects(:putc).with('.')
8
- logger.update(Time.now,true)
8
+ logger.update(Time.now,true,'')
9
9
  end
10
10
  it "should put a F for a fail" do
11
11
  logger = Magellan::Logger.new
12
12
  $stdout.expects(:putc).with('F')
13
- logger.update(Time.now,false)
13
+ logger.update(Time.now,false,'')
14
14
  end
15
- end
15
+ it "should create a log file if one is passed in and the updated failed" do
16
+ begin
17
+ log = File.dirname(__FILE__) + "/log.txt"
18
+ FileUtils.rm(log,:force => true)
19
+ File.exists?(log).should be_false
20
+ $stdout.stubs(:putc)
21
+ logger =Magellan::Logger.new(log)
22
+ logger.update(Time.now,false,'foozor')
23
+ File.exists?(log).should be_true
24
+ File.open(log).readlines.should include("foozor\n")
25
+ ensure
26
+ FileUtils.rm(log,:force => true)
27
+ end
28
+ end
29
+
30
+ it "should not a log file if one is passed in and the updated passed" do
31
+ log = File.dirname(__FILE__) + "/log2.txt"
32
+ FileUtils.rm(log,:force => true)
33
+ File.exists?(log).should be_false
34
+ $stdout.stubs(:putc)
35
+ logger =Magellan::Logger.new(log)
36
+ logger.update(Time.now,true,'foozor')
37
+ File.exists?(log).should be_false
38
+ end
39
+
40
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magellan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nolan Evans
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-06 00:00:00 -07:00
12
+ date: 2009-04-07 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency