Sha256: c3f518c74220ac4c82065265dda6c934d07445bf0d73913428544e3d275d55ba

Contents?: true

Size: 1.79 KB

Versions: 3

Compression:

Stored size: 1.79 KB

Contents

require 'color_pound_spec_reporter/version'
require 'minitest/reporters'

class ColorPoundSpecReporter < Minitest::Reporters::SpecReporter
  # minitest-reporters methods for version 0.14.24
  def pass(suite, test, test_runner)
    common_print(suite, test, :green, 'PASS')
  end

  def skip(suite, test, test_runner)
    common_print(suite, test, :yellow, 'SKIP')
  end

  def failure(suite, test, test_runner)
    common_print(suite, test, :red, 'FAIL')
    print_exception(test_runner.exception, 'FAIL')
  end

  def error(suite, test, test_runner)
    common_print(suite, test, :red, 'ERROR')
    print_exception(test_runner.exception, 'ERROR')
  end

  # Just in case we load a more recent minitest-reporters v1
  def record(test)
    Minitest::Reporters::BaseReporter.instance_method(:record).bind(self).call(test)
    print_colored_status(test)
    print(" (%.2fs)" % test.time)
    print " :: #{color_pound test.name}"
    if !test.skipped? && test.failure
      print_exception(test.failure, test.error? ? 'ERROR' : '' )
    else
      puts
    end
  end

  private
  def common_print(suite, test, color, message)
    print_suite(suite) unless @suites.include?(suite)
    print( send(color) { pad_mark(message) } )
    print_time(test)
    print " :: #{color_pound test}"
    puts
  end

  def print_exception(ex, kind)
    print color_pound "\n\n#{"    " if kind.=~(/error/i)}#{ex}\n\n"
    puts
  end

  def color_pound(str)
    str.to_s.gsub(/(?<foo>(?<!:)(?:#|:)\w{1,}\??)/, ANSI::Code.yellow('\k<foo>')).
      gsub(/(?<foo>[A-Z]\S*)/, ANSI::Code.cyan('\k<foo>')).
      gsub(/(?<foo>(?:NIL|NULL|ERROR|FAIL|EXCEPTION|FALSE))/i, ANSI::Code.red('\k<foo>')).
      gsub(/(?<foo>(?:self|true))/, ANSI::Code.green('\k<foo>')).
      gsub(/(?<foo>(?:Expected|Actual):)/, ANSI::Code.bold(ANSI::Code.white('\k<foo>')))
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
color_pound_spec_reporter-0.0.4 lib/color_pound_spec_reporter.rb
color_pound_spec_reporter-0.0.3 lib/color_pound_spec_reporter.rb
color_pound_spec_reporter-0.0.2 lib/color_pound_spec_reporter.rb