Class: Test::Unit::Collector::Load

Inherits:
Object
  • Object
show all
Includes:
Test::Unit::Collector
Defined in:
lib/test/unit/collector/load.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Test::Unit::Collector

#add_suite, #add_test_cases, #filter=, #include?, #sort

Constructor Details

#initializeLoad

Returns a new instance of Load.



15
16
17
18
19
20
21
22
23
24
# File 'lib/test/unit/collector/load.rb', line 15

def initialize
  super
  @system_excludes = [/~\z/, /\A\.\#/]
  @system_directory_excludes = [/\A(?:CVS|\.svn|\.git)\z/]
  @patterns = [/\Atest[_\-].+\.rb\z/m, /[_\-]test\.rb\z/]
  @excludes = []
  @base = nil
  @default_test_paths = []
  @require_failed_infos = []
end

Instance Attribute Details

#baseObject

Returns the value of attribute base.



12
13
14
# File 'lib/test/unit/collector/load.rb', line 12

def base
  @base
end

#default_test_pathsObject

Returns the value of attribute default_test_paths.



13
14
15
# File 'lib/test/unit/collector/load.rb', line 13

def default_test_paths
  @default_test_paths
end

#excludesObject (readonly)

Returns the value of attribute excludes.



12
13
14
# File 'lib/test/unit/collector/load.rb', line 12

def excludes
  @excludes
end

#patternsObject (readonly)

Returns the value of attribute patterns.



12
13
14
# File 'lib/test/unit/collector/load.rb', line 12

def patterns
  @patterns
end

Instance Method Details

#collect(*froms) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/test/unit/collector/load.rb', line 37

def collect(*froms)
  add_load_path(@base) do
    froms = @default_test_paths if froms.empty?
    froms = ["."] if froms.empty?
    test_suites = []
    already_gathered = {}
    find_test_cases(already_gathered)
    froms.each do |from|
      from = resolve_path(from)
      if from.directory?
        test_suite = collect_recursive(from, already_gathered)
        test_suites << test_suite unless test_suite.tests.empty?
      else
        collect_file(from, test_suites, already_gathered)
      end
    end
    add_require_failed_test_suite(test_suites)

    if test_suites.size > 1
      test_suite = TestSuite.new("[#{froms.join(', ')}]")
      sort(test_suites).each do |sub_test_suite|
        test_suite << sub_test_suite
      end
    else
      test_suite = test_suites.first
    end

    adjust_ractor_tests(test_suite)

    test_suite
  end
end

#find_test_cases(already_gathered) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/test/unit/collector/load.rb', line 70

def find_test_cases(already_gathered)
  test_cases = []
  TestCase::DESCENDANTS.each do |test_case|
    next if already_gathered.key?(test_case)
    test_cases << test_case
    already_gathered[test_case] = true
  end
  test_cases
end