Sha256: fe6225e3b732ac9ac3fbc070455c3b5ae9d3c0bd88a5afc8793bdf5330fea909

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

module Petitest
  class TestGroup
    include ::Petitest::Assertions

    TEST_METHOD_NAME_PREFIX = "test_"

    class << self
      # @return [Array<Class>]
      def descendants
        @@descendants ||= []
      end

      # @note Override
      def inherited(sub_class)
        super
        descendants << sub_class
      end

      # @return [Array<Petit::TestCase]
      def test_cases
        descendants.flat_map do |test_group_class|
          test_group_class.test_methods.map do |test_method|
            ::Petitest::TestCase.new(
              test_group_class: test_group_class,
              test_method: test_method,
            )
          end
        end
      end

      # @return [Array<String>]
      def test_method_names
        public_instance_methods.map(&:to_s).select do |method_name|
          method_name.start_with?(TEST_METHOD_NAME_PREFIX)
        end
      end

      # @return [Array<Petitest::TestMethod>]
      def test_methods
        test_method_names.map do |method_name|
          unbound_method = public_instance_method(method_name)
          ::Petitest::TestMethod.new(
            line_number: unbound_method.source_location[1],
            method_name: method_name.to_s,
            path: unbound_method.source_location[0],
          )
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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