Sha256: 27f18c6ff819fb57f178f61a7fb20a6154f80a1b495813272458bee745d8abe8
Contents?: true
Size: 1.66 KB
Versions: 3
Compression:
Stored size: 1.66 KB
Contents
describe Compel::Validation do context 'Param validation' do context 'required' do it 'should validate without errors' do errors = Compel::Validation.validate(123, { required: true }) expect(errors.empty?).to eq(true) end it 'should validate with error' do errors = Compel::Validation.validate(nil, { required: true }) expect(errors.empty?).to eq(false) expect(errors).to eq(['is required']) end end context 'length' do it 'should validate without errors' do errors = Compel::Validation.validate(123, { length: 3 }) expect(errors.empty?).to eq(true) end end context 'in, within, range' do def expect_be_in_within_range(range, value) [:in, :within].each do |key| errors = Compel::Validation.validate(value, { key => range }) yield errors end end it 'should validate without errors' do expect_be_in_within_range(['PT', 'UK'], 'PT') do |errors| expect(errors.empty?).to eq(true) end end it 'should validate with errors' do expect_be_in_within_range(['PT', 'UK'], 'US') do |errors| expect(errors).to eq(['must be within ["PT", "UK"]']) end end context 'range' do it 'should validate without errors' do errors = Compel::Validation.validate(2, range: (1..3)) expect(errors.empty?).to eq(true) end it 'should validate with errors' do errors = Compel::Validation.validate(4, range: (1..3)) expect(errors).to eq(['must be within 1..3']) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
compel-0.1.3 | spec/compel/validation_spec.rb |
compel-0.1.2 | spec/compel/validation_spec.rb |
compel-0.1.1 | spec/compel/validation_spec.rb |