Sha256: 6e3c43bf259c8ce29462860a8ca930d10cb6c8f786167d101b6c6213edfa84cd

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

require "petitest/texts/base_text"

module Petitest
  module Texts
    class TestCasesResultText < ::Petitest::Texts::BaseText
      # @return [Time]
      attr_reader :finished_at

      # @return [Time]
      attr_reader :started_at

      # @return [Array<Petitest::TestCase>]
      attr_reader :test_cases

      # @param finished_at [Time]
      # @param started_at [Time]
      # @param test_cases [Array<Petitest::TestCase>]
      def initialize(
        finished_at:,
        started_at:,
        test_cases:
      )
        @finished_at = finished_at
        @started_at = started_at
        @test_cases = test_cases
      end

      # @note Override
      def to_s
        [
          header,
          body,
        ].join
      end

      private

      # @return [String]
      def body
        texts = []
        texts << ::Petitest::Texts::FailuresText.new(test_cases: test_cases_failed) unless test_cases_failed.empty?
        texts << ::Petitest::Texts::TestCountsText.new(test_cases: test_cases)
        texts << ::Petitest::Texts::TimesText.new(
          finished_at: finished_at,
          started_at: started_at,
        )
        texts.join("\n\n")
      end

      # @return [String]
      def header
        ::Petitest::Texts::TestCasesResultMarginTopText.new(test_cases: test_cases).to_s
      end

      # @return [Array<Petitest::TestCase>]
      def test_cases_failed
        @test_cases_failed ||= test_cases.select(&:failed?)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
petitest-0.2.1 lib/petitest/texts/test_cases_result_text.rb
petitest-0.2.0 lib/petitest/texts/test_cases_result_text.rb