Class: CI::Reporter::TestCase

Inherits:
Struct
  • Object
show all
Includes:
StructureXmlHelpers
Defined in:
lib/ci/reporter/test_suite.rb

Overview

Structure used to represent an individual test case. Used to time the test and store the result.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StructureXmlHelpers

#attr_hash, #cleaned_attributes, #truncate_at_newline

Constructor Details

#initialize(*args) ⇒ TestCase

Returns a new instance of TestCase.



91
92
93
94
# File 'lib/ci/reporter/test_suite.rb', line 91

def initialize(*args)
  super
  @failures = []
end

Instance Attribute Details

#assertionsObject

Returns the value of attribute assertions

Returns:

  • (Object)

    the current value of assertions



85
86
87
# File 'lib/ci/reporter/test_suite.rb', line 85

def assertions
  @assertions
end

#failuresObject

Returns the value of attribute failures.



88
89
90
# File 'lib/ci/reporter/test_suite.rb', line 88

def failures
  @failures
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



85
86
87
# File 'lib/ci/reporter/test_suite.rb', line 85

def name
  @name
end

#skippedObject

Returns the value of attribute skipped.



89
90
91
# File 'lib/ci/reporter/test_suite.rb', line 89

def skipped
  @skipped
end

#timeObject

Returns the value of attribute time

Returns:

  • (Object)

    the current value of time



85
86
87
# File 'lib/ci/reporter/test_suite.rb', line 85

def time
  @time
end

Instance Method Details

#error?Boolean

Returns non-nil if the test had an error.

Returns:

  • (Boolean)


112
113
114
# File 'lib/ci/reporter/test_suite.rb', line 112

def error?
  failures.any?(&:error?)
end

#error_countObject



120
121
122
# File 'lib/ci/reporter/test_suite.rb', line 120

def error_count
  failures.count(&:error?)
end

#failure?Boolean

Returns non-nil if the test failed.

Returns:

  • (Boolean)


107
108
109
# File 'lib/ci/reporter/test_suite.rb', line 107

def failure?
  failures.any?(&:failure?)
end

#failure_countObject



116
117
118
# File 'lib/ci/reporter/test_suite.rb', line 116

def failure_count
  failures.count(&:failure?)
end

#finishObject

Finishes timing the test.



102
103
104
# File 'lib/ci/reporter/test_suite.rb', line 102

def finish
  self.time = MonotonicTime.time_in_seconds - @start
end

#skipped?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/ci/reporter/test_suite.rb', line 124

def skipped?
  skipped
end

#startObject

Starts timing the test.



97
98
99
# File 'lib/ci/reporter/test_suite.rb', line 97

def start
  @start = MonotonicTime.time_in_seconds
end

#to_xml(builder) ⇒ Object

Writes xml representing the test result to the provided builder.



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/ci/reporter/test_suite.rb', line 129

def to_xml(builder)
  builder.testcase(cleaned_attributes) do
    if skipped?
      builder.skipped
    else
      failures.each do |failure|
        tag = failure.error? ? :error : :failure

        builder.tag!(tag, type: truncate_at_newline(failure.name), message: truncate_at_newline(failure.message)) do
          builder.text!(failure.message + " (#{failure.name})\n")
          builder.text!(failure.location)
        end
      end
    end
  end
end