Skip to content

Commit

Permalink
organize the output from rspec --help
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Nov 6, 2011
1 parent 44965b4 commit 8b86187
Showing 1 changed file with 80 additions and 62 deletions.
142 changes: 80 additions & 62 deletions lib/rspec/core/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,62 @@ def parser(options)
OptionParser.new do |parser|
parser.banner = "Usage: rspec [options] [files or directories]\n\n"

parser.on('-b', '--backtrace', 'Enable full backtrace') do |o|
options[:full_backtrace] = true
parser.on('-I DIRECTORY', 'specify $LOAD_PATH directory (may be used more than once)') do |dir|
options[:libs] ||= []
options[:libs] << dir
end

parser.on('-c', '--[no-]color', '--[no-]colour', 'Enable color in the output') do |o|
options[:color] = o
parser.on('-r', '--require PATH', 'Require a file') do |path|
options[:requires] ||= []
options[:requires] << path
end

parser.on('-O', '--options PATH', 'Specify the path to a custom options file') do |path|
options[:custom_options_file] = path
end

parser.on('--order TYPE', 'Run examples by the specified order type',
' [rand] randomized',
' [random] alias for rand',
' [random:SEED] e.g. --order random:123') do |o|
options[:order] = o
end

parser.on('--seed SEED', "Equivalent of --order rand:SEED") do |seed|
options[:order] = "rand:#{seed}"
end

parser.on('-d', '--debugger', 'Enable debugging') do |o|
options[:debug] = true
end

parser.on('-e', '--example STRING', "Run examples whose full nested names include STRING") do |o|
options[:full_description] = Regexp.compile(Regexp.escape(o))
parser.on('--fail-fast', 'Abort the run on first failure') do |o|
options[:fail_fast] = true
end

parser.on('--failure-exit-code CODE', 'Override the exit code used when there are failing specs') do |o|
options[:failure_exit_code] = o.to_i
end

parser.on('-X', '--[no-]drb', 'Run examples via DRb') do |o|
options[:drb] = o
end

parser.on('--drb-port [PORT]', 'Port to connect to on the DRb server') do |o|
options[:drb_port] = o.to_i
end

parser.on('--configure COMMAND', 'Generate configuration files') do |cmd|
CommandLineConfiguration.new(cmd).run
exit
end

parser.on("--tty", "Used internally by rspec when sending commands to other processes") do |o|
options[:tty] = true
end

parser.separator("\n **** Output formatting ****\n\n")

parser.on('-f', '--format FORMATTER', 'Choose a formatter',
' [p]rogress (default - dots)',
' [d]ocumentation (group and example names)',
Expand All @@ -63,77 +103,46 @@ def parser(options)
options[:formatters].last << o
end

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

parser.on('-I DIRECTORY', 'specify $LOAD_PATH directory (may be used more than once)') do |dir|
options[:libs] ||= []
options[:libs] << dir
end

parser.on('-l', '--line_number LINE', 'Specify the line number of an example to run. May be specified multiple times.') do |o|
(options[:line_numbers] ||= []) << o
end

parser.on('-O', '--options PATH', 'Specify the path to an options file') do |path|
options[:custom_options_file] = path
end

parser.on('--order TYPE', 'Run examples by the specified order type',
' [rand] randomized',
' [random] alias for rand',
' [random:SEED] e.g. --order random:123') do |o|
options[:order] = o
parser.on('-b', '--backtrace', 'Enable full backtrace') do |o|
options[:full_backtrace] = true
end

parser.on('--seed SEED', "Equivalent of --order rand:SEED") do |seed|
options[:order] = "rand:#{seed}"
parser.on('-c', '--[no-]color', '--[no-]colour', 'Enable color in the output') do |o|
options[:color] = o
end

parser.on('-p', '--profile', 'Enable profiling of examples with output of the top 10 slowest examples') do |o|
options[:profile_examples] = o
end

parser.on('-P', '--pattern PATTERN', 'Load files matching this pattern. Default is "spec/**/*_spec.rb"') do |o|
options[:pattern] = o
end
parser.separator <<-FILTERING
parser.on('-r', '--require PATH', 'Require a file') do |path|
options[:requires] ||= []
options[:requires] << path
end
**** Filtering and tags ****
parser.on('-v', '--version', 'Show version') do
puts RSpec::Core::Version::STRING
exit
end
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:
parser.on('-X', '--[no-]drb', 'Run examples via DRb') do |o|
options[:drb] = o
end
rspec path/to/a_spec.rb:37
parser.on('--configure COMMAND', 'Generate configuration files') do |cmd|
CommandLineConfiguration.new(cmd).run
exit
end
FILTERING

parser.on('--drb-port [PORT]', 'Port to connect to on the DRb server') do |o|
options[:drb_port] = o.to_i
parser.on('-P', '--pattern PATTERN', 'Load files matching pattern (default: "spec/**/*_spec.rb")') do |o|
options[:pattern] = o
end

parser.on('--fail-fast', 'Abort the run on first failure.') do |o|
options[:fail_fast] = true
parser.on('-e', '--example STRING', "Run examples whose full nested names include STRING") do |o|
options[:full_description] = Regexp.compile(Regexp.escape(o))
end

parser.on('--failure-exit-code CODE', 'Override the exit code used when there are failing specs.') do |o|
options[:failure_exit_code] = o.to_i
parser.on('-l', '--line_number LINE', 'Specify line number of an example or group (may be specified multiple times)') do |o|
(options[:line_numbers] ||= []) << o
end

parser.on('-t', '--tag TAG[:VALUE]', 'Run examples with the specified tag',
'To exclude examples, add ~ before the tag (e.g. ~slow)',
'(TAG is always converted to a symbol)') do |tag|
parser.on('-t', '--tag TAG[:VALUE]',
'Run examples with the specified tag, or exclude',
'examples by ading ~ before the tag (e.g. ~slow)',
'(TAG is always converted to a symbol)') do |tag|
filter_type = tag =~ /^~/ ? :exclusion_filter : :inclusion_filter

name,value = tag.gsub(/^(~@|~|@)/, '').split(':')
Expand All @@ -150,14 +159,23 @@ def parser(options)
end
end

parser.on('--tty', 'Used internally by rspec when sending commands to other processes') do |o|
options[:tty] = true
end

parser.on('--default_path PATH', 'Set the default path where RSpec looks for examples.',
'Can be a path to a file or a directory') do |path|
options[:default_path] = path
end

parser.separator("\n **** Utility ****\n\n")

parser.on('-v', '--version', 'Show version') do
puts RSpec::Core::Version::STRING
exit
end

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

end
end
end
Expand Down

0 comments on commit 8b86187

Please sign in to comment.