Class: Gurke::Reporters::DefaultReporter

Inherits:
NullReporter show all
Includes:
Colored
Defined in:
lib/gurke/reporters/default_reporter.rb

Overview

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

That includes colorized step results reports etc.

Direct Known Subclasses

TeamCityReporter

Constant Summary

Constants inherited from Gurke::Reporter

Gurke::Reporter::CALLBACKS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Colored

#color?

Methods inherited from Gurke::Reporter

#before_features, #end_feature, #end_features, #end_scenario, #end_step, #start_feature, #start_features, #start_scenario, #start_step

Constructor Details

#initialize(io: $stdout, **kwargs) ⇒ DefaultReporter

Returns a new instance of DefaultReporter.



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

def initialize(io: $stdout, **kwargs)
  @io = io
  super(**kwargs)
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



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

def io
  @io
end

Instance Method Details

#after_featureObject



85
86
87
# File 'lib/gurke/reporters/default_reporter.rb', line 85

def after_feature(*)
  io.puts ' '
end

#after_features(features) ⇒ Object



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

def after_features(features)
  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, " 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_scenarioObject



81
82
83
# File 'lib/gurke/reporters/default_reporter.rb', line 81

def after_scenario(*)
  io.puts ' '
end

#after_step(step, *args) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/gurke/reporters/default_reporter.rb', line 61

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) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gurke/reporters/default_reporter.rb', line 20

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) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/gurke/reporters/default_reporter.rb', line 33

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) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/gurke/reporters/default_reporter.rb', line 53

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_backgroundObject



49
50
51
# File 'lib/gurke/reporters/default_reporter.rb', line 49

def end_background(*)
  @background = false
end

#retry_scenario(scenario) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/gurke/reporters/default_reporter.rb', line 73

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_backgroundObject



43
44
45
46
47
# File 'lib/gurke/reporters/default_reporter.rb', line 43

def start_background(*)
  io.puts light_black('    Background:') unless @background

  @background = true
end