Class: TLDR::Reporters::Default
- Defined in:
- lib/tldr/reporters/default.rb
Instance Method Summary collapse
- #after_fail_fast(planned_tests, wip_tests, test_results, last_result) ⇒ Object
- #after_suite(test_results) ⇒ Object
- #after_test(result) ⇒ Object
- #after_tldr(planned_tests, wip_tests, test_results) ⇒ Object
- #before_suite(tests) ⇒ Object
-
#initialize(config, out = $stdout, err = $stderr) ⇒ Default
constructor
A new instance of Default.
Constructor Details
#initialize(config, out = $stdout, err = $stderr) ⇒ Default
Returns a new instance of Default.
4 5 6 7 |
# File 'lib/tldr/reporters/default.rb', line 4 def initialize config, out = $stdout, err = $stderr super @icons = @config.no_emoji ? IconProvider::Base.new : IconProvider::Emoji.new end |
Instance Method Details
#after_fail_fast(planned_tests, wip_tests, test_results, last_result) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/tldr/reporters/default.rb', line 65 def after_fail_fast planned_tests, wip_tests, test_results, last_result unrun_tests = planned_tests - test_results.map(&:test) - wip_tests.map(&:test) @err.print "\n\n" wrap_in_horizontal_rule do @err.print [ "Failing fast after #{describe(last_result.test, last_result.relevant_location)} #{last_result.error? ? "errored" : "failed"}.", ("#{@icons.wip} #{plural(wip_tests.size, "test was", "tests were")} cancelled in progress." if wip_tests.any?), ("#{@icons.not_run} #{plural(unrun_tests.size, "test was", "tests were")} not run at all." if unrun_tests.any?), describe_tests_that_didnt_finish(planned_tests, test_results) ].compact.join("\n\n") end after_suite(test_results) end |
#after_suite(test_results) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/tldr/reporters/default.rb', line 81 def after_suite test_results duration = time_diff(@suite_start_time) test_results = test_results.sort_by { |result| [result.test.location.file, result.test.location.line] } @err.print summarize_failures(test_results).join("\n\n") @out.print summarize_skips(test_results).join("\n") @out.print "\n\n" @out.print "Finished in #{duration}ms." @out.print "\n\n" class_count = test_results.uniq { |result| result.test.test_class }.size test_count = test_results.size @out.print [ plural(class_count, "test class", "test classes"), plural(test_count, "test method"), plural(test_results.count(&:failure?), "failure"), plural(test_results.count(&:error?), "error"), plural(test_results.count(&:skip?), "skip") ].join(", ") @out.print "\n" end |
#after_test(result) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tldr/reporters/default.rb', line 21 def after_test result output = case result.type when :success then @icons.success when :skip then @icons.skip when :failure then @icons.failure when :error then @icons.error end if @config.verbose @out.puts "#{output} #{result.type.capitalize} - #{describe(result.test, result.relevant_location)}" else @out.print output end end |
#after_tldr(planned_tests, wip_tests, test_results) ⇒ Object
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 |
# File 'lib/tldr/reporters/default.rb', line 35 def after_tldr planned_tests, wip_tests, test_results stop_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond) @out.print @icons.tldr @err.print "\n\n" if @config.yes_i_know @err.print "🚨 TLDR after completing #{test_results.size} of #{planned_tests.size} tests! Print full summary by omitting --yes-i-know" else wrap_in_horizontal_rule do @err.print [ "too long; didn't run!", "#{@icons.run} Completed #{test_results.size} of #{planned_tests.size} tests (#{((test_results.size.to_f / planned_tests.size) * 100).round}%) before running out of time.", (<<~WIP.chomp if wip_tests.any?), (<<~SLOW.chomp if test_results.any?), #{@icons.slow} Your #{[10, test_results.size].min} slowest completed tests: #{test_results.sort_by(&:runtime).last(10).reverse.map { |result| " #{result.runtime}ms - #{describe(result.test)}" }.join("\n")} SLOW describe_tests_that_didnt_finish(planned_tests, test_results), "🙈 Suppress this summary with --yes-i-know" ].compact.join("\n\n") end end after_suite(test_results) end |
#before_suite(tests) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/tldr/reporters/default.rb', line 9 def before_suite tests clear_screen_if_being_watched! @suite_start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond) @out.print <<~MSG Command: #{tldr_command} #{@config.to_full_args} #{@icons.seed} #{CONFLAGS[:seed]} #{@config.seed} #{@icons.run} Running: MSG end |