1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
require 'spec_helper'
require 'puppetserver/ca/utils/cli_parsing'
require 'puppetserver/ca/logger'
RSpec.describe Puppetserver::Ca::Utils::CliParsing do
subject { Puppetserver::Ca::Utils::CliParsing }
let(:parser) do
OptionParser.new do |o|
o.on('-f FOO', 'Fizz.')
end
end
let(:args) { %w{blah -b --this non-sense --other=thing random -f} }
describe 'parse_without_raising' do
before do
@consumed_args = args.dup
@all, @not_flags, @malformed_flags, @unknown_flags =
subject.parse_without_raising(parser, @consumed_args)
end
it 'separates out flags called without required arguments' do
expect(@malformed_flags).to eq(['-f'])
end
it 'separates out unknown flags and their arguments' do
expect(@unknown_flags).to eq(['-b', '--this', 'non-sense', '--other=thing'])
end
it 'spearates out non flag parameters' do
expect(@not_flags).to eq(['blah', 'random'])
end
it 'saves items in the order they were passed' do
expect(@all).to eq(args)
end
end
describe 'parse_with_errors' do
it 'returns meaningful errors' do
errors = subject.parse_with_errors(parser, args)
expect(errors).to include(' Missing argument to flag `-f`')
expect(errors).to include(' Unknown flag or argument `--this`')
expect(errors).to include(' Unknown flag or argument `non-sense`')
expect(errors).to include(' Unknown input `blah`')
end
end
end
|