123456789_123456789_123456789_123456789_123456789_

Class: Test::Unit::TestSuiteRunner

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: lib/test/unit/test-suite-runner.rb

Class Attribute Summary

Class Method Summary

Instance Method Summary

Constructor Details

.new(test_suite) ⇒ TestSuiteRunner

[ GitHub ]

  
# File 'lib/test/unit/test-suite-runner.rb', line 29

def initialize(test_suite)
  @test_suite = test_suite
end

Class Attribute Details

.n_workers (rw)

[ GitHub ]

  
# File 'lib/test/unit/test-suite-runner.rb', line 20

def n_workers
  @n_workers
end

.n_workers=(n) (rw)

[ GitHub ]

  
# File 'lib/test/unit/test-suite-runner.rb', line 24

def n_workers=(n)
  @n_workers = n
end

Class Method Details

.run_all_tests

[ GitHub ]

  
# File 'lib/test/unit/test-suite-runner.rb', line 16

def run_all_tests
  yield
end

Instance Method Details

#handle_exception(exception, result) (private)

[ GitHub ]

  
# File 'lib/test/unit/test-suite-runner.rb', line 108

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(result, &progress_block)

[ GitHub ]

  
# File '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

#run_shutdown(result) (private)

[ GitHub ]

  
# File 'lib/test/unit/test-suite-runner.rb', line 98

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) (private)

[ GitHub ]

  
# File '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) (private)

[ GitHub ]

  
# File '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
  test.run(result, runner: self.class) 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 finished_is_yielded and not finished_object_is_yielded
    yield(Test::Unit::TestCase::FINISHED_OBJECT, test)
  end
end

#run_tests(result, &progress_block) (private)

[ GitHub ]

  
# File '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