Class: Spectre::Reporter::Console
- Defined in:
- lib/spectre/reporter/console.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ Console
constructor
A new instance of Console.
- #report(run_infos) ⇒ Object
Constructor Details
#initialize(config) ⇒ Console
Returns a new instance of Console.
5 6 7 |
# File 'lib/spectre/reporter/console.rb', line 5 def initialize config @debug = config['debug'] end |
Instance Method Details
#report(run_infos) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 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 |
# File 'lib/spectre/reporter/console.rb', line 9 def report run_infos report_str = '' errors = 0 failures = 0 skipped = run_infos.select { |x| x.skipped? }.count run_infos .select { |x| x.error != nil or x.failure != nil } .each_with_index do |run_info, index| report_str += "\n#{index+1}) #{format_title(run_info)}\n" if run_info.failure report_str += " Expected #{run_info.failure.expectation}" report_str += " with #{run_info.data}" if run_info.data report_str += " but it failed" if run_info.failure.cause report_str += "\n with an unexpected error:\n" report_str += format_exception(run_info.failure.cause) elsif run_info.failure. and not run_info.failure..empty? report_str += " with:\n #{run_info.failure.}" else report_str += '.' end report_str += "\n" failures += 1 else report_str += " but an unexpected error occurred during run\n" report_str += format_exception(run_info.error) errors += 1 end end if failures + errors > 0 summary = '' summary += "#{run_infos.length - failures - errors - skipped} succeeded " summary += "#{failures} failures " if failures > 0 summary += "#{errors} errors " if errors > 0 summary += "#{skipped} skipped " if skipped > 0 summary += "#{run_infos.length} total" print "\n#{summary}\n".red else summary = "\nRun finished successfully" summary += " (#{skipped} skipped)" if skipped > 0 print "#{summary}\n".green end puts report_str.red end |