Sha256: 7687a14cf9e6938912363cdd6bf08ae51d4558f7fa06f8e8d248695814119fd3
Contents?: true
Size: 1.94 KB
Versions: 5
Compression:
Stored size: 1.94 KB
Contents
require 'spec_helper' describe OptParseValidator::OptURI do subject(:opt) { described_class.new(['-u', '--uri URI'], attrs) } let(:attrs) { {} } describe '#new, #allowed_protocols' do context 'when no attrs supplied' do its(:allowed_protocols) { should be_empty } its(:default_protocol) { should be nil } end context 'when only one protocol supplied' do let(:attrs) { { protocols: 'http' } } it 'sets it' do opt.allowed_protocols << 'ftp' expect(opt.allowed_protocols).to eq %w(http ftp) end end context 'when multiple protocols are given' do let(:attrs) { { protocols: %w(ftp https) } } it 'sets them' do expect(opt.allowed_protocols).to eq attrs[:protocols] end end end describe '#validate' do context 'when allowed_protocols is empty' do it 'accepts all protocols' do %w(http ftp file).each do |p| expected = "#{p}://testing" expect(opt.validate(expected)).to eq expected end end end context 'when allowed_protocols is set' do let(:attrs) { { protocols: %w(https) } } it 'raises an error if the protocol is not allowed' do expect { opt.validate('ftp://ishouldnotbethere') } .to raise_error(Addressable::URI::InvalidURIError) end it 'returns the uri string if valid' do expected = 'https://example.com/' expect(opt.validate(expected)).to eq expected end end context 'when default_protocol' do let(:attrs) { { default_protocol: 'ftp' } } context 'when the argument already contains a protocol' do it 'does not add the default protocol' do expect(opt.validate('http://ex.lo')).to eq 'http://ex.lo' end end context 'when no protocol given in the argument' do it 'adds it' do expect(opt.validate('ex.lo')).to eq 'ftp://ex.lo' end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems