Sha256: 33c9063944682dcafe60ee5b037e6352957b7eb93e854eb591bdd8a4e043cbbb

Contents?: true

Size: 1.14 KB

Versions: 4

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::FailureMessageText.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

4 entries across 4 versions & 1 rubygems

Version Path
petitest-0.1.3 lib/petitest/texts/failures_element_text.rb
petitest-0.1.2 lib/petitest/texts/failures_element_text.rb
petitest-0.1.1 lib/petitest/texts/failures_element_text.rb
petitest-0.1.0 lib/petitest/texts/failures_element_text.rb