Class: Minitest::RedGreen::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/red_green/plugin.rb

Constant Summary collapse

ESC =
"\e["

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Plugin

Returns a new instance of Plugin.



8
9
10
# File 'lib/minitest/red_green/plugin.rb', line 8

def initialize io
  @io = io
end

Instance Attribute Details

#syncObject

Returns the value of attribute sync.



4
5
6
# File 'lib/minitest/red_green/plugin.rb', line 4

def sync
  @sync
end

Instance Method Details

#colorize(str, col_code) ⇒ Object



48
49
50
# File 'lib/minitest/red_green/plugin.rb', line 48

def colorize str, col_code
  "#{ESC}#{col_code}m#{str}#{ESC}0m"
end

#external_encodingObject



12
13
14
# File 'lib/minitest/red_green/plugin.rb', line 12

def external_encoding
  @io.external_encoding
end

#filter_test_output_chars(str) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/minitest/red_green/plugin.rb', line 27

def filter_test_output_chars str
  case str
  when '.' then green str
  when 'E', 'F' then red str
  when 'S' then yellow str
  else str
  end
end

#green(str) ⇒ Object



36
37
38
# File 'lib/minitest/red_green/plugin.rb', line 36

def green str
  colorize str, 32
end


23
24
25
# File 'lib/minitest/red_green/plugin.rb', line 23

def print str
  @io.print filter_test_output_chars str
end

#puts(*strings) ⇒ Object



16
17
18
19
20
21
# File 'lib/minitest/red_green/plugin.rb', line 16

def puts *strings
  if not strings.grep(%r{\d+\) (?:Failure|Error)}).empty?
    strings.map! &method(:red)
  end
  @io.puts *strings
end

#red(str) ⇒ Object



40
41
42
# File 'lib/minitest/red_green/plugin.rb', line 40

def red str
  colorize str, 31
end

#yellow(str) ⇒ Object



44
45
46
# File 'lib/minitest/red_green/plugin.rb', line 44

def yellow str
  colorize str, 33
end