Skip to content
Browse files

A more useful error message is shown when an invalid command line opt…

…ion is used

* Closes #688
  • Loading branch information...
1 parent 336f201 commit ccedfcb9bbddabfe40dc3d924d79cb5a7aceaa4a @jcarres-mdsol jcarres-mdsol committed with alindeman
Showing with 15 additions and 1 deletion.
  1. +2 −0 Changelog.md
  2. +7 −1 lib/rspec/core/option_parser.rb
  3. +6 −0 spec/rspec/core/option_parser_spec.rb
View
2 Changelog.md
@@ -18,6 +18,8 @@ Enhancements
* --default_path can be specified as --default-line; --line_number can be
specified as --line-number. Hyphens are more idiomatic command line argument
separators (Sam Phippen).
+* A more useful error message is shown when an invalid command line option is
+ used (Jordi Polo).
Bug fixes
View
8 lib/rspec/core/option_parser.rb
@@ -17,7 +17,13 @@ def parse!(args)
convert_deprecated_args(args)
options = args.delete('--tty') ? {:tty => true} : {}
- parser(options).parse!(args)
+ begin
+ parser(options).parse!(args)
+ rescue OptionParser::InvalidOption => e
+ puts e.message
+ abort "please use --help for documentation on the options available"
+ end
+
options
end
View
6 spec/rspec/core/option_parser_spec.rb
@@ -15,6 +15,12 @@ module RSpec::Core
parser.parse!([])
end
+ it "proposes you to use --help and returns an error on incorrect argument" do
+ parser = Parser.new
+ parser.should_receive(:abort).with(/use --help/)
+ parser.parse!(%w[--my_very_wrong_argument_ein])
+ end
+
describe "--formatter" do
it "is deprecated" do
RSpec.should_receive(:deprecate)

0 comments on commit ccedfcb

Please sign in to comment.
Something went wrong with that request. Please try again.