Sha256: ad4c2bacfdb7b76cf2328b496243181854055fb26d4476394b2be4be24ac9295

Contents?: true

Size: 1.81 KB

Versions: 129

Compression:

Stored size: 1.81 KB

Contents

module Test
  module Unit
    module Collector
      def initialize
        @filters = []
      end

      def filter=(filters)
        @filters = case(filters)
          when Proc
            [filters]
          when Array
            filters
        end
      end

      def add_suite(destination, suite)
        to_delete = suite.tests.find_all do |test|
          test.is_a?(TestCase) and !include?(test)
        end
        suite.delete_tests(to_delete)
        destination << suite unless suite.empty?
      end

      def add_test_cases(suite, test_cases)
        children_map = {}
        test_cases.each do |test_case|
          ancestor_classes = test_case.ancestors.find_all do |ancestor|
            ancestor.is_a?(Class)
          end
          parent = ancestor_classes[1]
          children_map[parent] ||= []
          children_map[parent] << test_case
        end

        root_test_cases = children_map.keys - test_cases
        root_test_cases.each do |root_test_case|
          add_test_case(suite, root_test_case, children_map)
        end
      end

      def include?(test)
        return true if(@filters.empty?)
        @filters.each do |filter|
          return false if filter[test] == false
        end
        true
      end

      def sort(suites)
        suites.sort_by do |suite|
          [suite.priority, suite.name || suite.to_s]
        end
      end

      private
      def add_test_case(suite, test_case, children_map)
        children = children_map[test_case]
        return if children.nil?

        sub_suites = []
        children.each do |child|
          sub_suite = child.suite
          add_test_case(sub_suite, child, children_map)
          add_suite(sub_suites, sub_suite)
        end
        sort(sub_suites).each do |sub_suite|
          suite << sub_suite
        end
      end
    end
  end
end

Version data entries

129 entries across 99 versions & 10 rubygems

Version Path
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/test-unit-3.3.7/lib/test/unit/collector.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/test-unit-3.4.0/lib/test/unit/collector.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/test-unit-3.4.1/lib/test/unit/collector.rb
win32-api-1.10.1 vendor/bundle/ruby/2.5.0/gems/test-unit-3.3.5/lib/test/unit/collector.rb
win32-api-1.10.1 vendor/bundle/ruby/2.5.0/gems/test-unit-3.3.4/lib/test/unit/collector.rb
win32-api-1.10.1 vendor/bundle/ruby/3.0.0/gems/test-unit-3.4.1/lib/test/unit/collector.rb
win32-api-1.10.1 vendor/bundle/ruby/2.7.0/gems/test-unit-3.3.5/lib/test/unit/collector.rb
test-unit-3.4.1 lib/test/unit/collector.rb
win32-api-1.10.0 vendor/bundle/ruby/2.7.0/gems/test-unit-3.3.5/lib/test/unit/collector.rb
win32-api-1.10.0 vendor/bundle/ruby/2.5.0/gems/test-unit-3.3.4/lib/test/unit/collector.rb
win32-api-1.10.0 vendor/bundle/ruby/2.5.0/gems/test-unit-3.3.5/lib/test/unit/collector.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/test-unit-3.3.7/lib/test/unit/collector.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/test-unit-3.4.0/lib/test/unit/collector.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/test-unit-3.3.7/lib/test/unit/collector.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/test-unit-3.4.0/lib/test/unit/collector.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/test-unit-3.3.8/lib/test/unit/collector.rb
test-unit-3.4.0 lib/test/unit/collector.rb
test-unit-3.3.9 lib/test/unit/collector.rb
test-unit-3.3.8 lib/test/unit/collector.rb
tdiary-5.1.4 vendor/bundle/ruby/2.7.0/gems/test-unit-3.3.7/lib/test/unit/collector.rb