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
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#failures ⇒ Object
Returns the value of attribute failures.
-
#name ⇒ Object
Returns the value of attribute name.
-
#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.
6 7 8 9 |
# File 'lib/ci/reporter/test_suite.rb', line 6 def initialize(name) super @testcases = [] end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors
4 5 6 |
# File 'lib/ci/reporter/test_suite.rb', line 4 def errors @errors end |
#failures ⇒ Object
Returns the value of attribute failures
4 5 6 |
# File 'lib/ci/reporter/test_suite.rb', line 4 def failures @failures end |
#name ⇒ Object
Returns the value of attribute name
4 5 6 |
# File 'lib/ci/reporter/test_suite.rb', line 4 def name @name end |
#testcases ⇒ Object
Returns the value of attribute testcases.
5 6 7 |
# File 'lib/ci/reporter/test_suite.rb', line 5 def testcases @testcases end |
#tests ⇒ Object
Returns the value of attribute tests
4 5 6 |
# File 'lib/ci/reporter/test_suite.rb', line 4 def tests @tests end |
#time ⇒ Object
Returns the value of attribute time
4 5 6 |
# File 'lib/ci/reporter/test_suite.rb', line 4 def time @time end |
Instance Method Details
#create_builder ⇒ Object
Creates the xml builder instance used to create the report xml document.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ci/reporter/test_suite.rb', line 25 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.
17 18 19 20 21 22 |
# File 'lib/ci/reporter/test_suite.rb', line 17 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 end |
#start ⇒ Object
Starts timing the test suite.
12 13 14 |
# File 'lib/ci/reporter/test_suite.rb', line 12 def start @start = Time.now end |
#to_xml ⇒ Object
Creates an xml string containing the test suite results.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ci/reporter/test_suite.rb', line 42 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) } builder.testsuite(attrs) do @testcases.each do |tc| tc.to_xml(builder) end end end |