Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

better message when the command line arguments are incorrect #688

Closed
wants to merge 3 commits into from

6 participants

@JordiPolo

Currently we let the exception from OptionParser to propagate, is difficult to read and ugly.

@soulcutter
Collaborator

I like this, except I think this should use abort(msg) rather than puts + exit(false)

@myronmarston

except I think this should use abort(msg) rather than puts + exit(false)

Yep, that'd be good.

It'd also be good to add a spec for this; I think it'd work well to use a simpol mock expectation:

parser = Parser.new
parser.should_receive(:abort).with(/use --help/)
parse.parse!(some_invalid_args)
@alindeman
Collaborator

@JordiPolo, are you interested in writing the spec? If not, I'd be happy to run with your implementation and merge this in after adding one.

@alindeman alindeman was assigned
@JordiPolo

@alindeman Yes, I gonna update this PR with your suggestions and the spec

@JordiPolo

I think I have addressed the issues. Thank you for your advise. I was unaware of the Kernel.abort method.

@alindeman alindeman closed this in ccedfcb
@alindeman
Collaborator

Thank you @JordiPolo :rainbow:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
6 lib/rspec/core/option_parser.rb
@@ -18,7 +18,11 @@ def parse!(args)
args[args.index("--formatter")] = "--format"
end
options = args.delete('--tty') ? {:tty => true} : {}
- parser(options).parse!(args)
+ begin
+ parser(options).parse!(args)
+ rescue OptionParser::InvalidOption => e
+ abort(e.message + "\n" + "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)
Something went wrong with that request. Please try again.