Module: Speq::CLI

Defined in:
lib/speq/cli.rb

Overview

Includes useful methods for running Speq from a CLI

Class Method Summary collapse

Class Method Details

.file_description(path) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/speq/cli.rb', line 26

def self.file_description(path)
  path
    .split('/').last
    .delete_suffix('_speq.rb')
    .split('_')
    .map(&:capitalize)
    .join(' ')
end

.file_test(file) ⇒ Object



22
23
24
# File 'lib/speq/cli.rb', line 22

def self.file_test(file)
  speq(file_description(file)) { instance_eval(File.read(file), file) }
end

.find_files(cli_args) ⇒ Object



35
36
37
38
39
# File 'lib/speq/cli.rb', line 35

def self.find_files(cli_args)
  prefixes = cli_args.empty? ? ['*'] : cli_args
  glob_pattern = "#{Dir.pwd}/**/{#{prefixes.join(',')}}_speq.rb"
  Dir.glob(glob_pattern)
end


41
42
43
# File 'lib/speq/cli.rb', line 41

def self.print_report(tests)
  puts tests
end

.run(cli_args) ⇒ Object



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

def self.run(cli_args)
  run_tests(find_files(cli_args))
end

.run_and_report(cli_args) ⇒ Object



14
15
16
# File 'lib/speq/cli.rb', line 14

def self.run_and_report(cli_args)
  print_report(run(cli_args))
end

.run_tests(paths) ⇒ Object



18
19
20
# File 'lib/speq/cli.rb', line 18

def self.run_tests(paths)
  paths.map { |file| file_test(file) }
end