Class: CI::Reporter::TestSuite
- Inherits:
-
Struct
- Object
- Struct
- CI::Reporter::TestSuite
- 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.
-
#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.
Instance Method Summary collapse
-
#create_builder ⇒ Object
Creates the xml builder instance used to create the report xml document.
-
#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.
Constructor Details
#initialize(name) ⇒ TestSuite
Returns a new instance of TestSuite.
42 43 44 45 |
# File 'lib/ci/reporter/test_suite.rb', line 42 def initialize(name) super @testcases = [] end |
Instance Attribute Details
#assertions ⇒ Object
Returns the value of attribute assertions
39 40 41 |
# File 'lib/ci/reporter/test_suite.rb', line 39 def assertions @assertions end |
#errors ⇒ Object
Returns the value of attribute errors
39 40 41 |
# File 'lib/ci/reporter/test_suite.rb', line 39 def errors @errors end |
#failures ⇒ Object
Returns the value of attribute failures
39 40 41 |
# File 'lib/ci/reporter/test_suite.rb', line 39 def failures @failures end |
#name ⇒ Object
Returns the value of attribute name
39 40 41 |
# File 'lib/ci/reporter/test_suite.rb', line 39 def name @name end |
#stderr ⇒ Object
Returns the value of attribute stderr.
41 42 43 |
# File 'lib/ci/reporter/test_suite.rb', line 41 def stderr @stderr end |
#stdout ⇒ Object
Returns the value of attribute stdout.
41 42 43 |
# File 'lib/ci/reporter/test_suite.rb', line 41 def stdout @stdout end |
#testcases ⇒ Object
Returns the value of attribute testcases.
40 41 42 |
# File 'lib/ci/reporter/test_suite.rb', line 40 def testcases @testcases end |
#tests ⇒ Object
Returns the value of attribute tests
39 40 41 |
# File 'lib/ci/reporter/test_suite.rb', line 39 def tests @tests end |
#time ⇒ Object
Returns the value of attribute time
39 40 41 |
# File 'lib/ci/reporter/test_suite.rb', line 39 def time @time end |
Instance Method Details
#create_builder ⇒ Object
Creates the xml builder instance used to create the report xml document.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ci/reporter/test_suite.rb', line 67 def create_builder begin gem 'builder' require 'builder' rescue begin gem 'activesupport' require 'active_support' rescue raise LoadError, "XML Builder is required by CI::Reporter" end end unless defined?(Builder::XmlMarkup) # :escape_attrs is obsolete in a newer version, but should do no harm Builder::XmlMarkup.new(:indent => 2, :escape_attrs => true) end |
#finish ⇒ Object
Finishes timing the test suite.
57 58 59 60 61 62 63 64 |
# File 'lib/ci/reporter/test_suite.rb', line 57 def finish self.tests = testcases.size self.time = Time.now - @start self.failures = testcases.select {|tc| tc.failure? }.size self.errors = testcases.select {|tc| tc.error? }.size self.stdout = @capture_out.finish if @capture_out self.stderr = @capture_err.finish if @capture_err end |
#start ⇒ Object
Starts timing the test suite.
48 49 50 51 52 53 54 |
# File 'lib/ci/reporter/test_suite.rb', line 48 def start @start = Time.now unless ENV['CI_CAPTURE'] == "off" @capture_out = OutputCapture.new($stdout) {|io| $stdout = io } @capture_err = OutputCapture.new($stderr) {|io| $stderr = io } end end |
#to_xml ⇒ Object
Creates an xml string containing the test suite results.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ci/reporter/test_suite.rb', line 84 def to_xml builder = create_builder # more recent version of Builder doesn't need the escaping if Builder::XmlMarkup.private_instance_methods.include?("_attr_value") def builder.trunc!(txt) txt.sub(/\n.*/m, '...') end else def builder.trunc!(txt) _escape(txt.sub(/\n.*/m, '...')) end 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.cdata! self.stdout end builder.tag! "system-err" do builder.cdata! self.stderr end end end |