Sha256: 4aa291e5696342cd71079aa36d07b1bbd95cc32b94cd2d7888a6c1d9759b6bfc

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 KB

Contents

require File.expand_path('../../helper', __FILE__)
require File.join(Zen::FIXTURES, 'validation')
require 'fileutils'

describe 'Zen::Validation' do

  it 'Validate the presence of an attribute' do
    object = ValidationObject.new

    should.raise?(Zen::ValidationError) { object.presence }

    # Now validate it with a value
    object.name = 'yorick'

    should.not.raise?(Zen::ValidationError) { object.presence }
  end

  it 'Validate the length of an attribute' do
    object = ValidationObject.new

    should.raise?(Zen::ValidationError) { object.length }

    # Too short
    object.name = 'ab'

    should.raise?(Zen::ValidationError) { object.length }

    # Too long
    object.name = 'abcdef'

    should.raise?(Zen::ValidationError) { object.length }

    # Perfect
    object.name = 'ab3'

    should.not.raise?(Zen::ValidationError) { object.length }
  end

  it 'Validate the format of an attribute' do
    object      = ValidationObject.new
    object.name = 10

    should.raise?(Zen::ValidationError) { object.format }

    object.name = 'hello'

    should.not.raise?(Zen::ValidationError) { object.format }
  end

  it 'Validate a file' do
    object      = ValidationObject.new
    object.file = '/tmp/zen_validation'

    should.raise?(Zen::ValidationError) { object.exists }

    FileUtils.touch('/tmp/zen_validation')

    should.not.raise?(Zen::ValidationError) { object.exists }

    File.unlink('/tmp/zen_validation')
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zen-0.4.3 spec/zen/validation.rb
zen-0.4.2 spec/zen/validation.rb
zen-0.4.1 spec/zen/validation.rb
zen-0.4 spec/zen/validation.rb