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



26
27
28
29
30
# File 'lib/guard/cucumber/notification_formatter.rb', line 26

def initialize(step_mother, path_or_io, options)
  @options = options
  @file_names = []
  @step_mother = step_mother
end

Instance Attribute Details

#step_motherObject (readonly)

Returns the value of attribute step_mother.



18
19
20
# File 'lib/guard/cucumber/notification_formatter.rb', line 18

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)


54
55
56
57
58
59
# File 'lib/guard/cucumber/notification_formatter.rb', line 54

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

#after_features(features) ⇒ Object

Notification after all features have completed.

Parameters:

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

    the ran features



36
37
38
39
# File 'lib/guard/cucumber/notification_formatter.rb', line 36

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

#before_feature_element(feature_element) ⇒ Object

Before a feature gets run.

Parameters:

  • feature_element (Cucumber::Ast::FeatureElement)


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

def before_feature_element(feature_element)
  @rerun = false
  @feature_name = feature_element.name
end

#step_name(keyword, step_match, status, source_indent, background, file_colon_line) ⇒ Object

Gets called when a step is done.

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 used



70
71
72
73
74
75
76
77
# File 'lib/guard/cucumber/notification_formatter.rb', line 70

def step_name(keyword, step_match, status, source_indent, background, file_colon_line)
  if [:failed, :pending, :undefined].index(status)
    @rerun = true
    step_name = step_match.format_args(lambda { |param| "*#{ param }*" })

    ::Guard::Notifier.notify step_name, :title => @feature_name, :image => icon_for(status)
  end
end