source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 2.0 KB
Line 
1#--
2#
3# Author:: Nathaniel Talbott.
4# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
5# License:: Ruby license.
6
7require 'test/unit'
8require 'test/unit/util/observable'
9require 'test/unit/testresult'
10
11module Test
12 module Unit
13 module UI
14
15 # Provides an interface to write any given UI against,
16 # hopefully making it easy to write new UIs.
17 class TestRunnerMediator
18 RESET = name + "::RESET"
19 STARTED = name + "::STARTED"
20 FINISHED = name + "::FINISHED"
21
22 include Util::Observable
23
24 # Creates a new TestRunnerMediator initialized to run
25 # the passed suite.
26 def initialize(suite)
27 @suite = suite
28 end
29
30 # Runs the suite the TestRunnerMediator was created
31 # with.
32 def run_suite
33 Unit.run = true
34 begin_time = Time.now
35 notify_listeners(RESET, @suite.size)
36 result = create_result
37 notify_listeners(STARTED, result)
38 result_listener = result.add_listener(TestResult::CHANGED) do |updated_result|
39 notify_listeners(TestResult::CHANGED, updated_result)
40 end
41
42 fault_listener = result.add_listener(TestResult::FAULT) do |fault|
43 notify_listeners(TestResult::FAULT, fault)
44 end
45
46 @suite.run(result) do |channel, value|
47 notify_listeners(channel, value)
48 end
49
50 result.remove_listener(TestResult::FAULT, fault_listener)
51 result.remove_listener(TestResult::CHANGED, result_listener)
52 end_time = Time.now
53 elapsed_time = end_time - begin_time
54 notify_listeners(FINISHED, elapsed_time) #"Finished in #{elapsed_time} seconds.")
55 return result
56 end
57
58 private
59 # A factory method to create the result the mediator
60 # should run with. Can be overridden by subclasses if
61 # one wants to use a different result.
62 def create_result
63 return TestResult.new
64 end
65 end
66 end
67 end
68end
Note: See TracBrowser for help on using the repository browser.