Sha256: 90da5b0154fc40059e1ec2f2bad1c11a4ded6f643d3589bb97c65d7bfb2a4fdd

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

require "petitest/texts/base_text"

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

      # @return [Petitest::Test]
      attr_reader :test

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

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

      private

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

      # @return [String]
      def heading
        "#{ordinal_number}) #{test.class}##{test.runner.test_method_name}"
      end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
petitest-0.3.1 lib/petitest/texts/failures_element_text.rb
petitest-0.3.0 lib/petitest/texts/failures_element_text.rb