Class: RSpec::Core::Parser Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rspec-core/lib/rspec/core/option_parser.rb |
Class Method Summary
- .new(original_args) ⇒ Parser constructor Internal use only
- .parse(args, source = nil) Internal use only
Instance Attribute Summary
- #original_args readonly Internal use only
Instance Method Summary
- #parse(source = nil) Internal use only
-
#add_tag_filter(options, filter_type, tag_name, value = true)
private
Internal use only
rubocop:enable Metrics/MethodLength rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity.
- #configure_only_failures(options) private Internal use only
-
#parser(options)
private
Internal use only
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity.
- #set_fail_fast(options, value) private Internal use only
Class Method Details
.parse(args, source = nil)
[ GitHub ]# File 'rspec-core/lib/rspec/core/option_parser.rb', line 7
def self.parse(args, source=nil) new(args).parse(source) end
Instance Attribute Details
#original_args (readonly)
[ GitHub ]# File 'rspec-core/lib/rspec/core/option_parser.rb', line 11
attr_reader :original_args
Instance Method Details
#add_tag_filter(options, filter_type, tag_name, value = true) (private)
rubocop:enable Metrics/MethodLength rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity
# File 'rspec-core/lib/rspec/core/option_parser.rb', line 312
def add_tag_filter(, filter_type, tag_name, value=true) ( [filter_type] ||= {})[tag_name] = value end
#configure_only_failures(options) (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/option_parser.rb', line 320
def configure_only_failures( ) [:only_failures] = true add_tag_filter(, :inclusion_filter, :last_run_status, 'failed') end
#parse(source = nil)
[ GitHub ]# File 'rspec-core/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 = args.delete('--tty') ? { :tty => true } : {} begin parser( ).parse!(args) rescue OptionParser::InvalidOption => e abort "#{e.}#{" (defined in #{source})" if source}\n\n" \ "Please use --help for a listing of valid options" end [:files_or_directories_to_run] = args end
#parser(options) (private)
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
# File 'rspec-core/lib/rspec/core/option_parser.rb', line 39
def parser( ) OptionParser.new do |parser| parser.summary_width = 34 parser. = "Usage: rspec [options] [files or directories]\n\n" parser.on('-I PATH', 'Specify PATH to add to $LOAD_PATH (may be used more than once).') do |dirs| [:libs] ||= [] [:libs].concat(dirs.split(File::PATH_SEPARATOR)) end parser.on('-r', '--require PATH', 'Require a file.') do |path| [:requires] ||= [] [:requires] << path end parser.on('-O', '--options PATH', 'Specify the path to a custom options file.') do |path| [: ] = path end parser.on('--order TYPE[:SEED]', 'Run examples by the specified order type.', ' [defined] examples and groups are run in the order they are defined', ' [rand] randomize the order of groups and examples', ' [random] alias for rand', ' [random:SEED] e.g. --order random:123', ' [recently-modified] run the most recently modified files first') do |o| [:order] = o end parser.on('--seed SEED', Integer, 'Equivalent of --order rand:SEED.') do |seed| [:order] = "rand:#{seed}" end parser.on('--bisect[=verbose]', 'Repeatedly runs the suite in order to isolate the failures to the ', ' smallest reproducible case.') do |argument| [:bisect] = argument || true [:runner] = RSpec::Core::Invocations::Bisect.new end parser.on('--[no-]fail-fast[=COUNT]', 'Abort the run after a certain number of failures (1 by default).') do |argument| if argument == true value = 1 elsif argument == false || argument == 0 value = false else begin value = Integer(argument) rescue ArgumentError RSpec.warning "Expected an integer value for `--fail-fast`, got: #{argument.inspect}", :call_site => nil end end set_fail_fast(, value) end parser.on('--failure-exit-code CODE', Integer, 'Override the exit code used when there are failing specs.') do |code| [:failure_exit_code] = code end parser.on('--error-exit-code CODE', Integer, 'Override the exit code used when there are errors loading or running specs outside of examples.') do |code| [:error_exit_code] = code end parser.on('-X', '--[no-]drb', 'Run examples via DRb.') do |use_drb| [:drb] = use_drb [:runner] = RSpec::Core::Invocations::DRbWithFallback.new if use_drb end parser.on('--drb-port PORT', 'Port to connect to the DRb server.') do |o| [:drb_port] = o.to_i end parser.separator("\n **** Output ****\n\n") parser.on('-f', '--format FORMATTER', 'Choose a formatter.', ' [p]rogress (default - dots)', ' [d]ocumentation (group and example names)', ' [h]tml', ' [j]son', ' [f]ailures ("file:line:reason", suitable for editors integration)', ' custom formatter class name') do |o| [:formatters] ||= [] [:formatters] << [o] end parser.on('-o', '--out FILE', 'Write output to a file instead of $stdout. This option applies', ' to the previously specified --format, or the default format', ' if no format is specified.' ) do |o| [:formatters] ||= [['progress']] [:formatters].last << o end parser.on('--deprecation-out FILE', 'Write deprecation warnings to a file instead of $stderr.') do |file| [:deprecation_stream] = file end parser.on('-b', '--backtrace', 'Enable full backtrace.') do |_o| [:full_backtrace] = true end parser.on('-c', '--color', '--colour', '') do |_o| # flag will be excluded from `--help` output because it is deprecated [:color] = true [:color_mode] = :automatic end parser.on('--force-color', '--force-colour', 'Force the output to be in color, even if the output is not a TTY') do |_o| if [:color_mode] == :off abort "Please only use one of `--force-color` and `--no-color`" end [:color_mode] = :on end parser.on('--no-color', '--no-colour', 'Force the output to not be in color, even if the output is a TTY') do |_o| if [:color_mode] == :on abort "Please only use one of --force-color and --no-color" end [:color_mode] = :off end parser.on('-p', '--[no-]profile [COUNT]', 'Enable profiling of examples and list the slowest examples (default: 10).') do |argument| [:profile_examples] = if argument.nil? true elsif argument == false false else begin Integer(argument) rescue ArgumentError RSpec.warning "Non integer specified as profile count, separate " \ "your path from options with -- e.g. " \ "`rspec --profile -- #{argument}`", :call_site => nil true end end end parser.on('--dry-run', 'Print the formatter output of your suite without', ' running any examples or hooks') do |_o| [:dry_run] = true end parser.on('-w', '--warnings', 'Enable ruby warnings') do if Object.const_defined?(:Warning) && Warning.respond_to?(:[]=) # :nocov: on older Ruby without Warning Warning[:deprecated] = true # :nocov: end $VERBOSE = true end parser.separator <<-FILTERING **** Filtering/tags **** In addition to the following options for selecting specific files, groups, or examples, you can select individual examples by appending the line number(s) to the filename: rspec path/to/a_spec.rb:37:87 You can also pass example ids enclosed in square brackets: rspec path/to/a_spec.rb[1:5,1:6] # run the 5th and 6th examples/groups defined in the 1st group FILTERING parser.on('--only-failures', "Filter to just the examples that failed the last time they ran.") do configure_only_failures( ) end parser.on("-n", "--next-failure", "Apply `--only-failures` and abort after one failure.", " (Equivalent to `--only-failures --fail-fast --order defined`)") do configure_only_failures( ) set_fail_fast(, 1) [:order] ||= 'defined' end parser.on('-P', '--pattern PATTERN', 'Load files matching pattern (default: "spec/**/*_spec.rb").') do |o| if [:pattern] [:pattern] += ',' + o else [:pattern] = o end end parser.on('--exclude-pattern PATTERN', 'Load files except those matching pattern. Opposite effect of --pattern.') do |o| [:exclude_pattern] = o end parser.on('-e', '--example STRING', "Run examples whose full nested names include STRING (may be", " used more than once)") do |o| ( [:full_description] ||= []) << Regexp.compile(Regexp.escape(o)) end parser.on('-E', '--example-matches REGEX', "Run examples whose full nested names match REGEX (may be", " used more than once)") do |o| ( [:full_description] ||= []) << Regexp.compile(o) end parser.on('-t', '--tag TAG[:VALUE]', 'Run examples with the specified tag, or exclude examples', 'by adding ~ 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(':', 2) name = name.to_sym parsed_value = case value when nil then true # The default value for tags is true when 'true' then true when 'false' then false when 'nil' then nil when /^:/ then value[1..-1].to_sym when /^\d+$/ then Integer(value) when /^\d+.\d+$/ then Float(value) else value end add_tag_filter(, filter_type, name, parsed_value) 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| [:default_path] = path end parser.separator("\n **** Utility ****\n\n") parser.on('--init', 'Initialize your project with RSpec.') do |_cmd| [:runner] = RSpec::Core::Invocations::InitializeProject.new end parser.on('-v', '--version', 'Display the version.') do [:runner] = RSpec::Core::Invocations::PrintVersion.new end # These options would otherwise be confusing to users, so we forcibly # prevent them from executing. # # * --I is too similar to -I. # * -d was a shorthand for --debugger, which is removed, but now would # trigger --default-path. = %w[-d --I] = + %w[-c] parser.on_tail('-h', '--help', "You're looking at it.") do [:runner] = RSpec::Core::Invocations::PrintHelp.new(parser, ) end # This prevents usage of the invalid_options. .each do |option| parser.on(option) do raise OptionParser::InvalidOption.new end end end end
#set_fail_fast(options, value) (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/option_parser.rb', line 316
def set_fail_fast(, value) [:fail_fast] = value end