File: blank_spec.rb

package info (click to toggle)
libextlib-ruby 0.9.13-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 532 kB
  • ctags: 487
  • sloc: ruby: 7,120; makefile: 3
file content (85 lines) | stat: -rw-r--r-- 1,629 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))

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