Class: WSColor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ WSColor

Returns a new instance of WSColor.



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

def initialize io
  @io = io
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(msg, *args) ⇒ Object



42
43
44
# File 'lib/minitest/wscolor.rb', line 42

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

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



4
5
6
# File 'lib/minitest/wscolor.rb', line 4

def io
  @io
end

Instance Method Details



10
11
12
13
14
15
16
17
18
19
# File 'lib/minitest/wscolor.rb', line 10

def print o
  case o
  when '.'
    io.print "\e[32m#{o}\e[0m"
  when 'E'
    io.print "\e[33m#{o}\e[0m"
  when 'F'
    io.print "\e[31m#{o}\e[0m"
  end
end

#puts(*a) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/minitest/wscolor.rb', line 21

def puts *a
  output = a.collect do |out|
    case out
    when /(0 failures, 0 errors, 0 skips)/
      out.sub($&, "\e[32m#{$&}\e[0m")
    when /(\d+ failures), (\d+ errors), (\d+ skips)/
      md = $~
      out.sub(md[1], "\e[31m#{md[1]}\e[0m").sub(md[2], "\e[33m#{md[2]}\e[0m").sub(md[3], "\e[36m#{md[3]}\e[0m")
    when /Failure/
      out.sub(out, "\e[31m#{out}\e[0m")
    when /Error/
      out.sub(out, "\e[33m#{out}\e[0m")
    when /Skipped/
      out.sub(out, "\e[36m#{out}\e[0m")
    else
      out
    end
  end
  io.puts *output
end