Sha256: fe029f0d2408dcd290026cf1570537e57de4f3db631422497600094567628ebb

Contents?: true

Size: 1.25 KB

Versions: 8

Compression:

Stored size: 1.25 KB

Contents

require 'spec_helper'

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

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

      expect(errors).to be_empty
    end

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

      expect(errors).to be_empty
    end

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

      expect(errors).not_to be_empty
      expect(errors).to eq({ key: 'boolean required' })
    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: 'boolean required' })
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

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