Sha256: 939e781ab3c66411f78915ff45aa779d30253de8f99f0b146da989612fea19db

Contents?: true

Size: 1.15 KB

Versions: 9

Compression:

Stored size: 1.15 KB

Contents

require 'spec_helper'

describe HashValidator::Validator::Base do
  let(:validator) { HashValidator::Validator::EmailValidator.new }
  let(:errors)    { Hash.new }

  describe '#should_validate?' do
    it 'should validate the name "email"' do
      expect(validator.should_validate?('email')).to eq true
    end

    it 'should not validate other names' do
      expect(validator.should_validate?('string')).to eq false
      expect(validator.should_validate?('array')).to eq false
      expect(validator.should_validate?(nil)).to eq false
    end
  end

  describe '#validate' do
    it 'should validate an email with true' do
      validator.validate(:key, "johndoe@gmail.com", {}, errors)

      expect(errors).to be_empty
    end

    it 'should validate a string without an @ symbol with false' do
      validator.validate(:key, 'test', {}, errors)

      expect(errors).not_to be_empty
      expect(errors).to eq({ key: 'is not a valid email' })
    end

    it 'should validate a number with false' do
      validator.validate(:key, 123, {}, errors)

      expect(errors).not_to be_empty
      expect(errors).to eq({ key: 'is not a valid email' })
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hash_validator-1.1.1 spec/validators/email_spec.rb
hash_validator-1.1.0 spec/validators/email_spec.rb
hash_validator-1.0.0 spec/validators/email_spec.rb
hash_validator-0.8.0 spec/validators/email_spec.rb
hash_validator-0.7.1 spec/validators/email_spec.rb
hash_validator-0.7.0 spec/validators/email_spec.rb
hash_validator-0.6.0 spec/validators/email_spec.rb
hash_validator-0.5.0 spec/validators/email_spec.rb
hash_validator-0.4.0 spec/validators/email_spec.rb