Class: Minitest::RG

Inherits:
Object
  • Object
show all
Defined in:
lib/maxitest/vendor/rg.rb

Constant Summary collapse

VERSION =
"5.4.0"
COLORS =
{
  "." => "\e[32m.\e[0m",
  "E" => "\e[33mE\e[0m",
  "F" => "\e[31mF\e[0m",
  "S" => "\e[36mS\e[0m"
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, colors = COLORS) ⇒ RG

Returns a new instance of RG.



67
68
69
70
# File 'lib/maxitest/vendor/rg.rb', line 67

def initialize io, colors = COLORS
  @io     = io
  @colors = colors
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(msg, *args) ⇒ Object



90
91
92
93
94
# File 'lib/maxitest/vendor/rg.rb', line 90

def method_missing msg, *args
  return io.send(msg, *args) if io.respond_to? msg

  super
end

Instance Attribute Details

#colorsObject (readonly)

Returns the value of attribute colors.



57
58
59
# File 'lib/maxitest/vendor/rg.rb', line 57

def colors
  @colors
end

#ioObject (readonly)

Returns the value of attribute io.



57
58
59
# File 'lib/maxitest/vendor/rg.rb', line 57

def io
  @io
end

Class Method Details

.rg!(color: true) ⇒ Object



59
60
61
# File 'lib/maxitest/vendor/rg.rb', line 59

def self.rg! color: true
  @rg = color
end

.rg?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/maxitest/vendor/rg.rb', line 63

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

Instance Method Details



72
73
74
# File 'lib/maxitest/vendor/rg.rb', line 72

def print output
  io.print(colors[output] || output)
end

#puts(output = nil) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/maxitest/vendor/rg.rb', line 76

def puts output = nil
  return io.puts if output.nil?

  if output =~ /(\d+) failures, (\d+) errors/
    if Regexp.last_match[1] != "0" || Regexp.last_match[2] != "0"
      io.puts "\e[31m#{output}\e[0m"
    else
      io.puts "\e[32m#{output}\e[0m"
    end
  else
    io.puts output
  end
end

#respond_to_missing?(method_name, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
99
100
# File 'lib/maxitest/vendor/rg.rb', line 96

def respond_to_missing? method_name, include_all = false
  return true if io.respond_to? method_name, include_all

  super
end