class Spectre::Logger::Console

Public Class Methods

new(config) click to toggle source
# File lib/spectre/logger/console.rb, line 6
def initialize config
  raise 'No log format section in config for console logger' unless config.key? 'log_format' and config['log_format'].key? 'console'

  @config = config['log_format']['console']
  @indent = @config['indent'] || 2
  @width = @config['width'] || 80
  @fmt_end_context = @config['end_context']
  @fmt_sep = @config['separator']
  @fmt_start_group = @config['start_group']
  @fmt_end_group = @config['end_group']

  @process = nil
  @level = 0
end

Public Instance Methods

end_context(context) click to toggle source
# File lib/spectre/logger/console.rb, line 31
def end_context context
  return unless context.__desc
  @level -= 1
  puts (' ' * indent) + @fmt_end_context.gsub('<desc>', context.__desc).magenta if @fmt_end_context
end
end_group(desc) click to toggle source
# File lib/spectre/logger/console.rb, line 64
def end_group desc
  if desc and @fmt_start_group
    desc = @fmt_start_group.gsub('<desc>', desc) if @fmt_start_group
    puts (' ' * indent) + desc.blue
  end

  @level -= 1
end
end_spec(spec, data) click to toggle source
# File lib/spectre/logger/console.rb, line 45
def end_spec spec, data
  @level -= 1
end
log_debug(message) click to toggle source
# File lib/spectre/logger/console.rb, line 105
def log_debug message
  print_line(message, Status::DEBUG.grey)
end
log_error(spec, exception) click to toggle source
# File lib/spectre/logger/console.rb, line 109
def log_error spec, exception
  txt = (Status::ERROR + ' - ' + exception.class.name).red
  print_line('', txt)
end
log_info(message) click to toggle source
# File lib/spectre/logger/console.rb, line 101
def log_info message
  print_line(message, Status::INFO.blue)
end
log_process(desc) click to toggle source
# File lib/spectre/logger/console.rb, line 73
def log_process desc
  print_line(desc)
  @process = desc
  @level += 1
end
log_separator(desc) click to toggle source
# File lib/spectre/logger/console.rb, line 49
def log_separator desc
  if desc
    desc = @fmt_sep.gsub('<indent>', ' ' * indent).gsub('<desc>', desc) if @fmt_sep
    puts desc.blue
  else
    puts
  end
end
log_skipped(spec) click to toggle source
# File lib/spectre/logger/console.rb, line 114
def log_skipped spec
  print_line('', Status::SKIPPED.grey)
end
log_status(desc, status, annotation=nil) click to toggle source
# File lib/spectre/logger/console.rb, line 79
def log_status desc, status, annotation=nil
  status = status.green if status == Status::OK
  status = status.blue if status == Status::INFO
  status = status.grey if status == Status::DEBUG
  status = status.red if status == Status::FAILED
  status = status.red if status == Status::ERROR
  status = status.grey if status == Status::SKIPPED

  txt = status
  txt += ' ' + annotation if annotation

  @level -= 1

  if @process
    puts txt
  else
    print_line('', status)
  end

  @process = nil
end
start_context(context) click to toggle source
# File lib/spectre/logger/console.rb, line 25
def start_context context
  return unless context.__desc
  puts (' ' * indent) + context.__desc.magenta
  @level += 1
end
start_group(desc) click to toggle source
# File lib/spectre/logger/console.rb, line 58
def start_group desc
  desc = @fmt_start_group.gsub('<desc>', desc) if @fmt_start_group
  puts (' ' * indent) + desc.blue
  @level += 1
end
start_spec(spec, data=nil) click to toggle source
# File lib/spectre/logger/console.rb, line 37
def start_spec spec, data=nil
  text = spec.desc
  text += " with #{data}" if data
  puts (' ' * indent) + text.cyan

  @level += 1
end
start_subject(subject) click to toggle source
# File lib/spectre/logger/console.rb, line 21
def start_subject subject
  puts subject.desc.blue
end

Private Instance Methods

indent() click to toggle source
# File lib/spectre/logger/console.rb, line 120
def indent
  (@level+1) * @indent
end
print_line(text='', status=nil) click to toggle source