Sha256: 7ca40a92d353e77c3d972894fdc68d073c25539f9e72afd14c0078c3fde779b0

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require "minitest/test"
require "minitest/rg"

module MiniTest

  def self.plugin_rg_options opts, options # :nodoc:
  end

  def self.plugin_rg_init options # :nodoc:
    io = RG.new options[:io]

    self.reporter.reporters.grep(Minitest::Reporter).each do |rep|
      rep.io = io
    end
  end

  class RG
    VERSION = "5.0.0"

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

    attr_reader :io, :colors

    def self.rg!
      @rg = true
    end

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

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

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

    def puts o=nil
      return io.puts if o.nil?
      if o =~ /(\d+) failures, (\d+) errors/
        if $1 != '0' || $2 != '0'
          io.puts "\e[31m#{o}\e[0m"
        else
          io.puts "\e[32m#{o}\e[0m"
        end
      else
        io.puts o
      end
    end

    def method_missing msg, *args
      return super unless io.respond_to? msg
      io.send(msg, *args)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
minitest-rg-5.0.0 lib/minitest/rg_plugin.rb