Class: Guard::Cucumber::NotificationFormatter

Inherits:
Object
  • Object
show all
Includes:
Cucumber::Formatter::Console
Defined in:
lib/guard/cucumber/notification_formatter.rb

Overview

The notification formatter is a Cucumber formatter that Guard::Cucumber passes to the Cucumber binary. It writes the ‘rerun.txt` file with the failed features an creates system notifications.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(step_mother, _path_or_io, options) ⇒ NotificationFormatter

Initialize the formatter.

Parameters:

  • step_mother (Cucumber::Runtime)

    the step mother

  • path_or_io (String, IO)

    the path or IO to the feature file

  • options (Hash)

    the options



40
41
42
43
44
45
# File 'lib/guard/cucumber/notification_formatter.rb', line 40

def initialize(step_mother, _path_or_io, options)
  @options = options
  @file_names = []
  @step_mother = step_mother
  @feature = nil
end

Instance Attribute Details

#step_motherObject (readonly)

Returns the value of attribute step_mother.



32
33
34
# File 'lib/guard/cucumber/notification_formatter.rb', line 32

def step_mother
  @step_mother
end

Instance Method Details

#after_feature_element(feature_element) ⇒ Object

After a feature gets run.

Parameters:

  • feature_element (Cucumber::Ast::FeatureElement)


78
79
80
81
82
83
# File 'lib/guard/cucumber/notification_formatter.rb', line 78

def after_feature_element(feature_element)
  if @rerun
    @file_names << feature_element.location.to_s
    @rerun = false
  end
end

#after_features(_features) ⇒ Object

Notification after all features have completed.

Parameters:

  • features (Array[Cucumber::Ast::Feature])

    the ran features



59
60
61
62
# File 'lib/guard/cucumber/notification_formatter.rb', line 59

def after_features(_features)
  notify_summary
  write_rerun_features if !@file_names.empty?
end

#before_background(_background) ⇒ Object



47
48
49
# File 'lib/guard/cucumber/notification_formatter.rb', line 47

def before_background(_background)
  # NOTE: background.feature is nil on newer gherkin versions
end

#before_feature(feature) ⇒ Object



51
52
53
# File 'lib/guard/cucumber/notification_formatter.rb', line 51

def before_feature(feature)
  @feature = feature
end

#before_feature_element(_feature_element) ⇒ Object

Before a feature gets run.

Parameters:

  • feature_element (Cucumber::Ast::FeatureElement)


68
69
70
71
72
# File 'lib/guard/cucumber/notification_formatter.rb', line 68

def before_feature_element(_feature_element)
  @rerun = false
  # TODO: show feature element name instead?
  # @feature = feature_element.name
end

#step_name(_keyword, step_match, status, _src_indent, _bckgnd, _loc) ⇒ Object

Gets called when a step is done.

used

Parameters:

  • keyword (String)

    the keyword

  • step_match (Cucumber::StepMatch)

    the step match

  • status (Symbol)

    the status of the step

  • source_indent (Integer)

    the source indentation

  • background (Cucumber::Ast::Background)

    the feature background

  • file (String)

    name and line number describing where the step is



95
96
97
98
99
100
101
102
103
# File 'lib/guard/cucumber/notification_formatter.rb', line 95

def step_name(_keyword, step_match, status, _src_indent, _bckgnd, _loc)
  return unless [:failed, :pending, :undefined].index(status)

  @rerun = true
  step_name = step_match.format_args(lambda { |param| "*#{param}*" })

  options = { title: @feature.name, image: icon_for(status) }
  Guard::Compat::UI.notify(step_name, options)
end