Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/support/shared/examples/an_option.rb
Views: 11623
# -*- coding:binary -*-12RSpec.shared_examples_for "an option" do |valid_values, invalid_values, type|3subject do4described_class.new("name")5end67let(:required) { described_class.new('name', [true, 'A description here'])}8let(:optional) { described_class.new('name', [false, 'A description here'])}910it "should return a type of #{type}" do11expect(subject.type).to eq type12end1314context 'when required' do15it 'should not be valid for nil' do16expect(required.valid?(nil)).to eq false17end18end1920context 'when not required' do21it 'it should be valid for nil' do22expect(optional.valid?(nil)).to eq true23end24end2526context "with valid values" do27valid_values.each do |vhash|28valid_value = vhash[:value]29normalized_value = vhash[:normalized]3031it "should be valid and normalize appropriately: #{valid_value}" do32block = Proc.new {33expect(subject.normalize(valid_value)).to eq normalized_value34expect(subject.valid?(valid_value)).to be_truthy35}36if vhash[:skip]37skip(vhash[:skip], &block)38else39block.call40end41end42end43end4445context "with invalid values" do46invalid_values.each do |vhash|47invalid_value = vhash[:value]48it "should not be valid: #{invalid_value}" do49block = Proc.new { expect(subject.valid?(invalid_value)).to be_falsey }50if vhash[:skip]51skip(vhash[:skip], &block)52else53block.call54end55end56end57end5859end60616263