Class: TestLauncher::CLI::InputParser

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

Constant Summary collapse

ParseError =
Class.new(RuntimeError)
<<-DESC
Find tests and run them by trying to match an individual test or the name of a test file(s).

See full README: https://github.com/petekinnecom/test_launcher

Usage: `test_launcher "search string" [--all]`

VERSION: #{TestLauncher::VERSION}

DESC

Instance Method Summary collapse

Constructor Details

#initialize(args, env) ⇒ InputParser

Returns a new instance of InputParser.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/test_launcher/cli/input_parser.rb', line 28

def initialize(args, env)
  @search_string = args
  @env = env
  @options = {}
  option_parser.parse!(args)
rescue OptionParser::ParseError
  puts "Invalid arguments"
  puts "----"
  puts option_parser
  exit
end

Instance Method Details

#optionsObject



86
87
88
# File 'lib/test_launcher/cli/input_parser.rb', line 86

def options
  @options
end

#parsed_options(shell:, searcher:) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/test_launcher/cli/input_parser.rb', line 40

def parsed_options(shell:, searcher:)
  if @search_string.size == 0 && !@options[:rerun]
    puts "Enter a search term"
    puts "----"
    puts option_parser
    exit
  elsif @search_string.size > 0 && @options[:rerun]
    puts "Cannot specify search terms and use --rerun flag"
    puts "----"

    puts option_parser
    exit
  end

  frameworks =
    if @options[:framework] == "rspec"
      [Frameworks::RSpec]
    elsif @options[:framework] == "minitest"
      [Frameworks::Minitest]
    elsif @options[:framework] == "ex_unit"
      [Frameworks::ExUnit]
    elsif @options[:framework] == "generic"
      [Frameworks::Generic]
    else
      [
        Frameworks::Minitest,
        Frameworks::RSpec,
        Frameworks::ExUnit,
        Frameworks::Mochajs,
        Frameworks::Generic,
      ].select {|f| f.active?}
    end

  Options.new(
    search_string: @search_string.join(" "),
    run_all: !!@options[:run_all],
    rerun: !!@options[:rerun],
    disable_spring: @options[:disable_spring] || !!@env["DISABLE_SPRING"],
    force_spring: @options[:force_spring],
    example_name: @options[:name],
    frameworks: frameworks,
    shell: shell,
    searcher: searcher
  )
end