rainbow 2.2.1 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,149 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow'
3
-
4
- describe 'Rainbow() wrapper' do
5
-
6
- before do
7
- Rainbow.enabled = true
8
- end
9
-
10
- it 'allows foreground coloring by color number' do
11
- result = Rainbow('hello').foreground(5)
12
- expect(result).to eq("\e[35mhello\e[0m")
13
- end
14
-
15
- it 'allows foreground coloring by color name' do
16
- result = Rainbow('hello').foreground(:red)
17
- expect(result).to eq("\e[31mhello\e[0m")
18
- end
19
-
20
- it 'allows foreground coloring directly by ANSI method name' do
21
- result = Rainbow('hello').red
22
- expect(result).to eq("\e[31mhello\e[0m")
23
- end
24
-
25
- it 'allows foreground coloring directly by X11 method name' do
26
- result = Rainbow('hello').midnightblue
27
- expect(result).to eq("\e[38;5;18mhello\e[0m")
28
- end
29
-
30
- it 'allows foreground coloring by ANSI color name (color alias)' do
31
- result = Rainbow('hello').color(:red)
32
- expect(result).to eq("\e[31mhello\e[0m")
33
- end
34
-
35
- it 'allows foreground coloring by color name (colour alias)' do
36
- result = Rainbow('hello').colour(:red)
37
- expect(result).to eq("\e[31mhello\e[0m")
38
- end
39
-
40
- it 'allows foreground coloring by X11 color name' do
41
- result = Rainbow('hello').foreground(:midnightblue)
42
- expect(result).to eq("\e[38;5;18mhello\e[0m")
43
- end
44
-
45
- it 'allows foreground coloring by color rgb' do
46
- result = Rainbow('hello').foreground(255, 128, 64)
47
- expect(result).to eq("\e[38;5;215mhello\e[0m")
48
- end
49
-
50
- it 'allows foreground coloring by color rgb (hex string)' do
51
- result = Rainbow('hello').foreground('ff8040')
52
- expect(result).to eq("\e[38;5;215mhello\e[0m")
53
- end
54
-
55
- it 'allows background coloring by color number' do
56
- result = Rainbow('hello').background(3)
57
- expect(result).to eq("\e[43mhello\e[0m")
58
- end
59
-
60
- it 'allows background coloring by ANSI color name' do
61
- result = Rainbow('hello').background(:green)
62
- expect(result).to eq("\e[42mhello\e[0m")
63
- end
64
-
65
- it 'allows background coloring by X11 color name' do
66
- result = Rainbow('hello').background(:midnightblue)
67
- expect(result).to eq("\e[48;5;18mhello\e[0m")
68
- end
69
-
70
- it 'allows background coloring by color rgb' do
71
- result = Rainbow('hello').background(255, 128, 64)
72
- expect(result).to eq("\e[48;5;215mhello\e[0m")
73
- end
74
-
75
- it 'allows making text bright' do
76
- result = Rainbow('hello').bright
77
- expect(result).to eq("\e[1mhello\e[0m")
78
- end
79
-
80
- it 'allows making text italic' do
81
- result = Rainbow('hello').italic
82
- expect(result).to eq("\e[3mhello\e[0m")
83
- end
84
-
85
- it 'allows making text underlined' do
86
- result = Rainbow('hello').underline
87
- expect(result).to eq("\e[4mhello\e[0m")
88
- end
89
-
90
- it 'allows making text blinking' do
91
- result = Rainbow('hello').blink
92
- expect(result).to eq("\e[5mhello\e[0m")
93
- end
94
-
95
- it 'allows making text inversed' do
96
- result = Rainbow('hello').inverse
97
- expect(result).to eq("\e[7mhello\e[0m")
98
- end
99
-
100
- it 'allows making text hidden' do
101
- result = Rainbow('hello').hide
102
- expect(result).to eq("\e[8mhello\e[0m")
103
- end
104
-
105
- it 'allows resetting all the attributes' do
106
- result = Rainbow('hello').reset
107
- expect(result).to eq("\e[0mhello\e[0m")
108
- end
109
-
110
- it 'allows chaining' do
111
- result = Rainbow('hello').
112
- foreground(:red).
113
- bright.
114
- italic.
115
- background('#ff8040').
116
- underline.
117
- color(:blue).
118
- blink.
119
- inverse.
120
- hide
121
-
122
- expect(result).to eq(
123
- "\e[31m\e[1m\e[3m\e[48;5;215m\e[4m\e[34m\e[5m\e[7m\e[8mhello\e[0m"
124
- )
125
- end
126
-
127
- context "when Rainbow is disabled" do
128
-
129
- before do
130
- Rainbow.enabled = false
131
- end
132
-
133
- it "allows chaining but doesn't wrap with escape codes" do
134
- result = Rainbow('hello').
135
- foreground(:red).
136
- bright.
137
- italic.
138
- background('#ff8040').
139
- underline.
140
- color(:blue).
141
- blink.
142
- inverse.
143
- hide
144
-
145
- expect(result).to eq('hello')
146
- end
147
- end
148
-
149
- end
@@ -1,80 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow/ext/string'
3
-
4
- describe 'String mixin' do
5
-
6
- before do
7
- Rainbow.enabled = true
8
- end
9
-
10
- it 'proxies foreground to Rainbow().foreground' do
11
- expect('hello'.foreground(:red)).to eq(Rainbow('hello').foreground(:red))
12
- end
13
-
14
- it 'proxies color to Rainbow().color' do
15
- expect('hello'.color(:red)).to eq(Rainbow('hello').color(:red))
16
- end
17
-
18
- it 'proxies x11 color to Rainbow().color' do
19
- expect('hello'.color(:midnightblue)).to eq(Rainbow('hello').color(:midnightblue))
20
- end
21
-
22
- it 'proxies colour to Rainbow().colour' do
23
- expect('hello'.colour(:red)).to eq(Rainbow('hello').colour(:red))
24
- end
25
-
26
- it 'proxies background to Rainbow().background' do
27
- expect('hello'.background(:red)).to eq(Rainbow('hello').background(:red))
28
- end
29
-
30
- it 'proxies bright to Rainbow().bright' do
31
- expect('hello'.bright).to eq(Rainbow('hello').bright)
32
- end
33
-
34
- it 'proxies italic to Rainbow().italic' do
35
- expect('hello'.italic).to eq(Rainbow('hello').italic)
36
- end
37
-
38
- it 'proxies underline to Rainbow().underline' do
39
- expect('hello'.underline).to eq(Rainbow('hello').underline)
40
- end
41
-
42
- it 'proxies blink to Rainbow().blink' do
43
- expect('hello'.blink).to eq(Rainbow('hello').blink)
44
- end
45
-
46
- it 'proxies inverse to Rainbow().inverse' do
47
- expect('hello'.inverse).to eq(Rainbow('hello').inverse)
48
- end
49
-
50
- it 'proxies hide to Rainbow().hide' do
51
- expect('hello'.hide).to eq(Rainbow('hello').hide)
52
- end
53
-
54
- it 'proxies reset to Rainbow().reset' do
55
- expect('hello'.reset).to eq(Rainbow('hello').reset)
56
- end
57
-
58
- context "when Rainbow is disabled" do
59
-
60
- before do
61
- Rainbow.enabled = false
62
- end
63
-
64
- it "allows chaining but doesn't wrap with escape codes" do
65
- result = 'hello'.
66
- foreground(:red).
67
- bright.
68
- italic.
69
- background('#ff8040').
70
- underline.
71
- color(:blue).
72
- blink.
73
- inverse.
74
- hide
75
-
76
- expect(result).to eq('hello')
77
- end
78
- end
79
-
80
- end
data/spec/spec_helper.rb DELETED
@@ -1,6 +0,0 @@
1
- if ENV["CI"] && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby")
2
- require 'coveralls'
3
- Coveralls.wear!
4
- end
5
-
6
- Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |file| require file }
@@ -1,9 +0,0 @@
1
- shared_examples_for "presenter with shortcut color methods" do
2
- [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, :aqua].each do |name|
3
- describe "##{name}" do
4
- subject { presenter.public_send(name) }
5
-
6
- it { should eq(presenter.color(name)) }
7
- end
8
- end
9
- end
@@ -1,301 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow/color'
3
-
4
- module Rainbow
5
- describe Color do
6
- describe '.build' do
7
-
8
- subject { described_class.build(ground, values) }
9
-
10
- let(:ground) { :foreground }
11
-
12
- context "when single fixnum given" do
13
- let(:values) { [1] }
14
-
15
- it { should be_instance_of(Color::Indexed) }
16
-
17
- specify { expect(subject.ground).to eq(ground) }
18
- specify { expect(subject.num).to eq(1) }
19
- end
20
-
21
- context "when single ansi symbol given" do
22
- let(:values) { [:red] }
23
-
24
- it { should be_instance_of(Color::Named) }
25
-
26
- specify { expect(subject.ground).to eq(ground) }
27
- specify { expect(subject.num).to eq(1) }
28
- end
29
-
30
- context "when single x11 symbol given" do
31
- let(:values) { [:midnightblue] }
32
-
33
- it { should be_instance_of(Color::X11Named) }
34
-
35
- specify { expect(subject.ground).to eq(ground) }
36
- specify { expect(subject.r).to eq(25) }
37
- specify { expect(subject.g).to eq(25) }
38
- specify { expect(subject.b).to eq(112) }
39
- end
40
-
41
- context "when single string given" do
42
- let(:values) { ['#deadcc'] }
43
-
44
- it { should be_instance_of(Color::RGB) }
45
-
46
- specify { expect(subject.ground).to eq(ground) }
47
- specify { expect(subject.r).to eq(222) }
48
- specify { expect(subject.g).to eq(173) }
49
- specify { expect(subject.b).to eq(204) }
50
- end
51
-
52
- context "when 2 elements" do
53
- let(:values) { [1, 2] }
54
-
55
- it 'raises ArgumentError' do
56
- expect { subject }.to raise_error(ArgumentError)
57
- end
58
- end
59
-
60
- context "when 3 elements given" do
61
- let(:values) { [1, 2, 3] }
62
-
63
- it { should be_instance_of(Color::RGB) }
64
-
65
- specify { expect(subject.ground).to eq(ground) }
66
- specify { expect(subject.r).to eq(1) }
67
- specify { expect(subject.g).to eq(2) }
68
- specify { expect(subject.b).to eq(3) }
69
- end
70
-
71
- context "when 4 elements" do
72
- let(:values) { [1, 2, 3, 4] }
73
-
74
- it 'raises ArgumentError' do
75
- expect { subject }.to raise_error(ArgumentError)
76
- end
77
- end
78
-
79
- end
80
- end
81
-
82
- describe Color::Indexed do
83
- let(:color) { described_class.new(ground, 5) }
84
-
85
- describe '#codes' do
86
- subject { color.codes }
87
-
88
- context "when ground is :foreground" do
89
- let(:ground) { :foreground }
90
-
91
- it { should eq([35]) }
92
- end
93
-
94
- context "when ground is :background" do
95
- let(:ground) { :background }
96
-
97
- it { should eq([45]) }
98
- end
99
- end
100
- end
101
-
102
- describe Color::Named do
103
- let(:color) { described_class.new(ground, name) }
104
-
105
- describe '#codes' do
106
- subject { color.codes }
107
-
108
- context "when ground is :foreground" do
109
- let(:ground) { :foreground }
110
-
111
- context "and name is :black" do
112
- let(:name) { :black }
113
-
114
- it { should eq([30]) }
115
- end
116
-
117
- context "and name is :red" do
118
- let(:name) { :red }
119
-
120
- it { should eq([31]) }
121
- end
122
-
123
- context "and name is :green" do
124
- let(:name) { :green }
125
-
126
- it { should eq([32]) }
127
- end
128
-
129
- context "and name is :yellow" do
130
- let(:name) { :yellow }
131
-
132
- it { should eq([33]) }
133
- end
134
-
135
- context "and name is :blue" do
136
- let(:name) { :blue }
137
-
138
- it { should eq([34]) }
139
- end
140
-
141
- context "and name is :magenta" do
142
- let(:name) { :magenta }
143
-
144
- it { should eq([35]) }
145
- end
146
-
147
- context "and name is :cyan" do
148
- let(:name) { :cyan }
149
-
150
- it { should eq([36]) }
151
- end
152
-
153
- context "and name is :white" do
154
- let(:name) { :white }
155
-
156
- it { should eq([37]) }
157
- end
158
-
159
- context "and name is invalid" do
160
- let(:name) { :foo }
161
-
162
- it 'raises ArgumentError' do
163
- expect { subject }.to raise_error(ArgumentError)
164
- end
165
- end
166
- end
167
-
168
- context "when ground is :background" do
169
- let(:ground) { :background }
170
-
171
- context "and name is :black" do
172
- let(:name) { :black }
173
-
174
- it { should eq([40]) }
175
- end
176
-
177
- context "and name is :red" do
178
- let(:name) { :red }
179
-
180
- it { should eq([41]) }
181
- end
182
-
183
- context "and name is :green" do
184
- let(:name) { :green }
185
-
186
- it { should eq([42]) }
187
- end
188
-
189
- context "and name is :yellow" do
190
- let(:name) { :yellow }
191
-
192
- it { should eq([43]) }
193
- end
194
-
195
- context "and name is :blue" do
196
- let(:name) { :blue }
197
-
198
- it { should eq([44]) }
199
- end
200
-
201
- context "and name is :magenta" do
202
- let(:name) { :magenta }
203
-
204
- it { should eq([45]) }
205
- end
206
-
207
- context "and name is :cyan" do
208
- let(:name) { :cyan }
209
-
210
- it { should eq([46]) }
211
- end
212
-
213
- context "and name is :white" do
214
- let(:name) { :white }
215
-
216
- it { should eq([47]) }
217
- end
218
-
219
- context "and name is invalid" do
220
- let(:name) { :foo }
221
-
222
- it 'raises ArgumentError' do
223
- expect { subject }.to raise_error(ArgumentError)
224
- end
225
- end
226
- end
227
- end
228
- end
229
-
230
- describe Color::RGB do
231
- let(:color) { described_class.new(ground, r, g, b) }
232
-
233
- describe '#codes' do
234
- subject { color.codes }
235
-
236
- let(:ground) { :foreground }
237
- let(:r) { 0 }
238
- let(:g) { 128 }
239
- let(:b) { 255 }
240
-
241
- context "when ground is :foreground" do
242
- let(:ground) { :foreground }
243
-
244
- it { should eq([38, 5, 39]) }
245
- end
246
-
247
- context "when ground is :background" do
248
- let(:ground) { :background }
249
-
250
- it { should eq([48, 5, 39]) }
251
- end
252
-
253
- context "when a component is lower than 0" do
254
- let(:r) { -1 }
255
-
256
- it 'raises ArgumentError' do
257
- expect { subject }.to raise_error(ArgumentError)
258
- end
259
- end
260
-
261
- context "when a component is greater than 255" do
262
- let(:b) { 256 }
263
-
264
- it 'raises ArgumentError' do
265
- expect { subject }.to raise_error(ArgumentError)
266
- end
267
- end
268
-
269
- end
270
- end
271
-
272
- describe Color::X11Named do
273
- let(:color) { described_class.new(ground, name) }
274
-
275
- describe '#codes' do
276
- subject { color.codes }
277
-
278
- context "when ground is :foreground" do
279
- let(:name) { :midnightblue }
280
- let(:ground) { :foreground }
281
- it { should eq([38, 5, 18]) }
282
- end
283
-
284
- context "when ground is :background" do
285
- let(:name) { :midnightblue }
286
- let(:ground) { :background }
287
- it { should eq([48, 5, 18]) }
288
- end
289
-
290
- context "when name is invalid" do
291
- let(:name) { :foo }
292
- let(:ground) { :background }
293
- it 'raises ArgumentError' do
294
- expect { subject }.to raise_error(ArgumentError)
295
- end
296
- end
297
-
298
- end
299
- end
300
-
301
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow'
3
-
4
- describe Sickill::Rainbow do
5
-
6
- describe '.enabled' do
7
- before do
8
- ::Rainbow.enabled = :nope
9
- end
10
-
11
- it 'returns ::Rainbow.enabled' do
12
- expect(Sickill::Rainbow.enabled).to eq(:nope)
13
- end
14
- end
15
-
16
- describe '.enabled=' do
17
- before do
18
- allow(STDERR).to receive(:puts)
19
- Sickill::Rainbow.enabled = :yep
20
- end
21
-
22
- it 'sets ::Rainbow.enabled=' do
23
- expect(::Rainbow.enabled).to eq(:yep)
24
- end
25
-
26
- it 'prints the deprecation notice' do
27
- expect(STDERR).to have_received(:puts)
28
- end
29
- end
30
-
31
- end
@@ -1,93 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow/null_presenter'
3
-
4
- module Rainbow
5
- describe NullPresenter do
6
-
7
- let(:presenter) { described_class.new('hello') }
8
-
9
- shared_examples_for "rainbow null string method" do
10
- it "doesn't wrap the text with any sgr sequence" do
11
- expect(subject).to eq('hello')
12
- end
13
-
14
- it "returns an instance of Rainbow::NullPresenter" do
15
- expect(subject).to be_kind_of(Rainbow::NullPresenter)
16
- end
17
- end
18
-
19
- describe '#color' do
20
- subject { presenter.color(:arg1, 'arg2') }
21
-
22
- it_behaves_like "rainbow null string method"
23
- end
24
-
25
- describe '#foreground' do
26
- subject { presenter.foreground(:arg1, 'arg2') }
27
-
28
- it_behaves_like "rainbow null string method"
29
- end
30
-
31
- describe '#fg' do
32
- subject { presenter.fg(:arg1, 'arg2') }
33
-
34
- it_behaves_like "rainbow null string method"
35
- end
36
-
37
- describe '#background' do
38
- subject { presenter.background(:arg1, 'arg2') }
39
-
40
- it_behaves_like "rainbow null string method"
41
- end
42
-
43
- describe '#bg' do
44
- subject { presenter.bg(:arg1, 'arg2') }
45
-
46
- it_behaves_like "rainbow null string method"
47
- end
48
-
49
- describe '#reset' do
50
- subject { presenter.reset }
51
-
52
- it_behaves_like "rainbow null string method"
53
- end
54
-
55
- describe '#bright' do
56
- subject { presenter.bright }
57
-
58
- it_behaves_like "rainbow null string method"
59
- end
60
-
61
- describe '#italic' do
62
- subject { presenter.italic }
63
-
64
- it_behaves_like "rainbow null string method"
65
- end
66
-
67
- describe '#underline' do
68
- subject { presenter.underline }
69
-
70
- it_behaves_like "rainbow null string method"
71
- end
72
-
73
- describe '#blink' do
74
- subject { presenter.blink }
75
-
76
- it_behaves_like "rainbow null string method"
77
- end
78
-
79
- describe '#inverse' do
80
- subject { presenter.inverse }
81
-
82
- it_behaves_like "rainbow null string method"
83
- end
84
-
85
- describe '#hide' do
86
- subject { presenter.hide }
87
-
88
- it_behaves_like "rainbow null string method"
89
- end
90
-
91
- it_behaves_like "presenter with shortcut color methods"
92
- end
93
- end