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.
- #no_tests_found ⇒ Object
- #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
117 118 119 120 121 |
# File 'lib/dohtest/stream_output.rb', line 117 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
128 129 130 |
# File 'lib/dohtest/stream_output.rb', line 128 def assertion_passed(group_name, test_name) @assertions_passed += 1 end |
#callback_failed(proc_name) ⇒ Object
123 124 125 126 |
# File 'lib/dohtest/stream_output.rb', line 123 def callback_failed(proc_name) @callbacks_succeeded = false @err_ios.puts colorize(:error, "callback #{proc_name} failed") end |
#group_begin(group_name) ⇒ Object
80 81 82 |
# File 'lib/dohtest/stream_output.rb', line 80 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
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/dohtest/stream_output.rb', line 84 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 |
#no_tests_found ⇒ Object
132 133 134 |
# File 'lib/dohtest/stream_output.rb', line 132 def no_tests_found @err_ios.puts("\nno tests found") end |
#run_begin(config) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dohtest/stream_output.rb', line 18 def run_begin(config) display_config = config.dup display_config.delete(:test_files) @std_ios.puts "running tests with config: #{display_config}" @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
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 77 78 |
# File 'lib/dohtest/stream_output.rb', line 30 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
103 104 105 |
# File 'lib/dohtest/stream_output.rb', line 103 def test_begin(group_name, test_name) puts "running test #{test_name}" if @extra_verbose end |
#test_end(group_name, test_name) ⇒ Object
107 108 109 |
# File 'lib/dohtest/stream_output.rb', line 107 def test_end(group_name, test_name) @tests_ran += 1 end |
#test_error(group_name, test_name, error, seed) ⇒ Object
111 112 113 114 115 |
# File 'lib/dohtest/stream_output.rb', line 111 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 |