Class: CI::Reporter::TestSuite

Inherits:
Struct
  • Object
show all
Includes:
StructureXmlHelpers
Defined in:
lib/ci/reporter/test_suite.rb

Overview

Basic structure representing the running of a test suite. Used to time tests and store results.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StructureXmlHelpers

#attr_hash, #cleaned_attributes, #truncate_at_newline

Constructor Details

#initialize(name) ⇒ TestSuite



33
34
35
36
37
38
# File 'lib/ci/reporter/test_suite.rb', line 33

def initialize(name)
  super(name.to_s) # RSpec passes a "description" object instead of a string
  @testcases = []
  @capture_out = nil
  @capture_err = nil
end

Instance Attribute Details

#assertionsObject

Returns the value of attribute assertions



28
29
30
# File 'lib/ci/reporter/test_suite.rb', line 28

def assertions
  @assertions
end

#errorsObject

Returns the value of attribute errors



28
29
30
# File 'lib/ci/reporter/test_suite.rb', line 28

def errors
  @errors
end

#failuresObject

Returns the value of attribute failures



28
29
30
# File 'lib/ci/reporter/test_suite.rb', line 28

def failures
  @failures
end

#nameObject

Returns the value of attribute name



28
29
30
# File 'lib/ci/reporter/test_suite.rb', line 28

def name
  @name
end

#skippedObject

Returns the value of attribute skipped



28
29
30
# File 'lib/ci/reporter/test_suite.rb', line 28

def skipped
  @skipped
end

#stderrObject

Returns the value of attribute stderr.



32
33
34
# File 'lib/ci/reporter/test_suite.rb', line 32

def stderr
  @stderr
end

#stdoutObject

Returns the value of attribute stdout.



32
33
34
# File 'lib/ci/reporter/test_suite.rb', line 32

def stdout
  @stdout
end

#testcasesObject

Returns the value of attribute testcases.



31
32
33
# File 'lib/ci/reporter/test_suite.rb', line 31

def testcases
  @testcases
end

#testsObject

Returns the value of attribute tests



28
29
30
# File 'lib/ci/reporter/test_suite.rb', line 28

def tests
  @tests
end

#timeObject

Returns the value of attribute time



28
29
30
# File 'lib/ci/reporter/test_suite.rb', line 28

def time
  @time
end

#timestampObject

Returns the value of attribute timestamp



28
29
30
# File 'lib/ci/reporter/test_suite.rb', line 28

def timestamp
  @timestamp
end

Instance Method Details

#finishObject

Finishes timing the test suite.



51
52
53
54
55
56
57
58
59
60
# File 'lib/ci/reporter/test_suite.rb', line 51

def finish
  self.tests = testcases.size
  self.time = MonotonicTime.time_in_seconds - @start
  self.timestamp = @start_time.iso8601
  self.failures = testcases.map(&:failure_count).reduce(&:+)
  self.errors = testcases.map(&:error_count).reduce(&:+)
  self.skipped = testcases.count(&:skipped?)
  self.stdout = @capture_out.finish if @capture_out
  self.stderr = @capture_err.finish if @capture_err
end

#startObject

Starts timing the test suite.



41
42
43
44
45
46
47
48
# File 'lib/ci/reporter/test_suite.rb', line 41

def start
  @start_time = Time.now
  @start = MonotonicTime.time_in_seconds
  unless ENV['CI_CAPTURE'] == "off"
    @capture_out = OutputCapture.wrap($stdout) {|io| $stdout = io }
    @capture_err = OutputCapture.wrap($stderr) {|io| $stderr = io }
  end
end

#to_xmlObject

Creates an xml string containing the test suite results.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ci/reporter/test_suite.rb', line 63

def to_xml
  builder = Builder::XmlMarkup.new(indent: 2)
  builder.instruct!
  builder.testsuite(cleaned_attributes) do
    @testcases.each do |tc|
      tc.to_xml(builder)
    end
    unless self.stdout.to_s.empty?
      builder.tag! "system-out" do
        builder.text!(self.stdout)
      end
    end
    unless self.stderr.to_s.empty?
      builder.tag! "system-err" do
        builder.text!(self.stderr)
      end
    end
  end
end