Class: RSpec::Core::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/mrspec/add_options_to_rspec_parser.rb

Instance Method Summary collapse

Instance Method Details

#mrspec_parser(*args, &b) ⇒ Object

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



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mrspec/add_options_to_rspec_parser.rb', line 16

def mrspec_parser(*args, &b)
  option_parser = rspec_parser(*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
    $stdout.puts "mrspec     #{MRspec::VERSION}\n"\
                 "rspec-core #{RSpec::Core::Version::STRING}\n"\
                 "minitest   #{Minitest::VERSION}\n"
    exit
  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