Class: RSpec::TAP::Formatters::TestStats

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/tap/formatters/test_stats.rb

Overview

Test stats calculator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ TestStats

Constructor



13
14
15
# File 'lib/rspec/tap/formatters/test_stats.rb', line 13

def initialize
  @data = {}
end

Instance Attribute Details

#data ⇒ Hash<Integer, Array<Integer, 4>>

Returns example stats.

Returns:

  • (Hash<Integer, Array<Integer, 4>>) —

    example stats



10
11
12
# File 'lib/rspec/tap/formatters/test_stats.rb', line 10

def data
  @data
end

Instance Method Details

#increment(line_number, index) (private)

Increments the stats for a line number and example status.

Parameters:

  • line_number (Integer) —

    the example or group line number

  • index (Integer) —

    the example status index (1 - Passing, 2 - Failing, 3 - Pending)



42
43
44
45
46
# File 'lib/rspec/tap/formatters/test_stats.rb', line 42

def increment(line_number, index)
  @data[line_number] ||= [0, 0, 0, 0]
  @data[line_number][0] += 1
  @data[line_number][index] += 1
end

#populate(notification, index)

Populates total number of examples and one of passing, failing, and, pending example. Traverses bottom up to populate each of the parent example group stats.

Parameters:

  • notification (ExampleNotification) —

    example notification

  • index (Integer) —

    the example status index (1 - Passing, 2 - Failing, 3 - Pending)



25
26
27
28
29
30
31
32
33
# File 'lib/rspec/tap/formatters/test_stats.rb', line 25

def populate(notification, index)
   = notification.example.[:example_group]
  increment([:line_number], index)

  while ( = [:parent_example_group])
     = 
    increment([:line_number], index)
  end
end