Class: Guard::Test

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/test.rb,
lib/guard/test/runner.rb,
lib/guard/test/command.rb,
lib/guard/test/options.rb,
lib/guard/test/notifier.rb,
lib/guard/test/inspector.rb,
lib/guard/test/deprecator.rb,
lib/guard/test/inspectors/factory.rb,
lib/guard/test/inspectors/base_inspector.rb,
lib/guard/test/inspectors/simple_inspector.rb,
lib/guard/test/inspectors/focused_inspector.rb,
lib/guard/test/inspectors/keeping_inspector.rb

Defined Under Namespace

Modules: Inspector, Inspectors, Notifier, Options Classes: Command, Deprecator, Runner

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Test

Returns a new instance of Test.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/guard/test.rb', line 11

def initialize(options = {})
  super
  @options = {
    all_on_start:   true,
    all_after_pass: true,
    keep_failed:    true,
    test_paths:     ['test']
  }.update(options)
  @last_failed  = false
  @failed_paths = []

  @runner = Runner.new(options)
end

Instance Method Details

#reloadObject



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

def reload
  @failed_paths = []
end

#run_allObject



31
32
33
34
35
36
37
38
# File 'lib/guard/test.rb', line 31

def run_all
  Inspector.test_paths = @options[:test_paths]
  test_paths = @options[:test_paths].clone # because clean - cleaning variable
  passed = @runner.run(Inspector.clean(test_paths), message: 'Running all tests')

  @failed_paths = [] if passed
  @last_failed  = !passed
end

#run_on_modifications(paths) ⇒ Object



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

def run_on_modifications(paths)
  Inspector.test_paths = @options[:test_paths]
  paths += @failed_paths if @options[:keep_failed]
  paths  = Inspector.clean(paths)
  passed = @runner.run(paths)

  if passed
    # clean failed paths memory
    @failed_paths -= paths if @options[:keep_failed]

    # run all the tests if the changed tests failed, like autotest
    run_all if @last_failed && @options[:all_after_pass]
  else
    # remember failed paths for the next change
    @failed_paths += paths if @options[:keep_failed]

    # track whether the changed tests failed for the next change
    @last_failed = true
  end
end

#startObject



25
26
27
28
29
# File 'lib/guard/test.rb', line 25

def start
  Compat::UI.info("Guard::Test #{TestVersion::VERSION} is running, " +
                   "with Test::Unit #{::Test::Unit::VERSION}!", reset: true)
  run_all if @options[:all_on_start]
end