Class: Minitest::Colorin

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/colorin.rb,
lib/minitest/colorin/version.rb

Defined Under Namespace

Classes: TestID

Constant Summary collapse

LABELS =
{
  '.' => 'PASS ',
  'S' => 'SKIP ',
  'F' => 'FAIL ',
  'E' => 'ERROR'
}
GROUPS =
{
  '.' => :passed,
  'S' => :skips,
  'F' => :failures,
  'E' => :errors
}
COLORS =
{
  tests:      :blue_a700,
  passed:     :green_500,
  failures:   :red_500,
  errors:     :amber_300,
  skips:      :cyan_300,
  assertions: :purple_400
}
VERSION =
'0.1.3'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Colorin

Returns a new instance of Colorin.



47
48
49
50
51
# File 'lib/minitest/colorin.rb', line 47

def initialize(io)
  @io = io
  @previous_context = nil
  @results = []
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



45
46
47
# File 'lib/minitest/colorin.rb', line 45

def io
  @io
end

#previous_contextObject (readonly)

Returns the value of attribute previous_context.



45
46
47
# File 'lib/minitest/colorin.rb', line 45

def previous_context
  @previous_context
end

#resultsObject (readonly)

Returns the value of attribute results.



45
46
47
# File 'lib/minitest/colorin.rb', line 45

def results
  @results
end

#started_atObject (readonly)

Returns the value of attribute started_at.



45
46
47
# File 'lib/minitest/colorin.rb', line 45

def started_at
  @started_at
end

Instance Method Details

#passed?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/minitest/colorin.rb', line 82

def passed?
  results.all? { |r| r.failures.empty? }
end

#record(result) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/minitest/colorin.rb', line 58

def record(result)
  @results << result

  test_id = TestID.new result

  if test_id.context != @previous_context
    io.puts
    io.puts ::Colorin.white(test_id.context).bold
    @previous_context = test_id.context
  end

  label = colorin(LABELS[result.result_code], GROUPS[result.result_code])
  number = ::Colorin.grey_600(test_id.number)
  time = ::Colorin.grey_600("(#{result.time.round(3)}s)")
  message = case result.result_code
    when 'S' then colorin(result.failures[0].message, :skips) 
    when 'F' then colorin(relative_path(result.failures[0].location), :failures)
    when 'E' then colorin(error_message(result), :errors)
    else nil
  end

  io.puts "  #{label}  #{number} #{test_id.name} #{time} #{message}"
end

#reportObject



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/minitest/colorin.rb', line 86

def report
  io.puts

  print_detail_of :skips
  print_detail_of :failures
  print_detail_of :errors

  print_total_time

  print_summary
end

#startObject



53
54
55
56
# File 'lib/minitest/colorin.rb', line 53

def start
  @started_at = Time.now
  io.puts "Started at #{started_at}"
end