Class: PrideIO

Inherits:
Object show all
Defined in:
lib/minitest/pride.rb

Overview

Show your testing pride!

Direct Known Subclasses

PrideLOL

Constant Summary collapse

ESC =

Start an escape sequence

"\e["
NND =

End the escape sequence

"#{ESC}0m"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ PrideIO

:nodoc:



24
25
26
27
28
29
30
31
32
# File 'lib/minitest/pride.rb', line 24

def initialize io # :nodoc:
  @io = io
  # stolen from /System/Library/Perl/5.10.0/Term/ANSIColor.pm
  # also reference http://en.wikipedia.org/wiki/ANSI_escape_code
  @colors ||= (31..36).to_a
  @size   = @colors.size
  @index  = 0
  # io.sync = true
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(msg, *args) ⇒ Object

:nodoc:



71
72
73
# File 'lib/minitest/pride.rb', line 71

def method_missing msg, *args # :nodoc:
  io.send(msg, *args)
end

Instance Attribute Details

#ioObject (readonly)

The IO we’re going to pipe through.



22
23
24
# File 'lib/minitest/pride.rb', line 22

def io
  @io
end

Instance Method Details

#pride(string) ⇒ Object

Color a string.



64
65
66
67
68
69
# File 'lib/minitest/pride.rb', line 64

def pride string
  string = "*" if string == "."
  c = @colors[@index % @size]
  @index += 1
  "#{ESC}#{c}m#{string}#{NND}"
end

Wrap print to colorize the output.



37
38
39
40
41
42
43
44
45
46
# File 'lib/minitest/pride.rb', line 37

def print o
  case o
  when "." then
    io.print pride o
  when "E", "F" then
    io.print "#{ESC}41m#{ESC}37m#{o}#{NND}"
  else
    io.print o
  end
end

#puts(*o) ⇒ Object

:nodoc:



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/minitest/pride.rb', line 48

def puts(*o) # :nodoc:
  o.map! { |s|
    s.to_s.sub(/Finished tests/) {
      @index = 0
      'Fabulous tests'.split(//).map { |c|
        pride(c)
      }.join
    }
  }

  super
end