Class: Minitest::PrideIO

Inherits:
Object show all
Defined in:
lib/minitest/pride_plugin.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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ PrideIO

:nodoc:


48
49
50
51
52
53
54
55
# File 'lib/minitest/pride_plugin.rb', line 48

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
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(msg, *args) ⇒ Object

:nodoc:


96
97
98
# File 'lib/minitest/pride_plugin.rb', line 96

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

Instance Attribute Details

#ioObject (readonly)

The IO we're going to pipe through.


46
47
48
# File 'lib/minitest/pride_plugin.rb', line 46

def io
  @io
end

Class Method Details

.pride!Object

Activate the pride plugin. Called from both -p option and minitest/pride


28
29
30
# File 'lib/minitest/pride_plugin.rb', line 28

def self.pride!
  @pride = true
end

.pride?Boolean

Are we showing our testing pride?


35
36
37
# File 'lib/minitest/pride_plugin.rb', line 35

def self.pride?
  @pride ||= false
end

Instance Method Details

#pride(string) ⇒ Object

Color a string.


89
90
91
92
93
94
# File 'lib/minitest/pride_plugin.rb', line 89

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

Wrap print to colorize the output.


60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/minitest/pride_plugin.rb', line 60

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

#puts(*o) ⇒ Object

:nodoc:


73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/minitest/pride_plugin.rb', line 73

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

  io.puts(*o)
end