Class: FlakyTester::CommandParser

Inherits:
Object
  • Object
show all
Defined in:
lib/flaky_tester/command_parser.rb

Instance Method Summary collapse

Constructor Details

#initializeCommandParser



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/flaky_tester/command_parser.rb', line 8

def initialize
  @options = DEFAULT_OPTIONS.dup

  @option_parser = OptionParser.new do |option_parser|
    option_parser.banner = "Usage: fspec [options]"

    option_message = "Number of times to run the test suite (default: #{DEFAULT_OPTIONS[:times]})"
    option_parser.on("-t", "--times TIMES", option_message) do |times|
      raise(Errors::InvalidTimes) unless valid_times?(times)
      @options[:times] = times.to_i
    end

    option_message = "Relative path containing the tests to run (default: RSpec's default)"
    option_parser.on("-p", "--path PATH", option_message) do |path|
      raise(Errors::UnknownPath) unless valid_path?(path)
      @options[:path] = path
    end

    option_parser.on("-h", "--help", "Prints command instructions") do
      puts(option_parser)
      exit
    end
  end
end

Instance Method Details

#parse(args) ⇒ Object



33
34
35
36
# File 'lib/flaky_tester/command_parser.rb', line 33

def parse(args)
  @option_parser.parse!(args)
  @options
end

#to_sObject



38
39
40
# File 'lib/flaky_tester/command_parser.rb', line 38

def to_s
  @option_parser.to_s
end