class Test::Unit::TestSuiteRunner - test-unit: Ruby Standard Library Documentation

# class Test::Unit::TestSuiteRunner

### Public Class Methods

n_workers() click to toggle source

    # File test-unit-3.6.7/lib/test/unit/test-suite-runner.rb, line 20
    def n_workers
      @n_workers
    end

n_workers=(n) click to toggle source

    # File test-unit-3.6.7/lib/test/unit/test-suite-runner.rb, line 24
    def n_workers=(n)
      @n_workers = n
    end

new(test_suite) click to toggle source

    # File test-unit-3.6.7/lib/test/unit/test-suite-runner.rb, line 29
    def initialize(test_suite)
      @test_suite = test_suite
    end

run_all_tests() { || ... } click to toggle source

    # File test-unit-3.6.7/lib/test/unit/test-suite-runner.rb, line 16
    def run_all_tests
      yield
    end

### Public Instance Methods

run(result) { |STARTED, name| ... } click to toggle source

    # File test-unit-3.6.7/lib/test/unit/test-suite-runner.rb, line 33
    def run(result, &progress_block)
      yield(TestSuite::STARTED, @test_suite.name)
      yield(TestSuite::STARTED_OBJECT, @test_suite)
      run_startup(result)
      run_tests(result, &progress_block)
    ensure
      begin
        run_shutdown(result)
      ensure
        yield(TestSuite::FINISHED, @test_suite.name)
        yield(TestSuite::FINISHED_OBJECT, @test_suite)
      end
    end

### Private Instance Methods

handle_exception(exception, result) click to toggle source

    # File test-unit-3.6.7/lib/test/unit/test-suite-runner.rb, line 116
    def handle_exception(exception, result)
      case exception
      when *ErrorHandler::PASS_THROUGH_EXCEPTIONS
        false
      else
        result.add_error(Error.new(@test_suite.test_case.name, exception))
        true
      end
    end

run_shutdown(result) click to toggle source

    # File test-unit-3.6.7/lib/test/unit/test-suite-runner.rb, line 106
    def run_shutdown(result)
      test_case = @test_suite.test_case
      return if test_case.nil? or !test_case.respond_to?(:shutdown)
      begin
        test_case.shutdown
      rescue Exception
        raise unless handle_exception($!, result)
      end
    end

run_startup(result) click to toggle source

    # File test-unit-3.6.7/lib/test/unit/test-suite-runner.rb, line 48
    def run_startup(result)
      test_case = @test_suite.test_case
      return if test_case.nil? or !test_case.respond_to?(:startup)
      begin
        test_case.startup
      rescue Exception
        raise unless handle_exception($!, result)
      end
    end

run_test(test, result) { |STARTED_OBJECT, test| ... } click to toggle source

    # File test-unit-3.6.7/lib/test/unit/test-suite-runner.rb, line 64
    def run_test(test, result)
      finished_is_yielded = false
      finished_object_is_yielded = false
      previous_event_name = nil
      event_listener = lambda do |event_name, *args|
        case previous_event_name
        when Test::Unit::TestCase::STARTED
          if event_name != Test::Unit::TestCase::STARTED_OBJECT
            yield(Test::Unit::TestCase::STARTED_OBJECT, test)
          end
        when Test::Unit::TestCase::FINISHED
          if event_name != Test::Unit::TestCase::FINISHED_OBJECT
            yield(Test::Unit::TestCase::FINISHED_OBJECT, test)
          end
          finished_object_is_yielded = true
        end

        case event_name
        when Test::Unit::TestCase::STARTED
          finished_is_yielded = false
          finished_object_is_yielded = false
        when Test::Unit::TestCase::FINISHED
          finished_is_yielded = true
        end

        previous_event_name = event_name
        yield(event_name, *args)
      end

      if test.method(:run).arity == -2
        test.run(result, runner_class: self.class, &event_listener)
      else
        # For backward compatibility. There are scripts that overrides
        # Test::Unit::TestCase#run without keyword arguments.
        test.run(result, &event_listener)
      end

      if finished_is_yielded and not finished_object_is_yielded
        yield(Test::Unit::TestCase::FINISHED_OBJECT, test)
      end
    end

run_tests(result, &progress_block) click to toggle source

    # File test-unit-3.6.7/lib/test/unit/test-suite-runner.rb, line 58
    def run_tests(result, &progress_block)
      @test_suite.tests.each do |test|
        run_test(test, result, &progress_block)
      end
    end