Class: RSpec::Core::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/core/option_parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_args) ⇒ Parser

Returns a new instance of Parser



13
14
15
# File 'lib/rspec/core/option_parser.rb', line 13

def initialize(original_args)
  @original_args = original_args
end

Instance Attribute Details

#original_argsObject (readonly)

Returns the value of attribute original_args



11
12
13
# File 'lib/rspec/core/option_parser.rb', line 11

def original_args
  @original_args
end

Class Method Details

.parse(args, source = nil) ⇒ Object



7
8
9
# File 'lib/rspec/core/option_parser.rb', line 7

def self.parse(args, source=nil)
  new(args).parse(source)
end

Instance Method Details

#parse(source = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rspec/core/option_parser.rb', line 17

def parse(source=nil)
  return { :files_or_directories_to_run => [] } if original_args.empty?
  args = original_args.dup

  options = args.delete('--tty') ? { :tty => true } : {}
  begin
    parser(options).parse!(args)
  rescue OptionParser::InvalidOption => e
    failure = e.message
    failure << " (defined in #{source})" if source
    abort "#{failure}\n\nPlease use --help for a listing of valid options"
  end

  options[:files_or_directories_to_run] = args
  options
end