Class: CI::Reporter::TestSuite
- Inherits:
-
Struct
- Object
- Struct
- CI::Reporter::TestSuite
- 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
-
#assertions ⇒ Object
Returns the value of attribute assertions.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#failures ⇒ Object
Returns the value of attribute failures.
-
#name ⇒ Object
Returns the value of attribute name.
-
#skipped ⇒ Object
Returns the value of attribute skipped.
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
-
#testcases ⇒ Object
Returns the value of attribute testcases.
-
#tests ⇒ Object
Returns the value of attribute tests.
-
#time ⇒ Object
Returns the value of attribute time.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Instance Method Summary collapse
-
#finish ⇒ Object
Finishes timing the test suite.
-
#initialize(name) ⇒ TestSuite
constructor
A new instance of TestSuite.
-
#start ⇒ Object
Starts timing the test suite.
-
#to_xml ⇒ Object
Creates an xml string containing the test suite results.
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
#assertions ⇒ Object
Returns the value of attribute assertions
28 29 30 |
# File 'lib/ci/reporter/test_suite.rb', line 28 def assertions @assertions end |
#errors ⇒ Object
Returns the value of attribute errors
28 29 30 |
# File 'lib/ci/reporter/test_suite.rb', line 28 def errors @errors end |
#failures ⇒ Object
Returns the value of attribute failures
28 29 30 |
# File 'lib/ci/reporter/test_suite.rb', line 28 def failures @failures end |
#name ⇒ Object
Returns the value of attribute name
28 29 30 |
# File 'lib/ci/reporter/test_suite.rb', line 28 def name @name end |
#skipped ⇒ Object
Returns the value of attribute skipped
28 29 30 |
# File 'lib/ci/reporter/test_suite.rb', line 28 def skipped @skipped end |
#stderr ⇒ Object
Returns the value of attribute stderr.
32 33 34 |
# File 'lib/ci/reporter/test_suite.rb', line 32 def stderr @stderr end |
#stdout ⇒ Object
Returns the value of attribute stdout.
32 33 34 |
# File 'lib/ci/reporter/test_suite.rb', line 32 def stdout @stdout end |
#testcases ⇒ Object
Returns the value of attribute testcases.
31 32 33 |
# File 'lib/ci/reporter/test_suite.rb', line 31 def testcases @testcases end |
#tests ⇒ Object
Returns the value of attribute tests
28 29 30 |
# File 'lib/ci/reporter/test_suite.rb', line 28 def tests @tests end |
#time ⇒ Object
Returns the value of attribute time
28 29 30 |
# File 'lib/ci/reporter/test_suite.rb', line 28 def time @time end |
#timestamp ⇒ Object
Returns the value of attribute timestamp
28 29 30 |
# File 'lib/ci/reporter/test_suite.rb', line 28 def end |
Instance Method Details
#finish ⇒ Object
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. = @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 ⇒ Object
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_xml ⇒ Object
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 |