forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger_spec.rb
More file actions
181 lines (149 loc) · 3.88 KB
/
logger_spec.rb
File metadata and controls
181 lines (149 loc) · 3.88 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
require 'spec_helper'
describe Overcommit::Logger do
let(:io) { StringIO.new }
let(:output) { io.string }
subject { described_class.new(io) }
describe '.silent' do
subject { described_class.silent }
it 'does not output anything' do
capture_stdout { subject.log('Something') }.should be_empty
end
end
describe '#partial' do
subject { super().partial('Hello') }
it 'writes to the output stream' do
subject
output.should_not be_empty
end
it 'does not append a newline' do
subject
output[-1].should_not == "\n"
end
end
describe '#log' do
subject { super().log('Hello') }
it 'writes to the output stream' do
subject
output.should_not be_empty
end
it 'appends a newline' do
subject
output[-1, 1].should == "\n"
end
end
shared_examples_for 'colorized output' do
subject { super().send(method, 'Hello') }
it 'writes to the output stream' do
subject
output.should_not be_empty
end
it 'appends a newline' do
subject
output[-1, 1].should == "\n"
end
context 'when the output stream is a TTY' do
before do
io.stub(:tty?).and_return(true)
end
it 'includes the color escape sequence' do
subject
output.should include "\033[#{color_code}m"
end
it 'ends with the color reset sequence' do
subject
output.should end_with "[0m\n"
end
context 'and colorization is disabled' do
around do |example|
Overcommit::Utils.with_environment 'OVERCOMMIT_COLOR' => '0' do
example.run
end
end
it 'omits the color escape sequence' do
subject
output.should_not include "\033"
end
end
end
context 'when the output stream is not a TTY' do
before do
io.stub(:tty?).and_return(false)
end
it 'omits the color escape sequence' do
subject
output.should_not include "\033"
end
context 'and colorization is enabled' do
around do |example|
Overcommit::Utils.with_environment 'OVERCOMMIT_COLOR' => '1' do
example.run
end
end
it 'includes the color escape sequence' do
subject
output.should include "\033[#{color_code}m"
end
it 'ends with the color reset sequence' do
subject
output.should end_with "[0m\n"
end
end
end
end
describe '#debug' do
context 'when debug mode is enabled' do
around do |example|
Overcommit::Utils.with_environment 'OVERCOMMIT_DEBUG' => '1' do
example.run
end
end
it_behaves_like 'colorized output' do
let(:method) { :debug }
let(:color_code) { '35' }
end
end
context 'when debug mode is not enabled' do
subject { super().debug('Hello') }
it 'does not write to the output stream' do
subject
output.should be_empty
end
end
end
describe '#bold' do
it_behaves_like 'colorized output' do
let(:method) { :bold }
let(:color_code) { '1' }
end
end
describe '#error' do
it_behaves_like 'colorized output' do
let(:method) { :error }
let(:color_code) { 31 }
end
end
describe '#bold_error' do
it_behaves_like 'colorized output' do
let(:method) { :bold_error }
let(:color_code) { '1;31' }
end
end
describe '#success' do
it_behaves_like 'colorized output' do
let(:method) { :success }
let(:color_code) { 32 }
end
end
describe '#warning' do
it_behaves_like 'colorized output' do
let(:method) { :warning }
let(:color_code) { 33 }
end
end
describe '#bold_warning' do
it_behaves_like 'colorized output' do
let(:method) { :bold_warning }
let(:color_code) { '1;33' }
end
end
end