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 =
"\e["
NND =
"#{ESC}0m"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ PrideIO

Returns a new instance of PrideIO.



12
13
14
15
16
17
18
19
20
# File 'lib/minitest/pride.rb', line 12

def initialize io
  @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



53
54
55
# File 'lib/minitest/pride.rb', line 53

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

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



10
11
12
# File 'lib/minitest/pride.rb', line 10

def io
  @io
end

Instance Method Details

#pride(string) ⇒ Object



46
47
48
49
50
51
# File 'lib/minitest/pride.rb', line 46

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


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

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



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/minitest/pride.rb', line 33

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

  super
end