Sha256: 07f42cbaef1b963fe9b93fb83eec62d5916390d4a3e827fad54162557603bae2

Contents?: true

Size: 922 Bytes

Versions: 5

Compression:

Stored size: 922 Bytes

Contents

require 'spec_helper'

describe 'Regular expression validator' do
  describe 'Accepting RegExps in validations' do
    it 'should accept a regexp' do
      validate({}, { foo: // })
    end
  end

  describe '#validate' do
    let(:validations) {{ string: /^foo$/ }}

    it 'should validate true when the value is foo' do
      expect(validate({ string: 'foo' }, validations).valid?).to eq true
    end

    it 'should validate false when the value is not foo' do
      expect(validate({ string: 'bar' }, validations).valid?).to eq false
      expect(validate({ string: ' foo' }, validations).valid?).to eq false
      expect(validate({ string: 'foo ' }, validations).valid?).to eq false
      expect(validate({ string: nil }, validations).valid?).to eq false
      expect(validate({ string: 0 }, validations).valid?).to eq false
      expect(validate({ string: true }, validations).valid?).to eq false
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hash_validator-1.1.0 spec/validators/regexp_spec.rb
hash_validator-1.0.0 spec/validators/regexp_spec.rb
hash_validator-0.8.0 spec/validators/regexp_spec.rb
hash_validator-0.7.1 spec/validators/regexp_spec.rb
hash_validator-0.7.0 spec/validators/regexp_spec.rb