Class: Spectre::SimpleReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/spectre.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ SimpleReporter

Returns a new instance of SimpleReporter.



440
441
442
443
# File 'lib/spectre.rb', line 440

def initialize config
  @out = config['stdout'] || $stdout
  @debug = config['debug']
end

Instance Method Details

#report(runs) ⇒ Object



445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
# File 'lib/spectre.rb', line 445

def report runs
  runs = runs.select { |x| x.parent.is_a? Specification }

  errors    = runs.count { |x| x.status == :error }
  failed    = runs.count { |x| x.status == :failed }
  skipped   = runs.count { |x| x.status == :skipped }
  succeeded = runs.count - errors - failed - skipped

  summary  = "#{succeeded} succeeded"
  summary += " #{failed} failures"
  summary += " #{errors} errors"
  summary += " #{skipped} skipped"

  @out.puts(summary.send((errors + failed).positive? ? :red : :green))

  output = "\n"

  runs
    .select { |x| [:error, :failed].include? x.status }
    .each_with_index do |run, index|
      index += 1

      output += "#{index})"
      output += " #{run.parent.full_desc}"
      output += " (#{run.finished - run.started})"
      output += " [#{run.parent.name}]"

      output += "\n"

      if run.error
        file, line = get_call_location(run.error.backtrace_locations)

        error_output  = "but an unexpected error occurred during run\n"
        error_output += "  file.....: #{file}:#{line}\n" if file
        error_output += "  type.....: #{run.error.class.name}\n"
        error_output += "  message..: #{run.error.message}\n"

        if @debug and run.error.backtrace
          error_output += "  backtrace:\n"

          run.error.backtrace.each do |trace|
            error_output += "    #{trace}\n"
          end
        end

        output += error_output.indent(5)
        output += "\n\n"
      end

      next unless run.status == :failed

      failed = run.evaluations
        .select { |x| x.failures.any? }

      failed.each_with_index do |eval, eval_idx|
        output += if failed.one?
                    "     #{eval.desc}, but"
                  else
                    "     #{index}.#{eval_idx + 1}) #{eval.desc}, but"
                  end

        if eval.failures.one?
          output += " #{eval.failures.first.message}\n"
        else
          output += " #{eval.failures.count} failures occured\n"

          eval.failures.each_with_index do |fail, fail_idx|
            output += if failed.one?
                        "       #{index}.#{fail_idx + 1}) #{fail.message}\n"
                      else
                        "       #{index}.#{eval_idx + 1}.#{fail_idx + 1}) #{fail.message}\n"
                      end
          end
        end
      end

      output += "\n"
    end

  @out.puts output.red
end