Permalink
Browse files

handle invalid options

  • Loading branch information...
1 parent b7b0a71 commit db6c512663e11bc8ec76f9ef855190f097d6fc6c @NARKOZ committed Nov 14, 2011
Showing with 28 additions and 12 deletions.
  1. +17 −12 lib/spinach/cli.rb
  2. +11 −0 test/spinach/cli_test.rb
View
@@ -62,18 +62,23 @@ def parse_options
reporter_options = {}
reporter_options[:backtrace] = false
- OptionParser.new do |opts|
- opts.on('-b', '--backtrace', 'Show backtrace of errors') do |v|
- reporter_options[:backtrace] = v
- end
- opts.on('-g', '--generate', 'Auto-generate the feeature steps files') do |v|
- Spinach::Generators.bind
- end
- opts.on_tail('--version', 'Show version') do
- puts Spinach::VERSION
- exit
- end
- end.parse!(@args)
+ begin
+ OptionParser.new do |opts|
+ opts.on('-b', '--backtrace', 'Show backtrace of errors') do |v|
+ reporter_options[:backtrace] = v
+ end
+ opts.on('-g', '--generate', 'Auto-generate the feeature steps files') do |v|
+ Spinach::Generators.bind
+ end
+ opts.on_tail('--version', 'Show version') do
+ puts Spinach::VERSION
+ exit
+ end
+ end.parse!(@args)
+ rescue OptionParser::ParseError => e
+ puts e.message.capitalize
+ exit 1
+ end
{reporter: reporter_options}
end
View
@@ -40,6 +40,17 @@
end
end
end
+
+ describe 'undefined option' do
+ %w{-lorem --ipsum}.each do |opt|
+ it 'exits and outputs error message with #{opt}' do
+ cli = Spinach::Cli.new([opt])
+ cli.expects(:exit)
+ cli.expects(:puts).with("Invalid option: #{opt}")
+ options = cli.options
+ end
+ end
+ end
end
describe '#init_reporter' do

0 comments on commit db6c512

Please sign in to comment.