Class: Guard::Motion

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

Defined Under Namespace

Classes: Inspector, 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



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

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)
  @inspector = Inspector.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



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

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



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

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



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

def run_on_changes(paths)
  paths += @failed_paths if @options[:keep_failed]
  paths = @inspector.clean(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



32
33
34
35
# File 'lib/guard/motion.rb', line 32

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