Class: CI::Reporter::TestCase

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

Constructor Details

#initialize(*args) ⇒ TestCase

Returns a new instance of TestCase.



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

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

Instance Attribute Details

#assertionsObject

Returns the value of attribute assertions

Returns:

  • (Object)

    the current value of assertions



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

def assertions
  @assertions
end

#failuresObject

Returns the value of attribute failures.



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

def failures
  @failures
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



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

def name
  @name
end

#skippedObject

Returns the value of attribute skipped.



118
119
120
# File 'lib/ci/reporter/test_suite.rb', line 118

def skipped
  @skipped
end

#timeObject

Returns the value of attribute time

Returns:

  • (Object)

    the current value of time



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

def time
  @time
end

Instance Method Details

#error?Boolean

Returns non-nil if the test had an error.

Returns:

  • (Boolean)


141
142
143
# File 'lib/ci/reporter/test_suite.rb', line 141

def error?
  !failures.empty? && failures.detect {|f| f.error? }
end

#failure?Boolean

Returns non-nil if the test failed.

Returns:

  • (Boolean)


136
137
138
# File 'lib/ci/reporter/test_suite.rb', line 136

def failure?
  !failures.empty? && failures.detect {|f| f.failure? }
end

#finishObject

Finishes timing the test.



131
132
133
# File 'lib/ci/reporter/test_suite.rb', line 131

def finish
  self.time = Time.now - @start
end

#skipped?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/ci/reporter/test_suite.rb', line 145

def skipped?
  return skipped
end

#startObject

Starts timing the test.



126
127
128
# File 'lib/ci/reporter/test_suite.rb', line 126

def start
  @start = Time.now
end

#to_xml(builder) ⇒ Object

Writes xml representing the test result to the provided builder.



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/ci/reporter/test_suite.rb', line 150

def to_xml(builder)
  attrs = {}
  each_pair {|k,v| attrs[k] = builder.trunc!(v.to_s) unless v.nil? || v.to_s.empty?}
  builder.testcase(attrs) do
    if skipped
      builder.skipped
    else
      failures.each do |failure|
        tag = case failure.class.name
              when /TestUnitSkipped/ then :skipped
              when /TestUnitError/, /MiniTestError/ then :error
              else :failure end

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