class CI::Reporter::TestSuite

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

Attributes

stderr[RW]
stdout[RW]
testcases[RW]

Public Class Methods

new(name) click to toggle source
Calls superclass method
# 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

Public Instance Methods

finish() click to toggle source

Finishes timing the test suite.

# 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
start() click to toggle source

Starts timing the test suite.

# 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_xml() click to toggle source

Creates an xml string containing the test suite results.

# 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