module RSpec::Core::Formatters::ConsoleCodes

def config_colors_to_methods

Other tags:
    Private: -
def config_colors_to_methods
  @config_colors_to_methods ||=
    Configuration.instance_methods.grep(/_color\z/).inject({}) do |hash, method|
      hash[method.to_s.sub(/_color\z/, '').to_sym] = method
      hash
    end
end

def console_code_for(code_or_symbol)

Returns:
  • (Fixnum) - a console code

Parameters:
  • code_or_symbol (Symbol, Fixnum) -- Symbol or code to check
def console_code_for(code_or_symbol)
  if (config_method = config_colors_to_methods[code_or_symbol])
    console_code_for RSpec.configuration.__send__(config_method)
  elsif VT100_CODE_VALUES.key?(code_or_symbol)
    code_or_symbol
  else
    VT100_CODES.fetch(code_or_symbol) do
      console_code_for(:white)
    end
  end
end

def wrap(text, code_or_symbol)

Returns:
  • (String) - the wrapped text

Parameters:
  • code_or_symbol (Symbol, Fixnum) -- the desired control code
  • text (String) -- the text to wrap
def wrap(text, code_or_symbol)
  if RSpec.configuration.color_enabled?
    "\e[#{console_code_for(code_or_symbol)}m#{text}\e[0m"
  else
    text
  end
end