Class: Guard::Cucumber

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/cucumber.rb,
lib/guard/cucumber/runner.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: Inspector, Runner Classes: NotificationFormatter

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = { }) ⇒ Cucumber

Initialize Guard::Cucumber.

Parameters:

  • watchers (Array<Guard::Watcher>) (defaults to: [])

    the watchers in the Guard block

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

    the options for the Guard

Options Hash (options):

  • :cli (String)

    any arbitrary Cucumber CLI arguments

  • :feature_sets (Array<String>)

    a list of non-standard feature directory/ies

  • :bundler (Boolean)

    use bundler or not

  • :rvm (Array<String>)

    a list of rvm version to use for the test

  • :notification (Boolean)

    show notifications

  • :all_after_pass (Boolean)

    run all features after changed features pass

  • :all_on_start (Boolean)

    run all the features at startup

  • :keep_failed (Boolean)

    Keep failed features until they pass

  • :run_all (Boolean)

    run override any option when running all specs

  • :change_format (Boolean)

    use a different cucumber format when running individual features



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/guard/cucumber.rb', line 31

def initialize(watchers = [], options = { })
  super
  @options = {
      :all_after_pass => true,
      :all_on_start   => true,
      :keep_failed    => true,
      :cli            => '--no-profile --color --format progress --strict',
      :feature_sets   => ['features']
  }.update(options)

  @last_failed  = false
  @failed_paths = []
end

Instance Method Details

#reloadObject

Gets called when the Guard should reload itself.

Raises:

  • (:task_has_failed)

    when stop has failed



75
76
77
# File 'lib/guard/cucumber.rb', line 75

def reload
  @failed_paths = []
end

#run_allObject

Gets called when all specs should be run.

Raises:

  • (:task_has_failed)

    when stop has failed



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/guard/cucumber.rb', line 57

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

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

  @last_failed = !passed

  throw :task_has_failed unless passed
end

#run_on_changes(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



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/guard/cucumber.rb', line 84

def run_on_changes(paths)
  paths += @failed_paths if @options[:keep_failed]
  paths   = Inspector.clean(paths)
  options = @options[:change_format] ? change_format(@options[:change_format]) : @options
  passed  = Runner.run(paths, paths.include?('features') ? options.merge({ :message => 'Running all features' }) : options)

  if passed
    # clean failed paths memory
    @failed_paths -= paths if @options[:keep_failed]
    # run all the specs if the changed specs failed, like autotest
    run_all if @last_failed && @options[:all_after_pass]
  else
    # remember failed paths for the next change
    @failed_paths += read_failed_features if @options[:keep_failed]
    # track whether the changed feature failed for the next change
    @last_failed = true
  end

  throw :task_has_failed unless passed
end

#startObject

Gets called once when Guard starts.

Raises:

  • (:task_has_failed)

    when stop has failed



49
50
51
# File 'lib/guard/cucumber.rb', line 49

def start
  run_all if @options[:all_on_start]
end