Class: LeftRight::Runner
- Inherits:
-
Test::Unit::UI::Console::TestRunner
- Object
- Test::Unit::UI::Console::TestRunner
- LeftRight::Runner
- Defined in:
- lib/leftright/runner.rb
Instance Method Summary collapse
-
#add_fault(fault) ⇒ Object
We intercept this to be able to set some pertinent state.
-
#finished(elapsed_time) ⇒ Object
This prints the final summary at the end of all tests.
-
#lr ⇒ Object
Access to the LeftRight module from the Runner instance.
-
#output_single(captured, *etc) ⇒ Object
Test::Unit uses this method to print ‘.’, ‘F’, ‘E’, and possibly others.
-
#test_started(test_name) ⇒ Object
We intercept this to be able to set some pertinent state.
Instance Method Details
#add_fault(fault) ⇒ Object
We intercept this to be able to set some pertinent state
22 23 24 25 |
# File 'lib/leftright/runner.rb', line 22 def add_fault(fault) lr.state.fault = fault super end |
#finished(elapsed_time) ⇒ Object
This prints the final summary at the end of all tests.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/leftright/runner.rb', line 69 def finished(elapsed_time) passed_count = @result.run_count - @result.failure_count - @result.error_count - lr.state.skipped_count total = { :passed => passed_count, :failed => @result.failure_count, :errors => @result.error_count, :tests => @result.run_count, :skipped => lr.state.skipped_count } results = [] unless passed_count.zero? total[:passed] = 'all' if passed_count == @result.run_count results << lr::C.green("#{total[:passed]} passed") end unless lr.state.skipped_count.zero? results << lr::C.cyan("#{total[:skipped]} skipped") end unless @result.failure_count.zero? results << lr::C.red("#{total[:failed]} failed") end unless @result.error_count.zero? plural = @result.error_count > 1 ? 'errors' : 'error' results << lr::C.yellow("#{total[:errors]} #{plural}") end @io.write "\n" @io.write "\n" unless lr.state.previous_failed @io.write "#{total[:tests]} test#{'s' if @result.run_count > 1}: " @io.write results.join(', ').reverse.sub(',', 'dna ').reverse # :( @io.write "\n" + "\n" @io.puts "(#{elapsed_time} seconds)" end |
#lr ⇒ Object
Access to the LeftRight module from the Runner instance. Hopefully to reduce the likelyhood of future name clashes.
8 9 10 |
# File 'lib/leftright/runner.rb', line 8 def lr LeftRight end |
#output_single(captured, *etc) ⇒ Object
Test::Unit uses this method to print ‘.’, ‘F’, ‘E’, and possibly others. We do most of the work here, using the state saved in ‘add_fault’ and ‘test_finished’.
31 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 |
# File 'lib/leftright/runner.rb', line 31 def output_single(captured, *etc) # Make sure we are printing a test result return super unless %w[ . F E ].include? captured # Do nothing if the method was a skipper return if lr.state.skip && '.' == captured output = case captured when '.' then lr.P when 'F' then lr.F when 'E' then lr.E end if lr.state.last_class_printed != lr.state.class # If we're here, we need to print a new class name on the left side lr.state.last_class_printed = lr.state.class lr.state.dots = 0 @io.write "\n" @io.write lr.justify_left_side( lr.format_class_name(lr.state.class.name)) elsif captured != '.' # This handles the edge case when the first test for a class fails @io.write "\n" @io.write lr.justify_left_side end # Justify all lines but first: output.gsub! "\n", "\n" + lr.justify_left_side @io.write output ensure # reset all of the nasty state stuff @io.flush lr.state.previous_failed = captured != '.' lr.state.skip = false end |
#test_started(test_name) ⇒ Object
We intercept this to be able to set some pertinent state.
14 15 16 17 18 19 |
# File 'lib/leftright/runner.rb', line 14 def test_started(test_name) name = lr.extract_class_name test_name lr.state.class = lr.testcase_classes.detect { |c| c.name == name } super end |