Skip to content

Commit

Permalink
Add more tests for unrecognized options in yard commands
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal committed May 21, 2011
1 parent 08018d1 commit 4531df0
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions spec/cli/command_spec.rb
Expand Up @@ -5,27 +5,32 @@
describe '#parse_options' do
before do
@options = OptionParser.new
@saw_foo = false
@options.on('--foo') { @saw_foo = true }
end

def parse(*args)
CLI::Command.new.send(:parse_options, @options, args)
args
end

it "should skip unrecognized options but continue to next option" do
log.should_receive(:warn).with(/Unrecognized.*--list/)
log.should_receive(:warn).with(/Unrecognized.*--list2/)
saw_foo = false
@options.on('--foo') { saw_foo = true }
parse('--list', '--list2', '--foo')
saw_foo.should be_true
@saw_foo.should be_true
end

it "should skip unrecognized options and any extra non-option arg that follows" do
log.should_receive(:warn).with(/Unrecognized.*--list/)
saw_foo = false
@options.on('--foo') { saw_foo = true }
parse('--list', 'foo', '--foo')
saw_foo.should be_true
@saw_foo.should be_true
end

it "should stop retrying to parse at non-switch argument" do
log.should_receive(:warn).with(/Unrecognized.*--list/)
args = parse('--list', 'foo', 'foo', 'foo')
args.should == %w(foo foo)
end
end
end

0 comments on commit 4531df0

Please sign in to comment.