Class: Guard::Cucumber

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/cucumber.rb,
lib/guard/cucumber/runner.rb,
lib/guard/cucumber/focuser.rb,
lib/guard/cucumber/inspector.rb,
lib/guard/cucumber/notification_formatter.rb

Overview

The Cucumber guard that gets notifications about the following Guard events: ‘start`, `stop`, `reload`, `run_all` and `run_on_change`.

Defined Under Namespace

Modules: Focuser, Inspector, Runner Classes: NotificationFormatter

Constant Summary collapse

KNOWN_OPTIONS =
%w(
  cmd
  cmd_additional_args

  all_after_pass
  all_on_start
  keep_failed
  feature_sets

  run_all
  focus_on
  notification
).map(&:to_sym)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Cucumber

Initialize Guard::Cucumber.

feature directory/ies features pass pass all specs

Parameters:

  • watchers (Array<Guard::Watcher>)

    the watchers in the Guard block

  • options (Hash) (defaults to: {})

    the options for the Guard

Options Hash (options):

  • :feature_sets (Array<String>)

    a list of non-standard

  • :notification (Boolean)

    show notifications

  • :all_after_pass (Boolean)

    run all features after changed

  • :all_on_start (Boolean)

    run all the features at startup

  • :keep_failed (Boolean)

    Keep failed features until they

  • :run_all (Boolean)

    run override any option when running

  • :cmd (Boolean)

    the command to run

  • :cmd_additional_args (Boolean)

    additional args to append



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/guard/cucumber.rb', line 45

def initialize(options = {})
  super(options)

  @options = {
    all_after_pass: true,
    all_on_start: true,
    keep_failed: true,
    cmd: "cucumber",
    cmd_additional_args: "--no-profile --color --format progress --strict",
    feature_sets: ["features"]
  }.update(options)

  unknown_options = @options.keys - KNOWN_OPTIONS
  unknown_options.each do |unknown|
    msg = "Unknown guard-cucumber option: #{unknown.inspect}"
    Guard::Compat::UI.warning(msg)
  end

  @last_failed  = false
  @failed_paths = []
end

Instance Attribute Details

#failed_pathObject

Returns the value of attribute failed_path.



12
13
14
# File 'lib/guard/cucumber.rb', line 12

def failed_path
  @failed_path
end

#last_failedObject

Returns the value of attribute last_failed.



12
13
14
# File 'lib/guard/cucumber.rb', line 12

def last_failed
  @last_failed
end

Instance Method Details

#reloadObject

Gets called when the Guard should reload itself.

Raises:

  • (:task_has_failed)

    when stop has failed



99
100
101
# File 'lib/guard/cucumber.rb', line 99

def reload
  @failed_paths = []
end

#run_allObject

Gets called when all specs should be run.

Raises:

  • (:task_has_failed)

    when stop has failed



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/guard/cucumber.rb', line 79

def run_all
  opts = options.merge(options[:run_all] || {})
  opts[:message] = "Running all features"
  passed = Runner.run(options[:feature_sets], opts)

  if passed
    @failed_paths = []
  elsif @options[:keep_failed]
    @failed_paths = read_failed_features
  end

  @last_failed = !passed

  throw :task_has_failed unless passed
end

#run_on_modifications(paths) ⇒ Object

Gets called when watched paths and files have changes.

Parameters:

  • paths (Array<String>)

    the changed paths and files

Raises:

  • (:task_has_failed)

    when stop has failed



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/guard/cucumber.rb', line 108

def run_on_modifications(paths)
  paths += @failed_paths if @options[:keep_failed]
  paths = Inspector.clean(paths, options[:feature_sets])

  options = @options

  msg = "Running all features"
  options[:message] = msg if paths.include?("features")

  _run(paths, options)
end

#startObject

Gets called once when Guard starts.

Raises:

  • (:task_has_failed)

    when stop has failed



71
72
73
# File 'lib/guard/cucumber.rb', line 71

def start
  run_all if @options[:all_on_start]
end