class RSpec::Core::Parser

Attributes

parser_method[RW]

Public Instance Methods

mrspec_parser(options, *args, &b) click to toggle source

Ours calls RSpec's, then modifies values on the returned parser

# File lib/mrspec/add_options_to_rspec_parser.rb, line 21
def mrspec_parser(options, *args, &b)
  option_parser = rspec_parser(options, *args, &b)

  # update the program name
  option_parser.banner.gsub! /\brspec\b/, 'mrspec'

  # print mrspec version, and dependency versions.
  # calling exit and toplevel puts, b/c that's what RSpec's does https://github.com/rspec/rspec-core/blob/c7c1154934c42b5f6905bb7bd22025fe6c8a816c/lib/rspec/core/option_parser.rb#L290
  # and I don't feel like figuring out how to work around it.
  option_parser.on('-v', '--version', 'Display the version.') do
    options[:runner] = method :print_mrspec_version
  end

  format_description = option_parser.top.short['f'].desc
  first_option       = format_description.find { |s| s[/\[[a-zA-Z]\]/] }
  leading_whitespace = first_option[/^\s*/]
  index              = format_description.index first_option
  format_description.insert index, "#{leading_whitespace}[w]hat (we've got here is an error to communicate)"

  option_parser
end
print_mrspec_version(_opts, _err, out) click to toggle source