rainbow 3.0.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,110 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow/null_presenter'
3
-
4
- module Rainbow
5
- RSpec.describe NullPresenter do
6
- let(:presenter) { described_class.new('hello') }
7
-
8
- shared_examples_for "rainbow null string method" do
9
- it "doesn't wrap the text with any sgr sequence" do
10
- expect(subject).to eq('hello')
11
- end
12
-
13
- it "returns an instance of Rainbow::NullPresenter" do
14
- expect(subject).to be_kind_of(Rainbow::NullPresenter)
15
- end
16
- end
17
-
18
- describe '#color' do
19
- subject { presenter.color(:arg1, 'arg2') }
20
-
21
- it_behaves_like "rainbow null string method"
22
- end
23
-
24
- describe '#foreground' do
25
- subject { presenter.foreground(:arg1, 'arg2') }
26
-
27
- it_behaves_like "rainbow null string method"
28
- end
29
-
30
- describe '#fg' do
31
- subject { presenter.fg(:arg1, 'arg2') }
32
-
33
- it_behaves_like "rainbow null string method"
34
- end
35
-
36
- describe '#background' do
37
- subject { presenter.background(:arg1, 'arg2') }
38
-
39
- it_behaves_like "rainbow null string method"
40
- end
41
-
42
- describe '#bg' do
43
- subject { presenter.bg(:arg1, 'arg2') }
44
-
45
- it_behaves_like "rainbow null string method"
46
- end
47
-
48
- describe '#reset' do
49
- subject { presenter.reset }
50
-
51
- it_behaves_like "rainbow null string method"
52
- end
53
-
54
- describe '#bright' do
55
- subject { presenter.bright }
56
-
57
- it_behaves_like "rainbow null string method"
58
- end
59
-
60
- describe '#bold' do
61
- subject { presenter.bold }
62
-
63
- it_behaves_like "rainbow null string method"
64
- end
65
-
66
- describe '#faint' do
67
- subject { presenter.faint }
68
-
69
- it_behaves_like "rainbow null string method"
70
- end
71
-
72
- describe '#dark' do
73
- subject { presenter.dark }
74
-
75
- it_behaves_like "rainbow null string method"
76
- end
77
-
78
- describe '#italic' do
79
- subject { presenter.italic }
80
-
81
- it_behaves_like "rainbow null string method"
82
- end
83
-
84
- describe '#underline' do
85
- subject { presenter.underline }
86
-
87
- it_behaves_like "rainbow null string method"
88
- end
89
-
90
- describe '#blink' do
91
- subject { presenter.blink }
92
-
93
- it_behaves_like "rainbow null string method"
94
- end
95
-
96
- describe '#inverse' do
97
- subject { presenter.inverse }
98
-
99
- it_behaves_like "rainbow null string method"
100
- end
101
-
102
- describe '#hide' do
103
- subject { presenter.hide }
104
-
105
- it_behaves_like "rainbow null string method"
106
- end
107
-
108
- it_behaves_like "presenter with shortcut color methods"
109
- end
110
- end
@@ -1,199 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow/presenter'
3
-
4
- module Rainbow
5
- RSpec.describe Presenter do
6
- let(:presenter) { described_class.new('hello') }
7
-
8
- shared_examples_for "rainbow string method" do
9
- it "wraps the text with a sgr sequence" do
10
- expect(subject).to eq('[hello]')
11
- end
12
-
13
- it "returns an instance of Rainbow::Presenter" do
14
- expect(subject).to be_kind_of(Rainbow::Presenter)
15
- end
16
- end
17
-
18
- shared_examples_for "text color method" do
19
- let(:color) { double('color', codes: [1, 2]) }
20
-
21
- before do
22
- allow(Color).to receive(:build)
23
- .with(:foreground, [:arg1, 'arg2']) { color }
24
- end
25
-
26
- it_behaves_like "rainbow string method"
27
-
28
- it 'wraps with color codes' do
29
- subject
30
- expect(StringUtils).to have_received(:wrap_with_sgr)
31
- .with('hello', [1, 2])
32
- end
33
- end
34
-
35
- shared_examples_for "text background method" do
36
- let(:color) { double('color', codes: [1, 2]) }
37
-
38
- before do
39
- allow(Color).to receive(:build)
40
- .with(:background, [:arg1, 'arg2']) { color }
41
- end
42
-
43
- it_behaves_like "rainbow string method"
44
-
45
- it 'wraps with color codes' do
46
- subject
47
- expect(StringUtils).to have_received(:wrap_with_sgr)
48
- .with('hello', [1, 2])
49
- end
50
- end
51
-
52
- before do
53
- allow(StringUtils).to receive(:wrap_with_sgr) { '[hello]' }
54
- end
55
-
56
- describe '#color' do
57
- subject { presenter.color(:arg1, 'arg2') }
58
-
59
- it_behaves_like "text color method"
60
- end
61
-
62
- describe '#foreground' do
63
- subject { presenter.foreground(:arg1, 'arg2') }
64
-
65
- it_behaves_like "text color method"
66
- end
67
-
68
- describe '#fg' do
69
- subject { presenter.fg(:arg1, 'arg2') }
70
-
71
- it_behaves_like "text color method"
72
- end
73
-
74
- describe '#background' do
75
- subject { presenter.background(:arg1, 'arg2') }
76
-
77
- it_behaves_like "text background method"
78
- end
79
-
80
- describe '#bg' do
81
- subject { presenter.bg(:arg1, 'arg2') }
82
-
83
- it_behaves_like "text background method"
84
- end
85
-
86
- describe '#reset' do
87
- subject { presenter.reset }
88
-
89
- it_behaves_like "rainbow string method"
90
-
91
- it 'wraps with 0 code' do
92
- subject
93
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [0])
94
- end
95
- end
96
-
97
- describe '#bright' do
98
- subject { presenter.bright }
99
-
100
- it_behaves_like "rainbow string method"
101
-
102
- it 'wraps with 1 code' do
103
- subject
104
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [1])
105
- end
106
- end
107
-
108
- describe '#bold' do
109
- subject { presenter.bold }
110
-
111
- it_behaves_like "rainbow string method"
112
-
113
- it 'wraps with 1 code' do
114
- subject
115
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [1])
116
- end
117
- end
118
-
119
- describe '#faint' do
120
- subject { presenter.faint }
121
-
122
- it_behaves_like "rainbow string method"
123
-
124
- it 'wraps with 2 code' do
125
- subject
126
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [2])
127
- end
128
- end
129
-
130
- describe '#dark' do
131
- subject { presenter.dark }
132
-
133
- it_behaves_like "rainbow string method"
134
-
135
- it 'wraps with 2 code' do
136
- subject
137
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [2])
138
- end
139
- end
140
-
141
- describe '#italic' do
142
- subject { presenter.italic }
143
-
144
- it_behaves_like "rainbow string method"
145
-
146
- it 'wraps with 3 code' do
147
- subject
148
- expect(StringUtils).to have_received(:wrap_with_sgr)
149
- .with('hello', [3])
150
- end
151
- end
152
-
153
- describe '#underline' do
154
- subject { presenter.underline }
155
-
156
- it_behaves_like "rainbow string method"
157
-
158
- it 'wraps with 4 code' do
159
- subject
160
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [4])
161
- end
162
- end
163
-
164
- describe '#blink' do
165
- subject { presenter.blink }
166
-
167
- it_behaves_like "rainbow string method"
168
-
169
- it 'wraps with 5 code' do
170
- subject
171
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [5])
172
- end
173
- end
174
-
175
- describe '#inverse' do
176
- subject { presenter.inverse }
177
-
178
- it_behaves_like "rainbow string method"
179
-
180
- it 'wraps with 7 code' do
181
- subject
182
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [7])
183
- end
184
- end
185
-
186
- describe '#hide' do
187
- subject { presenter.hide }
188
-
189
- it_behaves_like "rainbow string method"
190
-
191
- it 'wraps with 8 code' do
192
- subject
193
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [8])
194
- end
195
- end
196
-
197
- it_behaves_like "presenter with shortcut color methods"
198
- end
199
- end
@@ -1,94 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow/string_utils'
3
-
4
- module Rainbow
5
- RSpec.describe StringUtils do
6
- describe '.wrap_with_sgr' do
7
- subject { described_class.wrap_with_sgr(string, codes) }
8
-
9
- let(:string) { 'hello' }
10
- let(:codes) { [1] }
11
-
12
- it "doesn't mutate original string" do
13
- string.freeze
14
- expect(subject).to eq("\e[1mhello\e[0m")
15
- expect(string).to eq('hello')
16
- end
17
-
18
- context "when subclass of String class given" do
19
- class Stringgg < ::String; end
20
-
21
- let(:string) { Stringgg.new('hello') }
22
-
23
- it { should eq("\e[1mhello\e[0m") }
24
- end
25
-
26
- context "when no codes given" do
27
- let(:codes) { [] }
28
-
29
- it "doesn't wrap the given string with any sgr sequence" do
30
- expect(subject).to eq("hello")
31
- end
32
- end
33
-
34
- context "when single code given" do
35
- let(:codes) { [1] }
36
-
37
- it "wraps the given string with sgr sequence for given codes" do
38
- expect(subject).to eq("\e[1mhello\e[0m")
39
- end
40
- end
41
-
42
- context "when multiple codes given" do
43
- let(:codes) { [1, 2] }
44
-
45
- it "wraps the given string with sgr sequence for given codes" do
46
- expect(subject).to eq("\e[1;2mhello\e[0m")
47
- end
48
- end
49
-
50
- context "when wrapping an already wrapped string" do
51
- let(:string) { "\e[1;2mhello\e[0m" }
52
- let(:codes) { [3, 4] }
53
-
54
- it "wraps the given string with sgr sequence for given codes" do
55
- expect(subject).to eq("\e[1;2m\e[3;4mhello\e[0m")
56
- end
57
- end
58
- end
59
-
60
- describe '.uncolor' do
61
- subject { described_class.uncolor(string) }
62
-
63
- context "when string with ansi color escape is passed" do
64
- let(:string) do
65
- rainbow = Rainbow.new
66
- rainbow.enabled = true
67
- rainbow.wrap('hello').
68
- foreground(:red).
69
- bright.
70
- bold.
71
- italic.
72
- background('#ff8040').
73
- underline.
74
- color(:blue).
75
- blink.
76
- inverse.
77
- hide
78
- end
79
-
80
- it "removes ansi color codes" do
81
- expect(subject).to eq 'hello'
82
- end
83
- end
84
-
85
- context "when string with scroll down ansi escape is passed" do
86
- let(:string) { "\e[1Thello" }
87
-
88
- it "does not remove ansi scroll down escape" do
89
- expect(subject).to eq "\e[1Thello"
90
- end
91
- end
92
- end
93
- end
94
- end
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow/wrapper'
3
-
4
- module Rainbow
5
- RSpec.describe Wrapper do
6
- let(:wrapper) { described_class.new(enabled) }
7
-
8
- it "is enabled by default" do
9
- expect(described_class.new.enabled).to be(true)
10
- end
11
-
12
- describe '#wrap' do
13
- subject { wrapper.wrap(object) }
14
-
15
- let(:object) { Object.new }
16
-
17
- context "when wrapping is enabled" do
18
- let(:enabled) { true }
19
-
20
- it { should eq(object.to_s) }
21
- it { should be_kind_of(Rainbow::Presenter) }
22
- end
23
-
24
- context "when wrapping is disabled" do
25
- let(:enabled) { false }
26
-
27
- it { should eq(object.to_s) }
28
- it { should be_kind_of(Rainbow::NullPresenter) }
29
- end
30
- end
31
- end
32
- end