Sha256: da0e4c3dbe1b14ef8d212c2a9d9a0cd5df5f401b922249d42212a0c3e428e0c0

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 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
      validator.should_validate?('email').should be_true
    end

    it 'should not validate other names' do
      validator.should_validate?('string').should be_false
      validator.should_validate?('array').should  be_false
      validator.should_validate?(nil).should      be_false
    end
  end

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

      errors.should be_empty
    end

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

      errors.should_not be_empty
      errors.should eq({ key: 'is not a valid email' })
    end

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

      errors.should_not be_empty
      errors.should eq({ key: 'is not a valid email' })
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hash_validator-0.3.0 spec/validators/email_spec.rb
hash_validator-0.2.7 spec/validators/email_spec.rb
hash_validator-0.2.6 spec/validators/email_spec.rb
hash_validator-0.2.5 spec/validators/email_spec.rb
hash_validator-0.2.4 spec/validators/email_spec.rb
hash_validator-0.2.3 spec/validators/email_spec.rb
hash_validator-0.2.2 spec/validators/email_spec.rb
hash_validator-0.2.1 spec/validators/email_spec.rb