Sha256: 99ebf39920c8c5021a930c9ea6c05dbfaa60a464b28213628d57c92e1461750a

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

require "petitest/texts/base_text"

module Petitest
  module Texts
    class FailuresElementText < ::Petitest::Texts::BaseText
      # @return [Integer]
      attr_reader :index

      # @return [Petitest::TestCase]
      attr_reader :test_case

      # @param index [Integer]
      # @param test_case [Petitest::TestCase]
      def initialize(index:, test_case:)
        @index = index
        @test_case = test_case
      end

      # @note Override
      def to_s
        [
          heading,
          indent(body, 2)
        ].join("\n")
      end

      private

      # @return [String]
      def body
        [
          ::Petitest::Texts::RaisedCodeText.new(test_case: test_case),
          ::Petitest::Texts::ErrorMessageText.new(test_case: test_case),
          ::Petitest::Texts::FilteredBacktraceText.new(test_case: test_case),
        ].join("\n")
      end

      # @return [String]
      def heading
        "#{ordinal_number}) #{test_signature}"
      end

      # @return [Integer]
      def ordinal_number
        index + 1
      end

      # @return [String]
      def test_signature
        test_case.test_signature
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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