Class CI::Reporter::TestSuite
In: lib/ci/reporter/test_suite.rb
Parent: Struct.new(:name, :tests, :time, :failures, :errors, :skipped, :assertions)

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

Methods

create_builder   finish   new   start   to_xml  

Attributes

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

Public Class methods

[Source]

    # File lib/ci/reporter/test_suite.rb, line 43
43:       def initialize(name)
44:         super(name.to_s) # RSpec passes a "description" object instead of a string
45:         @testcases = []
46:       end

Public Instance methods

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

[Source]

    # File lib/ci/reporter/test_suite.rb, line 69
69:       def create_builder
70:         require 'builder'
71:         # :escape_attrs is obsolete in a newer version, but should do no harm
72:         Builder::XmlMarkup.new(:indent => 2, :escape_attrs => true)
73:       end

Finishes timing the test suite.

[Source]

    # File lib/ci/reporter/test_suite.rb, line 58
58:       def finish
59:         self.tests = testcases.size
60:         self.time = Time.now - @start
61:         self.failures = testcases.inject(0) {|sum,tc| sum += tc.failures.select{|f| f.failure? }.size }
62:         self.errors = testcases.inject(0) {|sum,tc| sum += tc.failures.select{|f| f.error? }.size }
63:         self.skipped = testcases.inject(0) {|sum,tc| sum += (tc.skipped? ? 1 : 0) }
64:         self.stdout = @capture_out.finish if @capture_out
65:         self.stderr = @capture_err.finish if @capture_err
66:       end

Starts timing the test suite.

[Source]

    # File lib/ci/reporter/test_suite.rb, line 49
49:       def start
50:         @start = Time.now
51:         unless ENV['CI_CAPTURE'] == "off"
52:           @capture_out = OutputCapture.new($stdout) {|io| $stdout = io }
53:           @capture_err = OutputCapture.new($stderr) {|io| $stderr = io }
54:         end
55:       end

Creates an xml string containing the test suite results.

[Source]

    # File lib/ci/reporter/test_suite.rb, line 76
76:       def to_xml
77:         builder = create_builder
78:         # more recent version of Builder doesn't need the escaping
79:         def builder.trunc!(txt)
80:           txt.sub(/\n.*/m, '...')
81:         end
82:         builder.instruct!
83:         attrs = {}
84:         each_pair {|k,v| attrs[k] = builder.trunc!(v.to_s) unless v.nil? || v.to_s.empty? }
85:         builder.testsuite(attrs) do
86:           @testcases.each do |tc|
87:             tc.to_xml(builder)
88:           end
89:           builder.tag! "system-out" do
90:             builder.text! self.stdout
91:           end
92:           builder.tag! "system-err" do
93:             builder.text! self.stderr
94:           end
95:         end
96:       end

[Validate]