Sha256: cf3c972dfb996f7aa71def95de295c0a276aae1accfdc223ea846ddc909abfbf

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

module Petitest
  class TestGroup
    # @return [Class]
    attr_reader :test_class

    # @param test_class [Class]
    def initialize(test_class:)
      @test_class ||= test_class
    end

    # @return [String]
    def description
      test_class.description
    end

    # @return [String]
    def full_description
      test_class.test_ancestors.reverse.map(&:description).join(" ")
    end

    # @return [Hash{Symbol => Object}]
    def metadata
      test_class.metadata
    end

    # @return [Integer]
    def nest_level
      test_class.test_ancestors.length - 1
    end

    # @return [Array<Petitest::Test>]
    def self_and_descendant_tests
      tests + sub_test_groups.flat_map(&:self_and_descendant_tests)
    end

    # @return [Array<Petitest::TestGroup>]
    def sub_test_groups
      @sub_test_groups ||= test_class.children.map(&:generate_test_group)
    end

    # @return [Array<Petitest::Test>]
    def tests
      @tests ||= test_class.test_method_names.map do |test_method_name|
        test_class.new(
          test_group: self,
          test_method_name: test_method_name,
        )
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
petitest-0.3.1 lib/petitest/test_group.rb
petitest-0.3.0 lib/petitest/test_group.rb