Sha256: 3745c9d7372fca58ca299a18f83cbdac13208090fb96bea797fa33efa2002e03

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require 'spec_helper'

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

  describe '#should_validate?' do
    it 'should validate the name "required"' do
      expect(validator.should_validate?('required')).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 a string with true' do
      validator.validate(:key, 'test', {}, errors)

      expect(errors).to be_empty
    end

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

      expect(errors).to be_empty
    end

    it 'should validate a time with true' do
      validator.validate(:key, Time.now, {}, errors)

      expect(errors).to be_empty
    end

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

      expect(errors).not_to be_empty
      expect(errors).to eq({ key: 'is required' })
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hash_validator-0.4.0 spec/validators/presence_spec.rb