Class: Minitest::Heat::Results

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/heat/results.rb

Overview

A collection of test failures

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResults

Returns a new instance of Results.



9
10
11
12
# File 'lib/minitest/heat/results.rb', line 9

def initialize
  @issues = []
  @heat_map = Heat::Map.new
end

Instance Attribute Details

#heat_mapObject (readonly)

Returns the value of attribute heat_map.



7
8
9
# File 'lib/minitest/heat/results.rb', line 7

def heat_map
  @heat_map
end

#issuesObject (readonly)

Returns the value of attribute issues.



7
8
9
# File 'lib/minitest/heat/results.rb', line 7

def issues
  @issues
end

Instance Method Details

#brokensObject



59
60
61
# File 'lib/minitest/heat/results.rb', line 59

def brokens
  @brokens ||= select_issues(:broken)
end

#errorsObject



55
56
57
# File 'lib/minitest/heat/results.rb', line 55

def errors
  @errors ||= select_issues(:error)
end

#failuresObject



63
64
65
# File 'lib/minitest/heat/results.rb', line 63

def failures
  @failures ||= select_issues(:failure)
end

#painfulsObject



71
72
73
# File 'lib/minitest/heat/results.rb', line 71

def painfuls
  @painfuls ||= select_issues(:painful).sort_by(&:execution_time).reverse
end

#problems?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/minitest/heat/results.rb', line 51

def problems?
  errors.any? || brokens.any? || failures.any?
end

#record(issue) ⇒ type

Logs an issue to the results for later reporting

Parameters:

  • issue (Issue)

    the issue generated from a given test result

Returns:

  • (type)
    description


18
19
20
21
22
23
24
25
26
27
# File 'lib/minitest/heat/results.rb', line 18

def record(issue)
  # Record everything—even if it's a success
  @issues.push(issue)

  # If it's not a genuine problem, we're done here...
  return unless issue.hit?

  # ...otherwise update the heat map
  update_heat_map(issue)
end

#skipsObject



67
68
69
# File 'lib/minitest/heat/results.rb', line 67

def skips
  @skips ||= select_issues(:skipped)
end

#slowsObject



75
76
77
# File 'lib/minitest/heat/results.rb', line 75

def slows
  @slows ||= select_issues(:slow).sort_by(&:execution_time).reverse
end

#update_heat_map(issue) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/minitest/heat/results.rb', line 29

def update_heat_map(issue)
  # For heat map purposes, only the project backtrace lines are interesting
  pathname, line_number = issue.locations.project.to_a

  # A backtrace is only relevant for exception-generating issues (i.e. errors), not slows or skips
  # However, while assertion failures won't have a backtrace, there can still be repeated line
  # numbers if the tests reference a shared method with an assertion in it. So in those cases,
  # the backtrace is simply the test definition
  backtrace = if issue.error?
    # With errors, we have a backtrace
    issue.locations.backtrace.project_locations
  else
    # With failures, the test definition is the most granular backtrace equivalent
    location = issue.locations.test_definition
    location.raw_container = issue.test_identifier

    [location]
  end

  @heat_map.add(pathname, line_number, issue.type, backtrace: backtrace)
end