class Lopata::Observers::ConsoleOutputObserver

@private

Attributes

output[R]

@private

Public Class Methods

new() click to toggle source
# File lib/lopata/observers/console_output_observer.rb, line 14
def initialize
  @output = $stdout
end

Public Instance Methods

finished(world) click to toggle source

@see Lopata::Observers::BaseObserver#finished

# File lib/lopata/observers/console_output_observer.rb, line 19
def finished(world)
  total = statuses.values.inject(0, &:+)
  counts = statuses.map do |status, count|
    colored("%d %s", status) % [count, status]
  end
  details = counts.empty? ? "" : "(%s)" % counts.join(', ')
  puts "#{total} scenario%s %s" % [total == 1 ? '' : 's', details]
end
scenario_finished(scenario) click to toggle source

@see Lopata::Observers::BaseObserver#scenario_finished

# File lib/lopata/observers/console_output_observer.rb, line 29
def scenario_finished(scenario)
  message = "#{scenario.title} #{bold(scenario.status.to_s.upcase)}"
  puts colored(message, scenario.status)

  statuses[scenario.status] ||= 0
  statuses[scenario.status] += 1

  if scenario.failed?
    scenario.steps.each do |step|
      puts colored("  #{status_marker(step.status)} #{step.title}", step.status)
      puts indent(4, backtrace_formatter.error_message(step.exception, include_backtrace: true)) if step.failed?
    end
  end

  flush
end

Private Instance Methods

backtrace_formatter() click to toggle source
# File lib/lopata/observers/console_output_observer.rb, line 74
def backtrace_formatter
  @backtrace_formatter ||= Lopata::Observers::BacktraceFormatter.new
end
colored(text, status) click to toggle source
# File lib/lopata/observers/console_output_observer.rb, line 48
def colored(text, status)
  case status
  when :failed then red(text)
  when :passed then green(text)
  when :skipped then cyan(text)
  when :pending then yellow(text)
  else text
  end
end
indent(cols, text) click to toggle source

Adds indent to text @param cols [Number] number of spaces to be added @param text [String] text to add indent @return [String] text with indent

# File lib/lopata/observers/console_output_observer.rb, line 91
def indent(cols, text)
  text.split("\n").map { |line| " " * cols + line }.join("\n")
end
status_marker(status) click to toggle source
# File lib/lopata/observers/console_output_observer.rb, line 78
def status_marker(status)
  case status
  when :failed then "[!]"
  when :skipped then "[-]"
  when :pending then "[?]"
  else "[+]"
  end
end
statuses() click to toggle source
# File lib/lopata/observers/console_output_observer.rb, line 95
def statuses
  @statuses ||= {}
end
wrap(text, code) click to toggle source
# File lib/lopata/observers/console_output_observer.rb, line 70
def wrap(text, code)
  "\e[#{code}m#{text}\e[0m"
end