class Gurke::Reporters::DefaultReporter

The {DefaultReporter} prints features, scenarios and steps while they are executed.

That includes colorized step results reports etc.

Attributes

io[R]

Public Class Methods

new(io = $stdout) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 19
def initialize(io = $stdout)
  @io = io
end

Public Instance Methods

after_feature(*) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 88
def after_feature(*)
  io.puts
end
after_features(features) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 92
def after_features(features)
  scenarios = features.map(&:scenarios).flatten

  size    = scenarios.size
  passed  = scenarios.select(&:passed?).size
  failed  = scenarios.select(&:failed?).size
  pending = scenarios.select(&:pending?).size
  not_run = size - scenarios.select(&:run?).size

  message = "#{scenarios.size} scenarios: "
  message += "#{passed} passed, " unless passed == size || passed.zero?
  message += "#{failed} failing, #{pending} pending"
  message += ", #{not_run} not run" if not_run.positive?

  if failed.positive?
    io.puts red message
  elsif pending.positive? || not_run.positive?
    io.puts yellow message
  else
    io.puts green message
  end

  io.puts
end
after_scenario(*) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 84
def after_scenario(*)
  io.puts
end
after_step(step, *args) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 64
def after_step(step, *args)
  case step.state
    when :pending then step_pending(step, *args)
    when :failed  then step_failed(step, *args)
    when :passed then step_passed(step, *args)
    else step_skipped(step, *args)
  end

  io.puts
  io.flush
end
before_feature(feature) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 23
def before_feature(feature)
  io.print yellow('Feature')
  io.print ': '
  io.print feature.name
  io.print '   '
  io.print format_location(feature)
  io.puts

  io.print light_black(feature.description.gsub(/^/, '  '))
  io.puts
  io.puts
end
before_scenario(scenario) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 36
def before_scenario(scenario)
  io.print '  '
  io.print yellow('Scenario')
  io.print ': '
  io.print scenario.name
  io.print '   '
  io.print format_location(scenario)
  io.puts
end
before_step(step, *) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 56
def before_step(step, *)
  io.print '  ' if @background
  io.print '    '
  io.print yellow(step.keyword)
  io.print ' '
  io.print step.name.gsub(/"(.*?)"/, cyan('\0'))
end
end_background(*) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 52
def end_background(*)
  @background = false
end
retry_scenario(scenario) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 76
def retry_scenario(scenario)
  if scenario.flaky?
    io.print "\n  Retry flaky scenario due to previous failure:\n\n"
  else
    io.print "\n  Retry scenario due to previous failure:\n\n"
  end
end
start_background(*) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 46
def start_background(*)
  io.puts light_black('    Background:') unless @background

  @background = true
end

Protected Instance Methods

format_location(obj) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 148
def format_location(obj)
  file = obj.file.to_s
  line = obj.line.to_s
  cwd  = Pathname.new(Dir.getwd)
  path = Pathname.new(file).relative_path_from(cwd).to_s
  path = file if path.length > file.length

  light_black("# #{path}:#{line}")
end
print_exception(exception) click to toggle source
status(str) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 119
def status(str)
  " (#{str})"
end
step_failed(step, *_args, exception: true) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 127
def step_failed(step, *_args, exception: true)
  io.print status red 'failure'
  io.puts

  return unless exception

  print_exception(step.exception)
end
step_passed(*) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 136
def step_passed(*)
  io.print status green 'passed'
end
step_pending(*) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 123
def step_pending(*)
  io.print status yellow 'pending'
end
step_skipped(*) click to toggle source
# File lib/gurke/reporters/default_reporter.rb, line 140
def step_skipped(*)
  io.print status cyan 'skipped'
end