Sha256: c88d814397e5369ccb9b695b22922bb4f104ecb649ee15235c699d14c890644d

Contents?: true

Size: 1.1 KB

Versions: 14

Compression:

Stored size: 1.1 KB

Contents

class EmptyTrue
  def empty?() true; end
end

class EmptyFalse
  def empty?() false; end
end

BLANK = [ EmptyTrue.new, nil, false, '', '   ', "  \n\t  \r ", ' ', [], {} ]
NOT   = [ EmptyFalse.new, Object.new, true, 0, 1, 'a', [nil], { nil => 0 } ]

describe "blank" do
  describe "blank?" do
    BLANK.each do |v|
      it "should treat #{v.inspect} as blank" do
        v.should.be.blank
      end
    end
    
    NOT.each do |v|
      it "should treat #{v.inspect} as NOT blank" do
        v.should.not.be.blank
      end
    end
  end

  describe "present?" do
    BLANK.each do |v|
      it "should treat #{v.inspect} as NOT present" do
        v.should.not.be.present
      end
    end
    
    NOT.each do |v|
      it "should treat #{v.inspect} as present" do
        v.should.be.present
      end
    end
  end

  describe "presence" do
    BLANK.each do |v|
      it "should return nil for #{v.inspect}.presence" do
        v.presence.should.be.nil
      end
    end
    
    NOT.each do |v|
      it "should return self for #{v.inspect}.presence" do
        v.presence.should == v
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
motion-support-1.2.1 spec/motion-support/core_ext/object/blank_spec.rb
motion-support-1.1.1 spec/motion-support/core_ext/object/blank_spec.rb
motion-support-1.2.0 spec/motion-support/core_ext/object/blank_spec.rb
motion-support-1.1.0 spec/motion-support/core_ext/object/blank_spec.rb
motion-support-1.0.0 spec/motion-support/core_ext/object/blank_spec.rb
motion-support-0.3.0 spec/motion-support/core_ext/object/blank_spec.rb
motion_blender-support-0.2.8 spec/motion-support/core_ext/object/blank_spec.rb
motion_blender-support-0.2.7 spec/motion-support/core_ext/object/blank_spec.rb
motion-support-0.2.6 spec/motion-support/core_ext/object/blank_spec.rb
motion-support-0.2.5 spec/motion-support/core_ext/object/blank_spec.rb
motion-support-0.2.4 spec/motion-support/core_ext/object/blank_spec.rb
motion-support-0.2.3 spec/motion-support/core_ext/object/blank_spec.rb
motion-support-0.2.2 spec/motion-support/core_ext/object/blank_spec.rb
motion-support-0.2.0 spec/motion-support/core_ext/object/blank_spec.rb