Files
metasploit-gs/spec/support/shared/examples/an_option.rb
T

62 lines
1.5 KiB
Ruby
Raw Normal View History

# -*- coding:binary -*-
2012-11-29 14:40:25 -06:00
2015-12-31 16:56:13 -06:00
RSpec.shared_examples_for "an option" do |valid_values, invalid_values, type|
2012-11-29 14:40:25 -06:00
subject do
described_class.new("name")
end
2013-07-20 16:46:16 -05:00
let(:required) { described_class.new('name', [true, 'A description here'])}
let(:optional) { described_class.new('name', [false, 'A description here'])}
2013-07-20 17:37:39 -05:00
it "should return a type of #{type}" do
2015-10-20 11:30:38 -05:00
expect(subject.type).to eq type
2013-07-20 17:37:39 -05:00
end
2013-07-20 16:46:16 -05:00
context 'when required' do
it 'should not be valid for nil' do
2015-10-20 11:30:38 -05:00
expect(required.valid?(nil)).to eq false
2013-07-20 16:46:16 -05:00
end
end
context 'when not required' do
it 'it should be valid for nil' do
2015-10-20 11:30:38 -05:00
expect(optional.valid?(nil)).to eq true
2013-07-20 16:46:16 -05:00
end
end
2012-11-29 14:40:25 -06:00
context "with valid values" do
valid_values.each do |vhash|
2013-09-30 13:47:53 -05:00
valid_value = vhash[:value]
normalized_value = vhash[:normalized]
2012-11-29 14:40:25 -06:00
it "should be valid and normalize appropriately: #{valid_value}" do
2013-09-30 13:47:53 -05:00
block = Proc.new {
2015-10-20 11:30:38 -05:00
expect(subject.normalize(valid_value)).to eq normalized_value
2015-10-20 14:37:18 -05:00
expect(subject.valid?(valid_value)).to be_truthy
2013-09-30 13:47:53 -05:00
}
2014-08-26 15:17:00 -05:00
if vhash[:skip]
skip(vhash[:skip], &block)
2013-09-30 13:47:53 -05:00
else
block.call
end
2012-11-29 14:40:25 -06:00
end
end
end
context "with invalid values" do
invalid_values.each do |vhash|
2013-09-30 13:47:53 -05:00
invalid_value = vhash[:value]
2012-11-29 14:40:25 -06:00
it "should not be valid: #{invalid_value}" do
2015-10-20 14:37:18 -05:00
block = Proc.new { expect(subject.valid?(invalid_value)).to be_falsey }
2014-08-26 15:17:00 -05:00
if vhash[:skip]
skip(vhash[:skip], &block)
2013-09-30 13:47:53 -05:00
else
block.call
end
2012-11-29 14:40:25 -06:00
end
end
end
end