Parent

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
# File lib/ci/reporter/test_suite.rb, line 57
def initialize(name)
  super(name.to_s) # RSpec passes a "description" object instead of a string
  @testcases = []
end

Public Instance Methods

create_builder() click to toggle source

Creates the xml builder instance used to create the report xml document.

# File lib/ci/reporter/test_suite.rb, line 83
def create_builder
  require 'builder'
  # :escape_attrs is obsolete in a newer version, but should do no harm
  Builder::XmlMarkup.new(:indent => 2, :escape_attrs => true)
end
finish() click to toggle source

Finishes timing the test suite.

# File lib/ci/reporter/test_suite.rb, line 72
def finish
  self.tests = testcases.size
  self.time = Time.now - @start
  self.failures = testcases.inject(0) {|sum,tc| sum += tc.failures.select{|f| f.failure? }.size }
  self.errors = testcases.inject(0) {|sum,tc| sum += tc.failures.select{|f| f.error? }.size }
  self.skipped = testcases.inject(0) {|sum,tc| sum += (tc.skipped? ? 1 : 0) }
  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 63
def start
  @start = Time.now
  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 90
def to_xml
  builder = create_builder
  # more recent version of Builder doesn't need the escaping
  def builder.trunc!(txt)
    txt.sub(/\n.*/, '...')
  end
  builder.instruct!
  attrs = {}
  each_pair {|k,v| attrs[k] = builder.trunc!(v.to_s) unless v.nil? || v.to_s.empty? }
  builder.testsuite(attrs) do
    @testcases.each do |tc|
      tc.to_xml(builder)
    end
    builder.tag! "system-out" do
      builder.text!(self.stdout || '' )
    end
    builder.tag! "system-err" do
      builder.text!(self.stderr || '' )
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.