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)
"Find tests and run them by trying to match an individual test or the name of a test file(s).\n\nSee full README: https://github.com/petekinnecom/test_launcher\n\nUsage: `test_launcher \"search string\" [--all]`\n\nVERSION: \#{TestLauncher::VERSION}\n\n"

Instance Method Summary collapse

Constructor Details

#initialize(args, env) ⇒ InputParser

Returns a new instance of InputParser.



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

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



68
69
70
# File 'lib/test_launcher/cli/input_parser.rb', line 68

def options
  @options
end

#requests(shell:, searcher:) ⇒ Object



38
39
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
# File 'lib/test_launcher/cli/input_parser.rb', line 38

def requests(shell:, searcher:)
  if @search_string.size == 0
    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]
    else
      [Frameworks::Minitest, Frameworks::RSpec, Frameworks::ExUnit]
    end

  frameworks.map {|framework|
    Request.new(
      search_string: @search_string.join(" "),
      run_all: !!@options[:run_all],
      disable_spring: !!@env["DISABLE_SPRING"],
      example_name: @options[:name],
      framework: framework,
      shell: shell,
      searcher: searcher
    )
  }
end