Class: Rawler::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/howitzer/patches/rawler_patched.rb

Instance Method Summary collapse

Instance Method Details

#add_html_log_item(fields) ⇒ Object


82
83
84
# File 'lib/howitzer/patches/rawler_patched.rb', line 82

def add_html_log_item(fields)
  #Todo: should be implemented
end

#add_xml_log_item(fields) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/howitzer/patches/rawler_patched.rb', line 38

def add_xml_log_item(fields)
  log_file_path = File.expand_path(settings.rawler_xml_log, "#{settings.log_dir}")

  doc = File.exists?(log_file_path) ? Nokogiri::XML::Document.parse(File.read log_file_path) : Nokogiri::XML::Document.new

  doc.encoding = 'UTF-8'

  if doc.root
    tests = doc.root > ("testcase")
    failures = doc.root > ("testcase failure")
    doc.root[:failures] = failures.to_a.size.to_s
    doc.root[:tests] = tests.to_a.size.to_s
    doc.root[:time] = "#{tests.to_a.size} sec."
  else
    root = doc.create_element('testsuite')
    root[:errors] = "0"
    root[:failures] = "0"
    root[:name] = "Check links"
    root[:skipped] = "0"
    root[:tests] = "0"
    root[:time] = "0 sec."
    doc.root = root
  end

  testcase = doc.create_element('testcase')
  testcase[:classname] = "Check links"
  testcase[:name] = "Check: link '#{fields[:link]}'"
  testcase[:time] = "1"

  if fields[:failed]
    failure = doc.create_element('failure', message: "Failed responce code: '#{fields[:code]}'", type:'failed')
    failure << doc.create_cdata("#{fields[:message]}")
    testcase << failure
  end

  testcase << doc.create_element('system-out')
  testcase << doc.create_element('system-err')
  doc.root << testcase

  File.open(log_file_path, 'w+') do |f|
    f.write(doc.serialize(:encoding => 'UTF-8', :save_with => Nokogiri::XML::Node::SaveOptions::FORMAT))
  end
end

#record_response(code, link, from_url, redirection = nil) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/howitzer/patches/rawler_patched.rb', line 3

def record_response(code, link, from_url, redirection=nil)
  message = "#{code} - #{link}"

  if code.to_i >= 300
    message += " - Called from: #{from_url}"
  end

  message += " - Following redirection to: #{redirection}" if redirection
  log_fields = {code: code, link: link, message: message}

  code = code.to_i
  case code / 100
    when 1,2
      Rawler.output.info(message)
      add_xml_log_item(log_fields) if settings.add_rawler_xml_log
      add_html_log_item(log_fields) if settings.add_rawler_html_log
    when 3 then
      Rawler.output.warn(message)
      add_xml_log_item(log_fields) if settings.add_rawler_xml_log
      add_html_log_item(log_fields) if settings.add_rawler_html_log
    when 4,5 then
      Rawler.output.error(message)
      log_fields[:failed] = true
      add_xml_log_item(log_fields) if settings.add_rawler_xml_log
      add_html_log_item(log_fields) if settings.add_rawler_html_log
    else
      Rawler.output.error("Unknown code #{message}")
      log_fields[:failed] = true
      log_fields[:message] = "Unknown code #{message}"
      add_xml_log_item(log_fields) if settings.add_rawler_xml_log
      add_html_log_item(log_fields) if settings.add_rawler_html_log
  end
  @logfile.puts(message) if Rawler.log
end