class Minitest::Heat::Output::Results

Attributes

results[RW]

Public Class Methods

new(results) click to toggle source
# File lib/minitest/heat/output/results.rb, line 13
def initialize(results)
  @results = results
  @tokens = []
end

Public Instance Methods

tokens() click to toggle source
# File lib/minitest/heat/output/results.rb, line 18
def tokens
  @tokens << [*issue_counts_tokens] if issue_counts_tokens&.any?
  @tokens << [assertions_count_token, test_count_token]
  @tokens << [assertions_performance_token, tests_performance_token, timing_token]

  @tokens
end

Private Instance Methods

assertions_count_token() click to toggle source
# File lib/minitest/heat/output/results.rb, line 86
def assertions_count_token
  [:muted, pluralize(results.assertion_count, 'Assertion')]
end
assertions_performance_token() click to toggle source
# File lib/minitest/heat/output/results.rb, line 74
def assertions_performance_token
  [:bold, "#{results.assertions_per_second} assertions/s"]
end
broken_count_token() click to toggle source
# File lib/minitest/heat/output/results.rb, line 56
def broken_count_token
  issue_count_token(:broken, brokens)
end
error_count_token() click to toggle source
# File lib/minitest/heat/output/results.rb, line 52
def error_count_token
  issue_count_token(:error, errors)
end
failure_count_token() click to toggle source
# File lib/minitest/heat/output/results.rb, line 60
def failure_count_token
  issue_count_token(:failure, failures)
end
issue_count_token(type, collection, name: type.capitalize) click to toggle source
# File lib/minitest/heat/output/results.rb, line 94
def issue_count_token(type, collection, name: type.capitalize)
  return nil if collection.empty?

  [type, pluralize(collection.size, name)]
end
issue_counts_tokens() click to toggle source
# File lib/minitest/heat/output/results.rb, line 35
def issue_counts_tokens
  return unless problems? || slows?

  counts = [error_count_token, broken_count_token, failure_count_token, skip_count_token, slow_count_token].compact

  # # Create an array of separator tokens one less than the total number of issue count tokens
  separator_tokens = Array.new(counts.size, separator_token)

  counts_with_separators = counts
                            .zip(separator_tokens) # Add separators between the counts
                            .flatten(1) # Flatten the zipped separators, but no more

  counts_with_separators.pop # Remove the final trailing zipped separator that's not needed

  counts_with_separators
end
pluralize(count, singular) click to toggle source
# File lib/minitest/heat/output/results.rb, line 28
def pluralize(count, singular)
  singular_style = "#{count} #{singular}"

  # Given the narrow scope, pluralization can be relatively naive here
  count > 1 ? "#{singular_style}s" : singular_style
end
separator_token() click to toggle source
# File lib/minitest/heat/output/results.rb, line 100
def separator_token
  [:muted, ' ยท ']
end
skip_count_token() click to toggle source
# File lib/minitest/heat/output/results.rb, line 64
def skip_count_token
  style = problems? ? :muted : :skipped
  issue_count_token(style, skips, name: 'Skip')
end
slow_count_token() click to toggle source
# File lib/minitest/heat/output/results.rb, line 69
def slow_count_token
  style = problems? ? :muted : :slow
  issue_count_token(style, slows, name: 'Slow')
end
test_count_token() click to toggle source
# File lib/minitest/heat/output/results.rb, line 90
def test_count_token
  [:muted, " across #{pluralize(results.test_count, 'Test')}"]
end
tests_performance_token() click to toggle source
# File lib/minitest/heat/output/results.rb, line 78
def tests_performance_token
  [:default, " and #{results.tests_per_second} tests/s"]
end
timing_token() click to toggle source
# File lib/minitest/heat/output/results.rb, line 82
def timing_token
  [:default, " in #{results.total_time.round(2)}s"]
end