Class: RSpec::Parallel::Parser

Inherits:
Core::Parser
  • Object
show all
Defined in:
lib/rspec/parallel/option_parser.rb

Instance Method Summary collapse

Instance Method Details

#parse!(args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rspec/parallel/option_parser.rb', line 4

def parse!(args)
  return {} if args.empty?

  convert_deprecated_args(args)

  options = args.delete('--tty') ? {:tty => true} : {}
  begin
    parser(options).parse(args)
    delete_next = false
    args.delete_if do |arg|
      if delete_next
        true
      elsif arg == '--parallel-test'
        delete_next = true
        true
      end
    end
    parser(options, true).parse!(args)
  rescue OptionParser::InvalidOption => e
    abort "#{e.message}\n\nPlease use --help for a listing of valid options"
  end

  options
end

#parser(options, bypass = false) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rspec/parallel/option_parser.rb', line 29

def parser(options, bypass = false)
  if bypass
    super(options)
  else
    OptionParser.new do |parser|
      parser.banner = "\n  **** Parallel Testing ****\n\n"

      parser.on('--parallel-test NUMBER', Integer, 'Run the tests with the specified number of parallel threads (default: 1).') do |n|
        puts "found --parallel-test with value of: #{n}"
        options[:thread_maximum] = n || 1
      end

      parser.on('-v', '--version', 'Display the version.') do
        puts "rspec-parallel: #{RSpec::Parallel::Version::STRING}"
      end

      parser.on_tail('-h', '--help', "You're looking at it.") do
        puts parser
      end
    end
  end
end