Class: FTest::CLI

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

Defined Under Namespace

Classes: ArgvParser, Options

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, stdout) ⇒ CLI

Returns a new instance of CLI.



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

def initialize argv, stdout
  @argv   = argv
  @stdout = stdout
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/ftest/cli.rb', line 10

def options
  @options
end

Class Method Details

.run(argv) ⇒ Object



5
6
7
8
# File 'lib/ftest/cli.rb', line 5

def self.run argv
  instance = new argv, $stdout
  instance.()
end

Instance Method Details

#build_loggerObject



31
32
33
34
35
36
# File 'lib/ftest/cli.rb', line 31

def build_logger
  logger = Logger.new @stdout
  logger.level = options.log_level
  logger.progname = "ftest"
  logger
end

#callObject



17
18
19
20
21
# File 'lib/ftest/cli.rb', line 17

def call
  @options = ArgvParser.(@argv)
  setup_config
  Runner.(filter_files) or exit 1
end

#filter_filesObject



38
39
40
41
42
# File 'lib/ftest/cli.rb', line 38

def filter_files
  resolve_files.reject do |path|
    path.end_with? "init.rb"
  end
end

#resolve_filesObject



44
45
46
47
48
49
50
51
52
# File 'lib/ftest/cli.rb', line 44

def resolve_files
  options.paths.flat_map do |path|
    if path.end_with? ".rb"
      [path]
    else
      Dir[File.join path, "**/*.rb"]
    end
  end
end

#setup_configObject



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

def setup_config
  Config.child_count = options.child_count
  Config.fail_fast = options.fail_fast?
  Config.logger = build_logger
  Config.reverse_backtraces = options.reverse_backtraces?
  Config.trim_backtraces = options.trim_backtraces?
end