Class: Test::Unit::UI::TestRunnerMediator

Inherits:
Object
  • Object
show all
Includes:
Test::Unit::Util::Observable
Defined in:
lib/test/unit/ui/testrunnermediator.rb

Overview

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

Constant Summary collapse

RESET =
name + "::RESET"
STARTED =
name + "::STARTED"
FINISHED =
name + "::FINISHED"

Constants included from Test::Unit::Util::Observable

Test::Unit::Util::Observable::NOTHING

Instance Method Summary collapse

Methods included from Test::Unit::Util::Observable

#add_listener, #notify_listeners, #remove_listener

Constructor Details

#initialize(suite) ⇒ TestRunnerMediator

Creates a new TestRunnerMediator initialized to run the passed suite.



26
27
28
# File 'lib/test/unit/ui/testrunnermediator.rb', line 26

def initialize(suite)
  @suite = suite
end

Instance Method Details

#run_suiteObject

Runs the suite the TestRunnerMediator was created with.



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
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/test/unit/ui/testrunnermediator.rb', line 32

def run_suite
  Unit.run = true

  result = create_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

  start_time = Time.now
  begin
    notify_listeners(RESET, @suite.size)
    notify_listeners(STARTED, result)

    @suite.run(result) do |channel, value|
      notify_listeners(channel, value)
    end
  ensure
    elapsed_time = Time.now - start_time
    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)
    notify_listeners(FINISHED, elapsed_time)
  end

  result
end