Class: MiniTest::ANSI

Inherits:
SimpleDelegator
  • Object
show all
Includes:
ANSIVersion
Defined in:
lib/minitest/ansi.rb

Constant Summary collapse

TEST_REGEX =
/\d+(\)| tests)/
MAPPING =
[
  [/[1-9]\d*\)? (F|f)ailures?/, :yellow],
  [/[1-9]\d*\)? (E|e)rrors?/, :red],
  [/[1-9]\d*\)? (S|s)kip(ped|s)/, :cyan],
]

Constants included from ANSIVersion

MiniTest::ANSIVersion::VERSION

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream = MiniTest::Unit.output) ⇒ ANSI

Returns a new instance of ANSI.



18
19
20
# File 'lib/minitest/ansi.rb', line 18

def initialize(stream=MiniTest::Unit.output)
  super
end

Class Method Details

.use!Object



46
47
48
# File 'lib/minitest/ansi.rb', line 46

def self.use!
  MiniTest::Unit.output = new
end

Instance Method Details



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/minitest/ansi.rb', line 22

def print(*args)
  char = args.first
  color = case char
  when '.'; then :green
  when 'F'; then :yellow
  when 'E'; then :red
  when 'S'; then :cyan
  else
    __getobj__.print(*args)
    return
  end
  __getobj__.print(::ANSI[color] + char + ::ANSI[:clear])
end

#puts(*args) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/minitest/ansi.rb', line 36

def puts(*args)
  str = args.first
  if str && (str =~ TEST_REGEX) != nil
    MAPPING.each do |regex, color|
      str.gsub!(regex, ::ANSI[color] + "\\0" + ::ANSI[:clear])
    end
  end
  __getobj__.puts(*args)
end