Class: Spinach::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/spinach/cli.rb

Overview

The cli is a class responsible of handling all the command line interface logic.

Instance Method Summary (collapse)

Constructor Details

- (Cli) initialize(args = ARGV)

Returns a new instance of Cli

Parameters:

  • arguments (Array<String>)

    The command line arguments



12
13
14
# File 'lib/spinach/cli.rb', line 12

def initialize(args = ARGV)
  @args = args
end

Instance Method Details

- (Array) feature_files

Uses given args to list the feature files to run. It will find a single feature, features in a folder and subfolders or every feature file in the feature path.

Returns:

  • (Array)

    An array with the feature file names.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/spinach/cli.rb', line 50

def feature_files
  files_to_run = []

  @args.each do |arg|
    if arg.match(/\.feature/)
      if File.exists? arg.gsub(/:\d*/, '')
        files_to_run << arg
      else
        fail! "#{arg} could not be found"
      end
    elsif File.directory?(arg)
      files_to_run << Dir.glob(File.join(arg, '**', '*.feature'))
    else
      fail! "invalid argument - #{arg}"
    end
  end

  if !files_to_run.empty?
    files_to_run.flatten
  else
    Dir.glob(File.join(Spinach.config[:features_path], '**', '*.feature'))
  end
end

- (Hash) options

Returns A hash of options separated by its type.

Examples:

Cli.new.options
# => { reporter: { backtrace: true } }

Returns:

  • (Hash)

    A hash of options separated by its type.



38
39
40
# File 'lib/spinach/cli.rb', line 38

def options
  @options ||= parse_options
end

- (true, false) run

Runs all the features.

Returns:

  • (true, false)

    The exit status - true for success, false for failure.



22
23
24
25
26
27
28
# File 'lib/spinach/cli.rb', line 22

def run
  options

  return true if Spinach.config.generate

  Spinach::Runner.new(feature_files).run
end