Class: DTest::Test::GlobalResult

Inherits:
Object
  • Object
show all
Includes:
Stopwatch, BAResult
Defined in:
lib/dtest/result.rb

Overview

class CaseResult

Instance Attribute Summary collapse

Attributes included from BAResult

#after_failure, #before_failure

Attributes included from Stopwatch

#finish, #start

Instance Method Summary collapse

Methods included from BAResult

#ba_empty?

Methods included from Stopwatch

#elapsed, #timer

Constructor Details

#initialize(testcases) ⇒ GlobalResult

Returns a new instance of GlobalResult.



123
124
125
126
127
# File 'lib/dtest/result.rb', line 123

def initialize(testcases)
  super()
  @result = []
  @test_size = testcases.inject(0) { |sum, t| sum += t.test.size}
end

Instance Attribute Details

#resultObject

Returns the value of attribute result.



121
122
123
# File 'lib/dtest/result.rb', line 121

def result
  @result
end

Instance Method Details

#add(res) ⇒ Object



129
130
131
# File 'lib/dtest/result.rb', line 129

def add(res)
  @result << res
end

#executedObject



143
144
145
# File 'lib/dtest/result.rb', line 143

def executed
  @executed ||= result.inject(0) {|sum, r| sum += r.executed}
end

#failedObject



138
139
140
# File 'lib/dtest/result.rb', line 138

def failed
  @failed ||= result.inject(0) {|sum, r| sum += r.failed}
end

#outputxml(output_path) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/dtest/result.rb', line 151

def outputxml(output_path)
  doc = REXML::Document.new
  root = doc.add_element('testsuites', {
    'name' => 'Global',
    'tests' => executed,
    'failures' => failed,
    'errors' => 0,
    'time' => elapsed,
  })

  result.each do |result|
    suite = root.add_element('testsuite', {
      'name' => result.name,
      'tests' => result.executed,
      'failures' => result.failed,
      'errors' => 0,
      'time' => result.elapsed,
    })

    result.result.each do |t|
      test = suite.add_element('testcase', {
        'name' => t.name,
        'status' => 'run',
        'classname' => result.name,
        'time' => t.elapsed,
      })
      t.failure.each do |msg|
        failure = test.add_element('failure', {
          'type' => '',
        })
        failure.text = REXML::CData.new(msg.all)
      end
    end
  end

  if RUBY_VERSION >= '1.9.3'
    doc.write(REXML::Output.new(File.new(output_path, 'w+')))
  else
    doc.write(REXML::Output.new(File.new(output_path, 'w+'), REXML::Encoding::UTF_8))
  end
end

#passedObject



133
134
135
136
# File 'lib/dtest/result.rb', line 133

def passed
  @passed = result.inject(0) {|sum, r| sum += r.passed} unless @passed
  @passed
end

#untestedObject



147
148
149
# File 'lib/dtest/result.rb', line 147

def untested
  @untested ||= @test_size - executed
end