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:



17
18
19
20
21
22
23
24
25
# File 'lib/minitest/pride.rb', line 17

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:



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

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

Instance Attribute Details

#ioObject (readonly)

The IO we’re going to pipe through.



15
16
17
# File 'lib/minitest/pride.rb', line 15

def io
  @io
end

Instance Method Details

#pride(string) ⇒ Object

Color a string.



57
58
59
60
61
62
# File 'lib/minitest/pride.rb', line 57

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

Wrap print to colorize the output.



30
31
32
33
34
35
36
37
38
39
# File 'lib/minitest/pride.rb', line 30

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:



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/minitest/pride.rb', line 41

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