Sha256: 03235c5be2901a7dcd660f77c67e4f7f237dcf38885e62a23d42c04f175717d1

Contents?: true

Size: 1.87 KB

Versions: 7

Compression:

Stored size: 1.87 KB

Contents

require 'spec_helper'
require 'gorillib/object/blank'

describe 'object/blank', :simple_spec => true do
  describe Object do
    it 'should provide blank?' do
      Object.new.should respond_to(:blank?)
    end

    it 'should be blank if it is nil' do
      object = Object.new
      class << object
        def nil?; true end
      end
      object.should be_blank
    end

    it 'should be blank if it is empty' do
      {}.should be_blank
      [].should be_blank
    end

    it 'should not be blank if not nil or empty' do
      Object.new.should_not be_blank
      [nil].should_not be_blank
      { nil => 0 }.should_not be_blank
    end

    it 'should be present if not blank' do
      nil.should_not be_present
      "blarg".should be_present
    end
  end

  describe Numeric do
    it 'should provide blank?' do
      1.should respond_to(:blank?)
    end

    it 'should never be blank' do
      1.should_not be_blank
    end
  end

  describe NilClass do
    it 'should provide blank?' do
      nil.should respond_to(:blank?)
    end

    it 'should always be blank' do
      nil.should be_blank
    end
  end

  describe TrueClass do
    it 'should provide blank?' do
      true.should respond_to(:blank?)
    end

    it 'should never be blank' do
      true.should_not be_blank
    end
  end

  describe FalseClass do
    it 'should provide blank?' do
      false.should respond_to(:blank?)
    end

    it 'should always be blank' do
      false.should be_blank
    end
  end

  describe String do
    it 'should provide blank?' do
      'string'.should respond_to(:blank?)
    end

    it 'should be blank if empty' do
      ''.should be_blank
    end

    it 'should be blank if it only contains whitespace' do
      ' '.should be_blank
      " \r \n \t ".should be_blank
    end

    it 'should not be blank if it contains non-whitespace' do
      ' a '.should_not be_blank
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gorillib-0.6.0 spec/gorillib/object/blank_spec.rb
gorillib-0.5.2 spec/gorillib/object/blank_spec.rb
gorillib-0.5.0 spec/gorillib/object/blank_spec.rb
gorillib-0.4.2 spec/gorillib/object/blank_spec.rb
gorillib-0.4.2pre spec/gorillib/object/blank_spec.rb
gorillib-0.4.0pre spec/gorillib/object/blank_spec.rb
gorillib-0.4.1pre spec/gorillib/object/blank_spec.rb