Class: Test::Unit::Collector::Dir

### Home Classes Methods

### In Files

- lib/test/unit/collector/dir.rb

### Parent

Object

### Methods

- ::new
- #collect
- #collect_file
- #find_test_cases
- #realdir
- #recursive_collect

### Included Modules

- Test::Unit::Collector

### Class/Module Index

Quicksearch

- Test
- Test::Unit
- Test::Unit::AssertionFailedError
- Test::Unit::Assertions
- Test::Unit::Attribute
- Test::Unit::Attribute::BaseClassMethods
- Test::Unit::Attribute::ClassMethods
- Test::Unit::Attribute::StringifyKeyHash
- Test::Unit::AttributeMatcher
- Test::Unit::AutoRunner
- Test::Unit::CodeSnippetFetcher
- Test::Unit::Collector
- Test::Unit::Collector::Descendant
- Test::Unit::Collector::Dir
- Test::Unit::Collector::Load
- Test::Unit::Collector::ObjectSpace
- Test::Unit::Collector::XML
- Test::Unit::Collector::XML::Listener
- Test::Unit::Color
- Test::Unit::Color::Error
- Test::Unit::Color::ParseError
- Test::Unit::ColorScheme
- Test::Unit::Data
- Test::Unit::Data::ClassMethods
- Test::Unit::Data::ClassMethods::Loader
- Test::Unit::Diff
- Test::Unit::Diff::Differ
- Test::Unit::Diff::ReadableDiffer
- Test::Unit::Diff::SequenceMatcher
- Test::Unit::Diff::UTF8Line
- Test::Unit::Diff::UnifiedDiffer
- Test::Unit::Error
- Test::Unit::ErrorHandler
- Test::Unit::ExceptionHandler
- Test::Unit::ExceptionHandler::ClassMethods
- Test::Unit::Failure
- Test::Unit::FailureHandler
- Test::Unit::FaultLocationDetector
- Test::Unit::Fixture
- Test::Unit::Fixture::ClassMethods
- Test::Unit::MixColor
- Test::Unit::Notification
- Test::Unit::NotificationHandler
- Test::Unit::NotifiedError
- Test::Unit::NullResultContainerInitializer
- Test::Unit::Omission
- Test::Unit::OmissionHandler
- Test::Unit::OmittedError
- Test::Unit::PendedError
- Test::Unit::Pending
- Test::Unit::PendingHandler
- Test::Unit::Priority
- Test::Unit::Priority::Checker
- Test::Unit::Priority::ClassMethods
- Test::Unit::TestCase
- Test::Unit::TestCase::InternalData
- Test::Unit::TestCaseNotificationSupport
- Test::Unit::TestCaseOmissionSupport
- Test::Unit::TestCasePendingSupport
- Test::Unit::TestResult
- Test::Unit::TestResultErrorSupport
- Test::Unit::TestResultFailureSupport
- Test::Unit::TestResultNotificationSupport
- Test::Unit::TestResultOmissionSupport
- Test::Unit::TestResultPendingSupport
- Test::Unit::TestSuite
- Test::Unit::UI
- Test::Unit::UI::Console
- Test::Unit::UI::Console::ColorizedReadableDiffer
- Test::Unit::UI::Console::OutputLevel
- Test::Unit::UI::Console::TestRunner
- Test::Unit::UI::Emacs
- Test::Unit::UI::Emacs::TestRunner
- Test::Unit::UI::TestRunner
- Test::Unit::UI::TestRunnerMediator
- Test::Unit::UI::TestRunnerUtilities
- Test::Unit::UI::XML
- Test::Unit::UI::XML::TestRunner
- Test::Unit::Util
- Test::Unit::Util::BacktraceFilter
- Test::Unit::Util::MethodOwnerFinder
- Test::Unit::Util::Observable
- Test::Unit::Util::Output
- Test::Unit::Util::ProcWrapper
- Object

No matching classes.

# Test::Unit::Collector::Dir

### Attributes

base[RW]
exclude[R]
pattern[R]

### Public Class Methods

new(dir=::Dir, file=::File, object_space=::ObjectSpace, req=nil) click to toggle source

    # File lib/test/unit/collector/dir.rb, line 13
    def initialize(dir=::Dir, file=::File, object_space=::ObjectSpace, req=nil)
      super()
      @dir = dir
      @file = file
      @object_space = object_space
      @req = req
      @pattern = [/\btest_.*\.rb\Z/]
      @exclude = []
      @base = nil
    end

### Public Instance Methods

collect(*from) click to toggle source

    # File lib/test/unit/collector/dir.rb, line 24
    def collect(*from)
      basedir = @base
      $:.push(basedir) if basedir
      if(from.empty?)
        recursive_collect('.', find_test_cases)
      elsif(from.size == 1)
        recursive_collect(from.first, find_test_cases)
      else
        suites = []
        from.each do |f|
          suite = recursive_collect(f, find_test_cases)
          suites << suite unless(suite.tests.empty?)
        end
        suite = TestSuite.new("[#{from.join(', ')}]")
        sort(suites).each{|s| suite << s}
        suite
      end
    ensure
      $:.delete_at($:.rindex(basedir)) if basedir
    end

collect_file(name, suites, already_gathered) click to toggle source

    # File lib/test/unit/collector/dir.rb, line 85
    def collect_file(name, suites, already_gathered)
      dir = @file.dirname(@file.expand_path(name, @base))
      $:.unshift(dir)
      if(@req)
        @req.require(name)
      else
        require(name)
      end
      find_test_cases(already_gathered).each{|t| add_suite(suites, t.suite)}
    ensure
      $:.delete_at($:.rindex(dir)) if(dir)
    end

find_test_cases(ignore=[]) click to toggle source

    # File lib/test/unit/collector/dir.rb, line 45
    def find_test_cases(ignore=[])
      cases = []
      @object_space.each_object(Class) do |c|
        cases << c if(c < TestCase && !ignore.include?(c))
      end
      ignore.concat(cases)
      cases
    end

realdir(path) click to toggle source

    # File lib/test/unit/collector/dir.rb, line 98
    def realdir(path)
      if @base
        @file.join(@base, path)
      else
        path
      end
    end

recursive_collect(name, already_gathered) click to toggle source

    # File lib/test/unit/collector/dir.rb, line 54
    def recursive_collect(name, already_gathered)
      sub_suites = []
      path = realdir(name)
      if @file.directory?(path)
        dir_name = name unless name == '.'
        @dir.entries(path).each do |e|
          next if(e == '.' || e == '..')
          e_name = dir_name ? @file.join(dir_name, e) : e
          if @file.directory?(realdir(e_name))
            next if /\A(?:CVS|\.svn|\.git)\z/ =~ e
            sub_suite = recursive_collect(e_name, already_gathered)
            sub_suites << sub_suite unless(sub_suite.empty?)
          else
            next if /~\z/ =~ e_name or /\A\.\#/ =~ e
            if @pattern and !@pattern.empty?
              next unless @pattern.any? {|pat| pat =~ e_name}
            end
            if @exclude and !@exclude.empty?
              next if @exclude.any? {|pat| pat =~ e_name}
            end
            collect_file(e_name, sub_suites, already_gathered)
          end
        end
      else
        collect_file(name, sub_suites, already_gathered)
      end
      suite = TestSuite.new(@file.basename(name))
      sort(sub_suites).each{|s| suite << s}
      suite
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.