Class: Test::Unit::UI::TestRunnerMediator
- Inherits:
-
Object
- Object
- Test::Unit::UI::TestRunnerMediator
- Defined in:
- lib/test_extensions/register_additional_observers.rb
Class Method Summary collapse
-
.register_additional_observers(&block) ⇒ Object
Test::Unit uses listeners to notify the UI of test progress, failures, etc.
Instance Method Summary collapse
Class Method Details
.register_additional_observers(&block) ⇒ Object
Test::Unit uses listeners to notify the UI of test progress, failures, etc. That’s great, if you’re writing a new UI. But unfortunately, it doesn’t provide an easy way (that I could find) to add your own listeners (for things other than the UI). The only place that I see add_listener used anywhere in Test::Unit is in the UI classes (ui/*/testrunner.rb).
So how does one hook into Test::Unit to register/add a listener for things without writing a new UI? (Let’s assume we’re perfectly happy with the Test::Unit::UI::Console UI…)
They’ve provided some nice “events” (“channels”?) – like TestCase::STARTED, TestCase::FINISHED, TestResult::FAULT – but how do I register with Test::Unit that I want to be notified of those events too?
Also, add_listener is an instance method – how do you get inside of TestCase/TestRunnerMediator so that you have an instance?
I wanted to add my own listener callback. So that’s why I wrote this monkey patch… (If there’s an easier way, let me know…)
-
Test::Unit::TestCase::FINISHED – Seems to be called not when the entire TestCase has finished running (as the name would suggest) but after every test method in the TestCase…?
-
Test::Unit::UI::TestRunnerMediator::FINISHED – When all the tests for a whole suite have finished
32 33 34 35 |
# File 'lib/test_extensions/register_additional_observers.rb', line 32 def self.register_additional_observers(&block) @@additional_observers_procs ||= [] @@additional_observers_procs.push block end |
Instance Method Details
#run_suite_with_additional_observers ⇒ Object
36 37 38 39 40 41 |
# File 'lib/test_extensions/register_additional_observers.rb', line 36 def run_suite_with_additional_observers @@additional_observers_procs.each do |proc| proc.call(self) end if defined?(@@additional_observers_procs) run_suite_without_additional_observers end |