Class: MiniTest::Colorize

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

Constant Summary collapse

VERSION =
"0.0.5"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream = $stdout) ⇒ Colorize

Returns a new instance of Colorize.



8
9
10
11
12
# File 'lib/minitest/colorize.rb', line 8

def initialize(stream = $stdout)
  self.stream = stream.tap do |stream|
    stream.sync = true if stream.respond_to?(:sync=)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



52
53
54
# File 'lib/minitest/colorize.rb', line 52

def method_missing(method, *args, &block)
  stream.send(method, *args, &block)
end

Instance Attribute Details

#streamObject

Returns the value of attribute stream.



6
7
8
# File 'lib/minitest/colorize.rb', line 6

def stream
  @stream
end

Instance Method Details



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/minitest/colorize.rb', line 14

def print(string = nil)
  return stream.print if string.nil?

  case string
  when 'E', 'F'
    stream.print red(string)
  when 'S'
    stream.print yellow(string)
  when '.'
    stream.print green(string)
  else
    stream.print string
  end

  unless report.empty?
    stream.puts
    stream.puts
    stream.puts report.shift
    stream.puts
  end
end

#puts(string = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/minitest/colorize.rb', line 36

def puts(string = nil)
  return stream.puts if string.nil?

  if string =~ /(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors, (\d+) skips/
    if $3 != '0' || $4 != '0'
      stream.puts red(string)
    elsif $5 != '0'
      stream.puts yellow(string)
    else
      stream.puts green(string)
    end
  else
    stream.puts string
  end
end