Class: Guard::Ecukes

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/ecukes.rb,
lib/guard/ecukes/runner.rb,
lib/guard/ecukes/inspector.rb

Overview

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

Defined Under Namespace

Modules: Inspector, Runner

Instance Method Summary collapse

Constructor Details

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

Initialize Guard::Ecukes.

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 Ecukes CLI arguments

  • :all_after_pass (Boolean)

    run all features after changed features pass

  • :all_on_start (Boolean)

    run all the features at startup

  • :run_all (Boolean)

    run override any option when running all specs



25
26
27
28
29
30
31
32
33
34
# File 'lib/guard/ecukes.rb', line 25

def initialize(watchers = [], options = {})
  super

  @options = {
      :all_after_pass => true,
      :all_on_start   => true,
  }.update(options)

  @last_failed  = false
end

Instance Method Details

#reloadObject

Gets called when the Guard should reload itself.

Raises:

  • (:task_has_failed)

    when stop has failed



60
61
# File 'lib/guard/ecukes.rb', line 60

def reload
end

#run_allObject

Gets called when all specs should be run.

Raises:

  • (:task_has_failed)

    when stop has failed



48
49
50
51
52
53
54
# File 'lib/guard/ecukes.rb', line 48

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

  @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



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/guard/ecukes.rb', line 68

def run_on_changes(paths)
  paths   = Inspector.clean(paths)
  passed  = Runner.run(paths, paths.include?('features') ? @options.merge({ :message => 'Running all features' }) : @options)

  if passed
    # run all the specs if the changed specs failed, like autotest
    run_all if @last_failed && @options[:all_after_pass]
  else
    # 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



40
41
42
# File 'lib/guard/ecukes.rb', line 40

def start
  run_all if @options[:all_on_start]
end