class Test::Unit::UI::TestRunnerMediator - test-unit: Ruby Standard Library Documentation

# class Test::Unit::UI::TestRunnerMediator

Provides an interface to write any given `UI` against, hopefully making it easy to write new UIs.

### Constants

FINISHED
RESET
STARTED

### Public Class Methods

new(suite, options={}) click to toggle source

Creates a new `TestRunnerMediator` initialized to run the passed suite.

    # File test-unit-3.6.7/lib/test/unit/ui/testrunnermediator.rb, line 25
    def initialize(suite, options={})
      @suite = suite
      @options = options
      @test_suite_runner_class = @options[:test_suite_runner_class]
      @test_suite_runner_class ||= TestSuiteRunner
    end

### Public Instance Methods

run() click to toggle source

Runs the suite the `TestRunnerMediator` was created with.

    # File test-unit-3.6.7/lib/test/unit/ui/testrunnermediator.rb, line 34
    def run
      AutoRunner.need_auto_run = false

      result = create_result

      Test::Unit.run_at_start_hooks
      start_time = Time.now
      begin
        with_listener(result) do
          @test_suite_runner_class.run_all_tests do
            catch do |stop_tag|
              result.stop_tag = stop_tag
              notify_listeners(RESET, @suite.size)
              notify_listeners(STARTED, result)

              run_suite(result)
            end
          end
        end
      ensure
        elapsed_time = Time.now - start_time
        notify_listeners(FINISHED, elapsed_time)
      end
      Test::Unit.run_at_exit_hooks

      result
    end

run_suite(result=nil) click to toggle source

Just for backward compatibility for NetBeans. NetBeans should not use monkey patching. NetBeans should use runner change public API.

See GitHub#38

    https://github.com/test-unit/test-unit/issues/38

    # File test-unit-3.6.7/lib/test/unit/ui/testrunnermediator.rb, line 68
    def run_suite(result=nil)
      if result.nil?
        run
      else
        @suite.run(result, runner_class: @test_suite_runner_class) do |channel, value|
          notify_listeners(channel, value)
        end
      end
    end

### Private Instance Methods

create_result() click to toggle source

A factory method to create the result the mediator should run with. Can be overridden by subclasses if one wants to use a different result.

    # File test-unit-3.6.7/lib/test/unit/ui/testrunnermediator.rb, line 82
    def create_result
      TestResult.new
    end

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

    # File test-unit-3.6.7/lib/test/unit/ui/testrunnermediator.rb, line 86
    def measure_time
      begin_time = Time.now
      yield
      Time.now - begin_time
    end

with_listener(result) { || ... } click to toggle source

    # File test-unit-3.6.7/lib/test/unit/ui/testrunnermediator.rb, line 92
    def with_listener(result)
      finished_listener = result.add_listener(TestResult::FINISHED) do |*args|
        notify_listeners(TestResult::FINISHED, *args)
      end
      changed_listener = result.add_listener(TestResult::CHANGED) do |*args|
        notify_listeners(TestResult::CHANGED, *args)
      end
      pass_assertion_listener = result.add_listener(TestResult::PASS_ASSERTION) do |*args|
        notify_listeners(TestResult::PASS_ASSERTION, *args)
      end
      fault_listener = result.add_listener(TestResult::FAULT) do |*args|
        notify_listeners(TestResult::FAULT, *args)
      end

      begin
        yield
      ensure
        result.remove_listener(TestResult::FAULT, fault_listener)
        result.remove_listener(TestResult::CHANGED, changed_listener)
        result.remove_listener(TestResult::FINISHED, finished_listener)
        result.remove_listener(TestResult::PASS_ASSERTION,
                               pass_assertion_listener)
      end
    end