Class: Guard::Motion

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

Defined Under Namespace

Classes: ResultsParser, Runner

Instance Method Summary collapse

Constructor Details

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

Initialize a Guard.

Parameters:

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

    the Guard file watchers

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

    the custom Guard options



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/guard/motion.rb', line 14

def initialize(watchers = [], options = {})
  super
  @options = {
    :all_after_pass => true,
    :all_on_start   => true,
    :keep_failed    => true,
    :spec_paths     => ["spec"]
  }.merge(options)
  @last_failed  = false
  @failed_paths = []

  @runner = Runner.new(@options)
end

Instance Method Details

#reloadObject

Called when ‘reload|r|z + enter` is pressed. This method should be mainly used for “reload” (really!) actions like reloading passenger/spork/bundler/…

Raises:

  • (:task_has_failed)

    when reload has failed



38
39
40
# File 'lib/guard/motion.rb', line 38

def reload
  @failed_paths = []
end

#run_allObject

Called when just ‘enter` is pressed This method should be principally used for long action like running all specs/tests/…

Raises:

  • (:task_has_failed)

    when run_all has failed



45
46
47
48
49
50
51
52
53
# File 'lib/guard/motion.rb', line 45

def run_all
  passed = @runner.run

  unless @last_failed = !passed
    @failed_paths = []
  else
    throw :task_has_failed
  end
end

#run_on_changes(paths) ⇒ Object

Called on file(s) modifications that the Guard watches.

Parameters:

  • paths (Array<String>)

    the changes files or paths

Raises:

  • (:task_has_failed)

    when run_on_change has failed



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/guard/motion.rb', line 58

def run_on_changes(paths)
  paths += @failed_paths if @options[:keep_failed]
  paths.uniq!

  if passed = @runner.run(paths)
    remove_failed(paths)

    # run all the specs if the run before this one failed
    if @last_failed && @options[:all_after_pass]
      @last_failed = false
      run_all
    end
  else
    @last_failed = true
    add_failed(paths)

    throw :task_has_failed
  end
end

#startObject

Call once when Guard starts. Please override initialize method to init stuff.

Raises:

  • (:task_has_failed)

    when start has failed



30
31
32
33
# File 'lib/guard/motion.rb', line 30

def start
  UI.info "Guard::Motion is running"
  run_all if @options[:all_on_start]
end