Class: Guard::PHPSpec

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/phpspec/runner.rb,
lib/guard/phpspec/version.rb,
lib/guard/phpspec/watcher.rb,
lib/guard/phpspec/notifier.rb,
lib/guard/phpspec/inspector.rb,
lib/guard/phpspec/formatter.rb

Defined Under Namespace

Modules: Formatter, Inspector, Notifier, Runner

Constant Summary

VERSION =
'0.0.1'
DEFAULT_OPTIONS =
{
    :all_on_start => true,
    :all_after_pass => true,
    :keep_failed => true,
    :cli => nil,
    :tests_path => "#{Dir.pwd}/spec"
}

Instance Method Summary (collapse)

Constructor Details

- (PHPSpec) initialize(watchers = [], options = {})

Initialize Guard::PHPSpec

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):

  • :all_on_start (Boolean)

    run all tests on start

  • :all_after_pass (Boolean)

    run all tests after failed tests pass

  • :keep_failed (Boolean)

    remember failed tests or not

  • :cli (String)

    The CLI arguments passed to phpspec

  • :tests_path (String)

    the path where all tests exist



29
30
31
32
33
34
35
36
37
38
# File 'lib/guard/phpspec/watcher.rb', line 29

def initialize(watchers = [], options = {})
  defaults = DEFAULT_OPTIONS.clone
  @options = defaults.merge(options)
  super(watchers, @options)

  @failed_paths = []
  @previous_failed = false

  Inspector.tests_path = @options[:tests_path]
end

Instance Method Details

- (Object) run_all(runner = nil)

Gets called when all tests should be run.

Parameters:

  • runner (Runner) (defaults to: nil)

    (nil) The test runner. If nil, Runner is assumed

Raises:

  • (:task_has_failed)

    when stop has failed



49
50
51
52
53
54
55
56
57
# File 'lib/guard/phpspec/watcher.rb', line 49

def run_all(runner = nil)
  runner ||= Runner
  success = runner.run(options[:tests_path], options.merge(
      :message => 'Running all tests'
  ))

  @previous_failed = !success
  throw :task_has_failed unless success
end

- (Object) run_on_changes(paths, runner = nil, inspector = nil)

Gets called when the watched tests have changes.

Parameters:

  • paths (Array<String>)

    to the changed tests

  • runner (Runner) (defaults to: nil)

    (nil) The test runner. If nil, Runner is assumed

Raises:

  • (:task_has_failed)

    when stop has failed



63
64
65
66
67
68
69
70
71
# File 'lib/guard/phpspec/watcher.rb', line 63

def run_on_changes(paths, runner = nil, inspector = nil)
  runner ||= Runner
  inspector ||= Inspector
  paths = inspector.clean(paths + @failed_paths)
  success = runner.run(paths, options)
  update_failed_paths(success, paths)
  run_all_after_pass(success)
  throw :task_has_failed unless success
end

- (Object) start

Gets called once when Guard starts.

Raises:

  • (:task_has_failed)

    when stop has failed



42
43
44
# File 'lib/guard/phpspec/watcher.rb', line 42

def start
  run_all if options[:all_on_start]
end