Class: Gurke::Reporters::CompactReporter

Inherits:
NullReporter show all
Defined in:
lib/gurke/reporters/compact_reporter.rb

Constant Summary

Constants inherited from Gurke::Reporter

Gurke::Reporter::CALLBACKS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Gurke::Reporter

#after_feature, #before_feature, #before_features, #before_scenario, #before_step, #end_background, #end_feature, #end_features, #end_scenario, #end_step, #retry_scenario, #start_background, #start_feature, #start_features, #start_scenario, #start_step

Constructor Details

#initialize(io = $stdout) ⇒ CompactReporter

Returns a new instance of CompactReporter.



15
16
17
18
# File 'lib/gurke/reporters/compact_reporter.rb', line 15

def initialize(io = $stdout)
  super()
  @io = io
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



13
14
15
# File 'lib/gurke/reporters/compact_reporter.rb', line 13

def io
  @io
end

Instance Method Details

#after_features(features) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/gurke/reporters/compact_reporter.rb', line 91

def after_features(features)
  io.puts
  io.puts

  scenarios = features.map(&:scenarios).flatten

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

  message = "#{scenarios.size} scenarios: "
  message += "#{passed} passed, "
  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
end

#after_scenario(scenario) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/gurke/reporters/compact_reporter.rb', line 79

def after_scenario(scenario)
  if scenario.failed?
    # printed in after_step
  elsif scenario.pending?
    io.print yellow '?'
  elsif scenario.passed?
    io.print green '.'
  elsif scenario.aborted?
    io.puts
  end
end

#after_step(result, scenario) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/gurke/reporters/compact_reporter.rb', line 20

def after_step(result, scenario, *)
  return unless result.state == :failed

  io.print red 'E'

  feature = scenario.feature

  io.puts
  io.print yellow('Feature')
  io.print ': '
  io.print scenario.feature.name
  io.print '   '
  io.print format_location(scenario.feature)
  io.puts

  io.print '  '
  io.print yellow('Scenario')
  io.print ': '
  io.print scenario.name
  io.print '   '
  io.print format_location(scenario)
  io.puts

  background = feature.backgrounds.map(&:steps).flatten

  catch(:break) do
    if background.any?
      io.print '    '
      io.print light_black('Background')
      io.print ':'
      io.puts

      background.each do |step|
        io.print '      '
        io.print yellow(step.keyword)
        io.print ' '
        io.print step.name.gsub(/"(.*?)"/, cyan('\0'))
        io.puts

        throw :break if step == result.step
      end
    end

    scenario.steps.each do |step|
      io.print '    '
      io.print yellow(step.keyword)
      io.print ' '
      io.print step.name.gsub(/"(.*?)"/, cyan('\0'))
      io.puts

      throw :break if step == result.step
    end
  end

  exout = format_exception(result.exception, backtrace: true, indent: 6)
  io.puts red exout
  io.puts
end