diff options
| author | ntalbott <ntalbott@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-02-12 03:12:14 +0000 |
|---|---|---|
| committer | ntalbott <ntalbott@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-02-12 03:12:14 +0000 |
| commit | f4fade43ce5d51ab9e35463a0ee093a695286741 (patch) | |
| tree | 4354dc87a540b777a7eb6a2276f44be51ec8bebb /lib/test/unit/ui/testrunnermediator.rb | |
| parent | 045623d3287ee000a1c7e8275a643e88081132d2 (diff) | |
| download | ruby-f4fade43ce5d51ab9e35463a0ee093a695286741.tar.gz ruby-f4fade43ce5d51ab9e35463a0ee093a695286741.tar.xz ruby-f4fade43ce5d51ab9e35463a0ee093a695286741.zip | |
Initial revision
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/test/unit/ui/testrunnermediator.rb')
| -rw-r--r-- | lib/test/unit/ui/testrunnermediator.rb | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/lib/test/unit/ui/testrunnermediator.rb b/lib/test/unit/ui/testrunnermediator.rb new file mode 100644 index 000000000..41c77dc7a --- /dev/null +++ b/lib/test/unit/ui/testrunnermediator.rb @@ -0,0 +1,75 @@ +# :nodoc: +# +# Author:: Nathaniel Talbott. +# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. +# License:: Ruby license. + +require 'test/unit/util/observable' +require 'test/unit/testresult' + +module Test + module Unit + module UI # :nodoc: + + # Provides an interface to write any given UI against, + # hopefully making it easy to write new UIs. + class TestRunnerMediator + RESET = name + "::RESET" + STARTED = name + "::STARTED" + FINISHED = name + "::FINISHED" + + include Util::Observable + + @@run = false + + # Returns true if any TestRunnerMediator instances + # have been run. + def self.run? + return @@run + end + + # Creates a new TestRunnerMediator initialized to run + # the passed suite. + def initialize(suite) + @suite = suite + end + + # Runs the suite the TestRunnerMediator was created + # with. + def run_suite + @@run = true + begin_time = Time.now + notify_listeners(RESET, @suite.size) + result = create_result + notify_listeners(STARTED, result) + result_listener = result.add_listener(TestResult::CHANGED) do |updated_result| + notify_listeners(TestResult::CHANGED, updated_result) + end + + fault_listener = result.add_listener(TestResult::FAULT) do |fault| + notify_listeners(TestResult::FAULT, fault) + end + + @suite.run(result) do |channel, value| + notify_listeners(channel, value) + end + + result.remove_listener(TestResult::FAULT, fault_listener) + result.remove_listener(TestResult::CHANGED, result_listener) + end_time = Time.now + elapsed_time = end_time - begin_time + notify_listeners(FINISHED, elapsed_time) #"Finished in #{elapsed_time} seconds.") + return result + end + + private + # 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. + def create_result + return TestResult.new + end + end + end + end +end |
