Class: Guard::BustedRunner

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/busted/runner.rb

Overview

The class responsible for running ‘busted’ command in the proper context.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BustedRunner

Initialize BustedRunner It accepts following options:

- cmd - command to perform for specific spec files,
- cmd_options [Array<String>] - options for cmd command,
- cmd_all - command to perform for all spec files
- cmd_all_options [Array<String>] - options for cmd_all command.

Parameters:

  • options (Hash<Symbol, String>)

    options for runner



20
21
22
23
24
25
26
27
# File 'lib/guard/busted/runner.rb', line 20

def initialize(options)
  super

  @cmd = options[:cmd]
  @cmd_options = Array(options[:cmd_options])
  @cmd_all = options[:cmd_all]
  @cmd_all_options = Array(options[:cmd_all_options])
end

Instance Attribute Details

#cmdObject

Returns the value of attribute cmd.



10
11
12
# File 'lib/guard/busted/runner.rb', line 10

def cmd
  @cmd
end

#cmd_allObject

Returns the value of attribute cmd_all.



10
11
12
# File 'lib/guard/busted/runner.rb', line 10

def cmd_all
  @cmd_all
end

#cmd_all_optionsObject

Returns the value of attribute cmd_all_options.



10
11
12
# File 'lib/guard/busted/runner.rb', line 10

def cmd_all_options
  @cmd_all_options
end

#cmd_optionsObject

Returns the value of attribute cmd_options.



10
11
12
# File 'lib/guard/busted/runner.rb', line 10

def cmd_options
  @cmd_options
end

Instance Method Details

#run(paths) ⇒ Object

Run tests for the given paths

Parameters:

  • paths (Array<String>)

    array of spec files

Raises:

  • (:task_has_failed)

    when tests failed



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

def run(paths)
  existing_paths = paths.select { |p| Pathname.new(p).exist? }

  return if existing_paths.empty?

  UI.info "Running #{existing_paths.join(', ')}"
  status, stdout = perform_command([@cmd] + @cmd_options + existing_paths)
  Guard::BustedNotifier.new(stdout, status).notify
  throw(:task_has_failed) unless status
end

#run_allObject

Run all tests in the project

Raises:

  • (:task_has_failed)

    when run_all has failed



32
33
34
35
36
37
# File 'lib/guard/busted/runner.rb', line 32

def run_all
  UI.info 'Running all tests'
  status, stdout = perform_command([@cmd_all] + @cmd_all_options)
  Guard::BustedNotifier.new(stdout, status).notify
  throw(:task_has_failed) unless status
end