Parent

Class Index [+]

Quicksearch

RSpec::Core::Parser

Public Class Methods

parse!(args) click to toggle source
   # File lib/rspec/core/option_parser.rb, line 6
6:     def self.parse!(args)
7:       new.parse!(args)
8:     end

Public Instance Methods

parse(args) click to toggle source
Alias for: parse!
parse(args) click to toggle source
Alias for: parse!
parse!(args) click to toggle source
    # File lib/rspec/core/option_parser.rb, line 14
14:     def parse!(args)
15:       return {} if args.empty?
16:       if args.include?("--formatter")
17:         RSpec.deprecate("the --formatter option", "-f or --format")
18:         args[args.index("--formatter")] = "--format"
19:       end
20:       options = args.delete('--tty') ? {:tty => true} : {}
21:       parser(options).parse!(args)
22:       options
23:     end
Also aliased as: parse, parse
parser(options) click to toggle source
     # File lib/rspec/core/option_parser.rb, line 27
 27:     def parser(options)
 28:       OptionParser.new do |parser|
 29:         parser.banner = "Usage: rspec [options] [files or directories]\n\n"
 30: 
 31:         parser.on('-I PATH', 'Specify PATH to add to $LOAD_PATH (may be used more than once).') do |dir|
 32:           options[:libs] ||= []
 33:           options[:libs] << dir
 34:         end
 35: 
 36:         parser.on('-r', '--require PATH', 'Require a file.') do |path|
 37:           options[:requires] ||= []
 38:           options[:requires] << path
 39:         end
 40: 
 41:         parser.on('-O', '--options PATH', 'Specify the path to a custom options file.') do |path|
 42:           options[:custom_options_file] = path
 43:         end
 44: 
 45:         parser.on('--order TYPE[:SEED]', 'Run examples by the specified order type.',
 46:                   '  [default] files are ordered based on the underlying file',
 47:                   '            system\s order',
 48:                   '  [rand]    randomize the order of files, groups and examples',
 49:                   '  [random]  alias for rand',
 50:                   '  [random:SEED] e.g. --order random:123') do |o|
 51:           options[:order] = o
 52:         end
 53: 
 54:         parser.on('--seed SEED', Integer, 'Equivalent of --order rand:SEED.') do |seed|
 55:           options[:order] = "rand:#{seed}"
 56:         end
 57: 
 58:         parser.on('-d', '--debugger', 'Enable debugging.') do |o|
 59:           options[:debug] = true
 60:         end
 61: 
 62:         parser.on('--fail-fast', 'Abort the run on first failure.') do |o|
 63:           options[:fail_fast] = true
 64:         end
 65: 
 66:         parser.on('--failure-exit-code CODE', Integer, 'Override the exit code used when there are failing specs.') do |code|
 67:           options[:failure_exit_code] = code
 68:         end
 69: 
 70:         parser.on('-X', '--[no-]drb', 'Run examples via DRb.') do |o|
 71:           options[:drb] = o
 72:         end
 73: 
 74:         parser.on('--drb-port PORT', 'Port to connect to the DRb server.') do |o|
 75:           options[:drb_port] = o.to_i
 76:         end
 77: 
 78:         parser.on('--init', 'Initialize your project with RSpec.') do |cmd|
 79:           ProjectInitializer.new(cmd).run
 80:           exit
 81:         end
 82: 
 83:         parser.on('--configure', 'Deprecated. Use --init instead.') do |cmd|
 84:           warn "--configure is deprecated with no effect. Use --init instead."
 85:           exit
 86:         end
 87: 
 88:         parser.separator("\n  **** Output ****\n\n")
 89: 
 90:         parser.on('-f', '--format FORMATTER', 'Choose a formatter.',
 91:                 '  [p]rogress (default - dots)',
 92:                 '  [d]ocumentation (group and example names)',
 93:                 '  [h]tml',
 94:                 '  [t]extmate',
 95:                 '  custom formatter class name') do |o|
 96:           options[:formatters] ||= []
 97:           options[:formatters] << [o]
 98:         end
 99: 
100:         parser.on('-o', '--out FILE',
101:                   'Write output to a file instead of STDOUT. This option applies',
102:                   '  to the previously specified --format, or the default format',
103:                   '  if no format is specified.'
104:                  ) do |o|
105:           options[:formatters] ||= [['progress']]
106:           options[:formatters].last << o
107:         end
108: 
109:         parser.on('-b', '--backtrace', 'Enable full backtrace.') do |o|
110:           options[:full_backtrace] = true
111:         end
112: 
113:         parser.on('-c', '--[no-]color', '--[no-]colour', 'Enable color in the output.') do |o|
114:           options[:color] = o
115:         end
116: 
117:         parser.on('-p', '--profile', 'Enable profiling of examples and list 10 slowest examples.') do |o|
118:           options[:profile_examples] = o
119:         end
120: 
121:         parser.separator   **** Filtering/tags ****    In addition to the following options for selecting specific files, groups,    or examples, you can select a single example by appending the line number to    the filename:      rspec path/to/a_spec.rb:37
122: 
123:         parser.on('-P', '--pattern PATTERN', 'Load files matching pattern (default: "spec/**/*_spec.rb").') do |o|
124:           options[:pattern] = o
125:         end
126: 
127:         parser.on('-e', '--example STRING', "Run examples whose full nested names include STRING") do |o|
128:           options[:full_description] = Regexp.compile(Regexp.escape(o))
129:         end
130: 
131:         parser.on('-l', '--line_number LINE', 'Specify line number of an example or group (may be',
132:                                               '  used more than once).') do |o|
133:           (options[:line_numbers] ||= []) << o
134:         end
135: 
136:         parser.on('-t', '--tag TAG[:VALUE]',
137:                   'Run examples with the specified tag, or exclude examples',
138:                   'by adding ~ before the tag.',
139:                   '  - e.g. ~slow',
140:                   '  - TAG is always converted to a symbol') do |tag|
141:           filter_type = tag =~ /^~/ ? :exclusion_filter : :inclusion_filter
142: 
143:           name,value = tag.gsub(/^(~@|~|@)/, '').split(':')
144:           name = name.to_sym
145: 
146:           options[filter_type] ||= {}
147:           options[filter_type][name] = value.nil? ? true : eval(value) rescue value
148:         end
149: 
150:         parser.on('--default_path PATH', 'Set the default path where RSpec looks for examples (can',
151:                                          '  be a path to a file or a directory).') do |path|
152:           options[:default_path] = path
153:         end
154: 
155:         parser.separator("\n  **** Utility ****\n\n")
156: 
157:         parser.on('-v', '--version', 'Display the version.') do
158:           puts RSpec::Core::Version::STRING
159:           exit
160:         end
161: 
162:         parser.on_tail('-h', '--help', "You're looking at it.") do
163:           puts parser
164:           exit
165:         end
166: 
167:       end
168:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.