Skip to content

Commit

Permalink
handle invalid options
Browse files Browse the repository at this point in the history
  • Loading branch information
NARKOZ committed Nov 14, 2011
1 parent b7b0a71 commit db6c512
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
29 changes: 17 additions & 12 deletions lib/spinach/cli.rb
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/spinach/cli_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit db6c512

Please sign in to comment.