class Petitest::Texts::TestCountsText

Attributes

tests[R]

@return [Array<Petitest::Test>]

Public Class Methods

new(tests:) click to toggle source

@param tests [Array<Petitest::Test>]

# File lib/petitest/texts/test_counts_text.rb, line 10
def initialize(tests:)
  @tests = tests
end

Public Instance Methods

to_s() click to toggle source

@note Override

# File lib/petitest/texts/test_counts_text.rb, line 15
def to_s
  [
    heading,
    indent(body, 2),
  ].join("\n\n")
end

Private Instance Methods

body() click to toggle source

@return [String]

# File lib/petitest/texts/test_counts_text.rb, line 25
def body
  [
    text_of_count_of_tests,
    text_of_count_of_passed_tests,
    text_of_count_of_failed_tests,
    text_of_count_of_skipped_tests,
  ].join("\n")
end
count_of_failed_tests() click to toggle source

@return [Integer]

# File lib/petitest/texts/test_counts_text.rb, line 35
def count_of_failed_tests
  tests.map(&:runner).select(&:failed?).length
end
count_of_passed_tests() click to toggle source

@return [Integer]

# File lib/petitest/texts/test_counts_text.rb, line 40
def count_of_passed_tests
  tests.map(&:runner).select(&:passed?).length
end
count_of_skipped_tests() click to toggle source

@return [Integer]

# File lib/petitest/texts/test_counts_text.rb, line 45
def count_of_skipped_tests
  tests.map(&:runner).select(&:skipped?).length
end
count_of_tests() click to toggle source

@return [Integer]

# File lib/petitest/texts/test_counts_text.rb, line 50
def count_of_tests
  tests.length
end
heading() click to toggle source

@return [String]

# File lib/petitest/texts/test_counts_text.rb, line 55
def heading
  "Counts:"
end
max_digits_length() click to toggle source

@return [Integer]

# File lib/petitest/texts/test_counts_text.rb, line 60
def max_digits_length
  @max_digits_length ||= count_of_tests.to_s.length
end
text_of_count_of_failed_tests() click to toggle source

@return [String]

# File lib/petitest/texts/test_counts_text.rb, line 65
def text_of_count_of_failed_tests
  colorize("%#{max_digits_length}d failures" % count_of_failed_tests, :error)
end
text_of_count_of_passed_tests() click to toggle source

@return [String]

# File lib/petitest/texts/test_counts_text.rb, line 70
def text_of_count_of_passed_tests
  colorize("%#{max_digits_length}d passes" % count_of_passed_tests, :pass)
end
text_of_count_of_skipped_tests() click to toggle source

@return [String]

# File lib/petitest/texts/test_counts_text.rb, line 75
def text_of_count_of_skipped_tests
  colorize("%#{max_digits_length}d skips" % count_of_skipped_tests, :skip)
end
text_of_count_of_tests() click to toggle source

@return [String]

# File lib/petitest/texts/test_counts_text.rb, line 80
def text_of_count_of_tests
  "%#{max_digits_length}d tests" % count_of_tests
end