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.



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

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
  @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

#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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/test/unit/collector/load.rb', line 29

def collect(*froms)
  add_load_path(@base) do
    froms = ["."] if froms.empty?
    test_suites = []
    already_gathered = find_test_cases
    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

    test_suite
  end
end

#find_test_cases(ignore = []) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/test/unit/collector/load.rb', line 58

def find_test_cases(ignore=[])
  test_cases = []
  TestCase::DESCENDANTS.each do |test_case|
    test_cases << test_case unless ignore.include?(test_case)
  end
  ignore.concat(test_cases)
  test_cases
end