Class: DohTest::StreamOutput
- Inherits:
-
Object
- Object
- DohTest::StreamOutput
- Defined in:
- lib/dohtest/stream_output.rb
Constant Summary collapse
- DEFAULT_COLORS =
{:failure => :red, :error => :magenta, :info => :blue, :success => :green}.freeze
Instance Method Summary collapse
- #assertion_failed(group_name, test_name, failure, seed) ⇒ Object
- #assertion_passed(group_name, test_name) ⇒ Object
- #callback_failed(proc_name) ⇒ Object
- #group_begin(group_name) ⇒ Object
- #group_end(group_name, tests_ran, tests_skipped, assertions_passed, assertions_failed) ⇒ Object
-
#initialize(std_ios = nil, err_ios = nil) ⇒ StreamOutput
constructor
A new instance of StreamOutput.
- #run_begin(config) ⇒ Object
- #run_end(duration) ⇒ Object
- #test_begin(group_name, test_name) ⇒ Object
- #test_end(group_name, test_name) ⇒ Object
- #test_error(group_name, test_name, error, seed) ⇒ Object
Constructor Details
#initialize(std_ios = nil, err_ios = nil) ⇒ StreamOutput
Returns a new instance of StreamOutput.
10 11 12 13 14 15 16 |
# File 'lib/dohtest/stream_output.rb', line 10 def initialize(std_ios = nil, err_ios = nil) @error_count = @groups_ran = @groups_skipped = @tests_ran = @tests_skipped = @assertions_failed = @assertions_passed = 0 @callbacks_succeeded = true @badness = Set.new @std_ios = std_ios || $stdout @err_ios = err_ios || $stderr end |
Instance Method Details
#assertion_failed(group_name, test_name, failure, seed) ⇒ Object
115 116 117 118 119 |
# File 'lib/dohtest/stream_output.rb', line 115 def assertion_failed(group_name, test_name, failure, seed) @badness.add(group_name) @assertions_failed += 1 display_badness(group_name, test_name, failure, seed) end |
#assertion_passed(group_name, test_name) ⇒ Object
126 127 128 |
# File 'lib/dohtest/stream_output.rb', line 126 def assertion_passed(group_name, test_name) @assertions_passed += 1 end |
#callback_failed(proc_name) ⇒ Object
121 122 123 124 |
# File 'lib/dohtest/stream_output.rb', line 121 def callback_failed(proc_name) @callbacks_succeeded = false @err_ios.puts colorize(:error, "callback #{proc_name} failed") end |
#group_begin(group_name) ⇒ Object
78 79 80 |
# File 'lib/dohtest/stream_output.rb', line 78 def group_begin(group_name) puts "running group #{group_name}" if @extra_verbose end |
#group_end(group_name, tests_ran, tests_skipped, assertions_passed, assertions_failed) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/dohtest/stream_output.rb', line 82 def group_end(group_name, tests_ran, tests_skipped, assertions_passed, assertions_failed) @tests_skipped += tests_skipped if tests_ran == 0 if tests_skipped > 0 @groups_skipped += 1 else @std_ios.puts colorize(:info, "no tests defined in #{group_name}") end return end @groups_ran += 1 total_tests = tests_ran + tests_skipped total_assertions = assertions_passed + assertions_failed if @verbose skipped_str = if tests_skipped > 0 then ": #{tests_ran} ran, #{tests_skipped} skipped" else '' end @std_ios.puts "success in #{group_name}: #{total_tests} tests#{skipped_str}; #{total_assertions} assertions" unless @badness.include?(group_name) end end |
#run_begin(config) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/dohtest/stream_output.rb', line 18 def run_begin(config) @config = config @std_ios.puts "running tests with config: #{config}" has_terminal = @std_ios.tty? @no_color = !has_terminal || @config[:no_color] @verbose = (has_terminal && !@config[:quiet]) || @config[:verbose] @extra_verbose = @config[:extra_verbose] end |
#run_end(duration) ⇒ Object
28 29 30 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 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/dohtest/stream_output.rb', line 28 def run_end(duration) total_assertions = @assertions_passed + @assertions_failed if duration >= 1 tests_per_second = (@tests_ran / duration).round(2) assertions_per_second = (total_assertions / duration).round(2) @std_ios.puts "\n\ncompleted in #{duration.round(2)}s, #{tests_per_second} tests/s, #{assertions_per_second} assertions/s" else @std_ios.puts "\n\ncompleted in #{duration.round(2)}s" end if @error_count == 0 error_str = "0 errors" else error_str = colorize(:error, "#@error_count errors") end if @groups_skipped == 0 group_str = "#@groups_ran groups" else total_groups = @groups_ran + @groups_skipped group_str = "#{total_groups} groups: #@groups_ran ran, #@groups_skipped skipped" end if @tests_skipped == 0 test_str = "#@tests_ran tests" else total_tests = @tests_ran + @tests_skipped test_str = "#{total_tests} tests: #@tests_ran ran, #@tests_skipped skipped" end if total_assertions == 0 assertion_str = colorize(:info, "no assertions run") elsif @assertions_failed == 0 assertion_str = "all #{total_assertions} assertions passed" else failed_str = colorize(:failure, "#@assertions_failed failed") assertion_str = "#{total_assertions} assertions: #@assertions_passed passed, #{failed_str}" end success = (total_assertions > 0) && (@error_count == 0) && (@assertions_failed == 0) && @callbacks_succeeded msg = "#{error_str}; #{group_str}; #{test_str}; #{assertion_str}" msg = colorize(:success, msg) if success @std_ios.puts msg # this is to generate an exit code; true translates to 0, false to 1 success end |
#test_begin(group_name, test_name) ⇒ Object
101 102 103 |
# File 'lib/dohtest/stream_output.rb', line 101 def test_begin(group_name, test_name) puts "running test #{test_name}" if @extra_verbose end |
#test_end(group_name, test_name) ⇒ Object
105 106 107 |
# File 'lib/dohtest/stream_output.rb', line 105 def test_end(group_name, test_name) @tests_ran += 1 end |
#test_error(group_name, test_name, error, seed) ⇒ Object
109 110 111 112 113 |
# File 'lib/dohtest/stream_output.rb', line 109 def test_error(group_name, test_name, error, seed) @badness.add(group_name) @error_count += 1 display_badness(group_name, test_name, error, seed) end |