Sha256: f81078e2d39ac08374ce2777ed05b9195c156ec17776bb474ebbed1db642946b

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

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

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
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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gorillib-0.0.7 spec/blank_spec.rb
gorillib-0.0.6 spec/blank_spec.rb
gorillib-0.0.5 spec/blank_spec.rb