File: null_object_spec.rb

package info (click to toggle)
ruby-twitter 7.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,840 kB
  • sloc: ruby: 10,919; makefile: 6
file content (130 lines) | stat: -rw-r--r-- 2,928 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
require 'helper'

describe Twitter::NullObject do
  describe '#!' do
    it 'returns true' do
      expect(!subject).to be true
    end
  end

  describe '#respond_to?' do
    it 'returns true for any method' do
      expect(subject).to respond_to(:missing?)
    end
  end

  describe '#respond_to?' do
    it 'returns true for any method' do
      expect(subject).to respond_to(:missing?)
    end
  end

  describe '#instance_of?' do
    it 'returns true for Twitter::NullObject' do
      expect(subject).to be_instance_of(Twitter::NullObject)
    end
    it 'returns false for other classes' do
      expect(subject).not_to be_instance_of(String)
    end
  end

  describe '#kind_of?' do
    it 'returns true for Twitter::NullObject' do
      expect(subject).to be_a Twitter::NullObject
    end
    it 'returns true for module ancestors' do
      expect(subject).to be_a Comparable
    end
    it 'returns true for class ancestors' do
      expect(subject).to be_a Naught::BasicObject
    end
    it 'returns false for non-ancestors' do
      expect(subject).not_to be_a String
    end
  end

  describe '#<=>' do
    it 'sorts before non-null objects' do
      expect(subject <=> 1).to eq(-1)
    end
    it 'is equal to other Twitter::NullObjects' do
      null_object1 = Twitter::NullObject.new
      null_object2 = Twitter::NullObject.new
      expect(null_object1 <=> null_object2).to eq(0)
    end
  end

  describe '#nil?' do
    it 'returns true' do
      expect(subject.nil?).to be true
    end
  end

  describe '#as_json' do
    it "returns 'null'" do
      expect(subject.as_json).to eq('null')
    end
  end

  describe '#to_json' do
    it 'returns JSON' do
      expect({'null_object' => subject}.to_json).to eq('{"null_object":null}')
    end
  end

  describe 'black hole' do
    it 'returns self for missing methods' do
      expect(subject.missing).to eq(subject)
    end
  end

  describe 'explicit conversions' do
    describe '#to_a' do
      it 'returns an empty array' do
        expect(subject.to_a).to be_empty
      end
    end
    describe '#to_s' do
      it 'returns an empty string' do
        expect(subject.to_s).to be_empty
      end
    end
  end

  describe 'implicit conversions' do
    describe '#to_ary' do
      it 'returns an empty array' do
        expect(subject.to_ary).to be_empty
      end
    end
    describe '#to_str' do
      it 'returns an empty string' do
        expect(subject.to_str).to be_empty
      end
    end
  end

  describe 'predicates' do
    it 'return false for missing methods' do
      expect(subject).not_to be_missing
    end
  end

  describe '#presence' do
    it 'returns nil' do
      expect(subject.presence).to eq nil
    end
  end

  describe '#blank?' do
    it 'returns true' do
      expect(subject.blank?).to eq true
    end
  end

  describe '#present?' do
    it 'returns false' do
      expect(subject.present?).to eq false
    end
  end
end