Sha256: c7eac5b3981d64724818624ea74a04dc8a51cbe26726a7b2c1285be38e2521b6

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::PresenceValidator.new }
  let(:errors)    { Hash.new }

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

      errors.should be_empty
    end

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

      errors.should be_empty
    end

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

      errors.should be_empty
    end

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

      errors.should_not be_empty
      errors.should eq({ key: 'is required' })
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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