Class: CI::Reporter::TestSuite

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

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

#errorsObject

Returns the value of attribute errors

Returns:

  • (Object)

    the current value of errors



4
5
6
# File 'lib/ci/reporter/test_suite.rb', line 4

def errors
  @errors
end

#failuresObject

Returns the value of attribute failures

Returns:

  • (Object)

    the current value of failures



4
5
6
# File 'lib/ci/reporter/test_suite.rb', line 4

def failures
  @failures
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



4
5
6
# File 'lib/ci/reporter/test_suite.rb', line 4

def name
  @name
end

#testcasesObject

Returns the value of attribute testcases.



5
6
7
# File 'lib/ci/reporter/test_suite.rb', line 5

def testcases
  @testcases
end

#testsObject

Returns the value of attribute tests

Returns:

  • (Object)

    the current value of tests



4
5
6
# File 'lib/ci/reporter/test_suite.rb', line 4

def tests
  @tests
end

#timeObject

Returns the value of attribute time

Returns:

  • (Object)

    the current value of time



4
5
6
# File 'lib/ci/reporter/test_suite.rb', line 4

def time
  @time
end

Instance Method Details

#create_builderObject

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

#finishObject

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

#startObject

Starts timing the test suite.



12
13
14
# File 'lib/ci/reporter/test_suite.rb', line 12

def start
  @start = Time.now
end

#to_xmlObject

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