2012-11-29 20:40:25 +00:00
|
|
|
|
|
|
|
shared_examples_for "an option" do |valid_values, invalid_values|
|
|
|
|
subject do
|
|
|
|
described_class.new("name")
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with valid values" do
|
2012-11-29 22:35:50 +00:00
|
|
|
valid_values.each do |vhash|
|
|
|
|
valid_value = vhash[:value]
|
|
|
|
normalized_value = vhash[:normalized]
|
|
|
|
|
2012-11-29 20:40:25 +00:00
|
|
|
it "should be valid and normalize appropriately: #{valid_value}" do
|
2012-11-29 22:35:50 +00:00
|
|
|
block = Proc.new {
|
|
|
|
subject.normalize(valid_value).should == normalized_value
|
|
|
|
subject.valid?(valid_value).should be_true
|
|
|
|
}
|
|
|
|
if vhash[:pending]
|
|
|
|
pending(vhash[:pending], &block)
|
|
|
|
else
|
|
|
|
block.call
|
|
|
|
end
|
2012-11-29 20:40:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with invalid values" do
|
2012-11-29 22:35:50 +00:00
|
|
|
invalid_values.each do |vhash|
|
|
|
|
invalid_value = vhash[:value]
|
2012-11-29 20:40:25 +00:00
|
|
|
it "should not be valid: #{invalid_value}" do
|
2012-11-29 22:35:50 +00:00
|
|
|
block = Proc.new { subject.valid?(invalid_value).should be_false }
|
|
|
|
if vhash[:pending]
|
|
|
|
pending(vhash[:pending], &block)
|
|
|
|
else
|
|
|
|
block.call
|
|
|
|
end
|
2012-11-29 20:40:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|