Class: GroundControl::TestResult

Inherits:
Object
  • Object
show all
Defined in:
lib/groundcontrol/test_result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, failure_message = nil) ⇒ TestResult

Returns a new instance of TestResult.



45
46
47
48
49
50
51
52
53
# File 'lib/groundcontrol/test_result.rb', line 45

def initialize(name, failure_message = nil)
  @name = name      
  @failed = false
  
  if failure_message
    @failed = true
    @message = failure_message
  end
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



7
8
9
# File 'lib/groundcontrol/test_result.rb', line 7

def message
  @message
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/groundcontrol/test_result.rb', line 7

def name
  @name
end

Class Method Details

.read_from_directory(path_to_tests) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/groundcontrol/test_result.rb', line 9

def self.read_from_directory(path_to_tests)
  test_results_in_directory = []
  
  Dir.chdir(path_to_tests)
  Dir.glob("TEST-*.xml").each do |file|
    f = File.open(File.join(path_to_tests, file))
    doc = Nokogiri::XML(f)
    f.close()
    test_results_in_directory += read_tests_from_xml_document(doc)
  end
  
  return test_results_in_directory
end

.read_from_xml(xml_string) ⇒ Object



23
24
25
26
27
# File 'lib/groundcontrol/test_result.rb', line 23

def self.read_from_xml(xml_string)
  doc = Nokogiri::XML.parse(xml_string)
  
  return read_tests_from_xml_document(doc)
end

.read_tests_from_xml_document(doc) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/groundcontrol/test_result.rb', line 29

def self.read_tests_from_xml_document(doc)
  tests = []
  
  doc.xpath('//testcase').each do |testcase|
    failure = testcase.xpath('//failure')
    if failure.blank?
      tests << TestResult.new(testcase['name'])
    else
      tests << TestResult.new(testcase['name'], failure.first.content)
    end
  end
  
  
  return tests
end

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/groundcontrol/test_result.rb', line 55

def failed?
  return @failed
end

#success?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/groundcontrol/test_result.rb', line 59

def success?
  return true if not @failed
end