rainbow 2.1.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,168 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow/presenter'
3
-
4
- module Rainbow
5
- describe Presenter do
6
-
7
- let(:presenter) { described_class.new('hello') }
8
-
9
- shared_examples_for "rainbow string method" do
10
- it "wraps the text with a sgr sequence" do
11
- expect(subject).to eq('[hello]')
12
- end
13
-
14
- it "returns an instance of Rainbow::Presenter" do
15
- expect(subject).to be_kind_of(Rainbow::Presenter)
16
- end
17
- end
18
-
19
- shared_examples_for "text color method" do
20
- let(:color) { double('color', codes: [1, 2]) }
21
-
22
- before do
23
- allow(Color).to receive(:build).
24
- with(:foreground, [:arg1, 'arg2']) { color }
25
- end
26
-
27
- it_behaves_like "rainbow string method"
28
-
29
- it 'wraps with color codes' do
30
- subject
31
- expect(StringUtils).to have_received(:wrap_with_sgr).
32
- with('hello', [1, 2])
33
- end
34
- end
35
-
36
- shared_examples_for "text background method" do
37
- let(:color) { double('color', codes: [1, 2]) }
38
-
39
- before do
40
- allow(Color).to receive(:build).
41
- with(:background, [:arg1, 'arg2']) { color }
42
- end
43
-
44
- it_behaves_like "rainbow string method"
45
-
46
- it 'wraps with color codes' do
47
- subject
48
- expect(StringUtils).to have_received(:wrap_with_sgr).
49
- with('hello', [1, 2])
50
- end
51
- end
52
-
53
- before do
54
- allow(StringUtils).to receive(:wrap_with_sgr) { '[hello]' }
55
- end
56
-
57
- describe '#color' do
58
- subject { presenter.color(:arg1, 'arg2') }
59
-
60
- it_behaves_like "text color method"
61
- end
62
-
63
- describe '#foreground' do
64
- subject { presenter.foreground(:arg1, 'arg2') }
65
-
66
- it_behaves_like "text color method"
67
- end
68
-
69
- describe '#fg' do
70
- subject { presenter.fg(:arg1, 'arg2') }
71
-
72
- it_behaves_like "text color method"
73
- end
74
-
75
- describe '#background' do
76
- subject { presenter.background(:arg1, 'arg2') }
77
-
78
- it_behaves_like "text background method"
79
- end
80
-
81
- describe '#bg' do
82
- subject { presenter.bg(:arg1, 'arg2') }
83
-
84
- it_behaves_like "text background method"
85
- end
86
-
87
- describe '#reset' do
88
- subject { presenter.reset }
89
-
90
- it_behaves_like "rainbow string method"
91
-
92
- it 'wraps with 0 code' do
93
- subject
94
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [0])
95
- end
96
- end
97
-
98
- describe '#bright' do
99
- subject { presenter.bright }
100
-
101
- it_behaves_like "rainbow string method"
102
-
103
- it 'wraps with 1 code' do
104
- subject
105
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [1])
106
- end
107
- end
108
-
109
- describe '#italic' do
110
- subject { presenter.italic }
111
-
112
- it_behaves_like "rainbow string method"
113
-
114
- it 'wraps with 3 code' do
115
- subject
116
- expect(StringUtils).to have_received(:wrap_with_sgr).
117
- with('hello', [3])
118
- end
119
- end
120
-
121
- describe '#underline' do
122
- subject { presenter.underline }
123
-
124
- it_behaves_like "rainbow string method"
125
-
126
- it 'wraps with 4 code' do
127
- subject
128
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [4])
129
- end
130
- end
131
-
132
- describe '#blink' do
133
- subject { presenter.blink }
134
-
135
- it_behaves_like "rainbow string method"
136
-
137
- it 'wraps with 5 code' do
138
- subject
139
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [5])
140
- end
141
- end
142
-
143
- describe '#inverse' do
144
- subject { presenter.inverse }
145
-
146
- it_behaves_like "rainbow string method"
147
-
148
- it 'wraps with 7 code' do
149
- subject
150
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [7])
151
- end
152
- end
153
-
154
- describe '#hide' do
155
- subject { presenter.hide }
156
-
157
- it_behaves_like "rainbow string method"
158
-
159
- it 'wraps with 8 code' do
160
- subject
161
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [8])
162
- end
163
- end
164
-
165
- it_behaves_like "presenter with shortcut color methods"
166
-
167
- end
168
- end
@@ -1,62 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow/string_utils'
3
-
4
- module Rainbow
5
- describe StringUtils do
6
- describe '.wrap_with_sgr' do
7
-
8
- subject { described_class.wrap_with_sgr(string, codes) }
9
-
10
- let(:string) { 'hello' }
11
- let(:codes) { [1] }
12
-
13
- it "doesn't mutate original string" do
14
- string.freeze
15
- expect(subject).to eq("\e[1mhello\e[0m")
16
- expect(string).to eq('hello')
17
- end
18
-
19
- context "when subclass of String class given" do
20
- class Stringgg < ::String; end
21
-
22
- let(:string) { Stringgg.new('hello') }
23
-
24
- it { should eq("\e[1mhello\e[0m") }
25
- end
26
-
27
- context "when no codes given" do
28
- let(:codes) { [] }
29
-
30
- it "doesn't wrap the given string with any sgr sequence" do
31
- expect(subject).to eq("hello")
32
- end
33
- end
34
-
35
- context "when single code given" do
36
- let(:codes) { [1] }
37
-
38
- it "wraps the given string with sgr sequence for given codes" do
39
- expect(subject).to eq("\e[1mhello\e[0m")
40
- end
41
- end
42
-
43
- context "when multiple codes given" do
44
- let(:codes) { [1, 2] }
45
-
46
- it "wraps the given string with sgr sequence for given codes" do
47
- expect(subject).to eq("\e[1;2mhello\e[0m")
48
- end
49
- end
50
-
51
- context "when wrapping an already wrapped string" do
52
- let(:string) { "\e[1;2mhello\e[0m" }
53
- let(:codes) { [3, 4] }
54
-
55
- it "wraps the given string with sgr sequence for given codes" do
56
- expect(subject).to eq("\e[1;2m\e[3;4mhello\e[0m")
57
- end
58
- end
59
-
60
- end
61
- end
62
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow/wrapper'
3
-
4
- module Rainbow
5
- describe Wrapper do
6
-
7
- let(:wrapper) { described_class.new(enabled) }
8
-
9
- it "is enabled by default" do
10
- expect(described_class.new.enabled).to be(true)
11
- end
12
-
13
- describe '#wrap' do
14
- subject { wrapper.wrap(object) }
15
-
16
- let(:object) { Object.new }
17
-
18
- context "when wrapping is enabled" do
19
- let(:enabled) { true }
20
-
21
- it { should eq(object.to_s) }
22
- it { should be_kind_of(Rainbow::Presenter) }
23
- end
24
-
25
- context "when wrapping is disabled" do
26
- let(:enabled) { false }
27
-
28
- it { should eq(object.to_s) }
29
- it { should be_kind_of(Rainbow::NullPresenter) }
30
- end
31
- end
32
-
33
- end
34
- end