/
bzip2_spec.rb
238 lines (208 loc) · 7.56 KB
/
bzip2_spec.rb
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# encoding: utf-8
require File.expand_path('../../spec_helper.rb', __FILE__)
describe Backup::Compressor::Bzip2 do
before do
Backup::Compressor::Bzip2.any_instance.stubs(:utility).returns('bzip2')
end
it 'should be a subclass of Compressor::Base' do
Backup::Compressor::Bzip2.
superclass.should == Backup::Compressor::Base
end
describe '#initialize' do
let(:compressor) { Backup::Compressor::Bzip2.new }
after { Backup::Compressor::Bzip2.clear_defaults! }
it 'should load pre-configured defaults' do
Backup::Compressor::Bzip2.any_instance.expects(:load_defaults!)
compressor
end
context 'when no pre-configured defaults have been set' do
it 'should use default values' do
compressor.level.should be_false
compressor.instance_variable_get(:@cmd).should == 'bzip2'
compressor.instance_variable_get(:@ext).should == '.bz2'
end
it 'should use the values given' do
compressor = Backup::Compressor::Bzip2.new do |c|
c.level = 5
end
compressor.level.should == 5
compressor.instance_variable_get(:@cmd).should == 'bzip2 -5'
compressor.instance_variable_get(:@ext).should == '.bz2'
end
end # context 'when no pre-configured defaults have been set'
context 'when pre-configured defaults have been set' do
before do
Backup::Compressor::Bzip2.defaults do |c|
c.level = 7
end
end
it 'should use pre-configured defaults' do
compressor.level.should == 7
compressor.instance_variable_get(:@cmd).should == 'bzip2 -7'
compressor.instance_variable_get(:@ext).should == '.bz2'
end
it 'should override pre-configured defaults' do
compressor = Backup::Compressor::Bzip2.new do |c|
c.level = 6
end
compressor.level.should == 6
compressor.instance_variable_get(:@cmd).should == 'bzip2 -6'
compressor.instance_variable_get(:@ext).should == '.bz2'
end
end # context 'when pre-configured defaults have been set'
end # describe '#initialize'
describe 'deprecations' do
describe 'fast and best options' do
context 'when only the fast option is used' do
before do
Backup::Logger.expects(:warn).with(
instance_of(Backup::Errors::ConfigurationError)
)
end
context 'when set to true' do
it 'should log a warning and set `level` to 1' do
Backup::Logger.expects(:warn).with(
"Backup::Compressor::Bzip2.level is being set to '1'"
)
compressor = Backup::Compressor::Bzip2.new do |c|
c.fast = true
end
compressor.level.should be(1)
end
end
context 'when set to false' do
it 'should only log a warning' do
compressor = Backup::Compressor::Bzip2.new do |c|
c.fast = false
end
compressor.level.should be_false
end
end
end
context 'when only the best option is used' do
before do
Backup::Logger.expects(:warn).with(
instance_of(Backup::Errors::ConfigurationError)
)
end
context 'when set to true' do
it 'should log a warning and set `level` to 1' do
Backup::Logger.expects(:warn).with(
"Backup::Compressor::Bzip2.level is being set to '9'"
)
compressor = Backup::Compressor::Bzip2.new do |c|
c.best = true
end
compressor.level.should be(9)
end
end
context 'when set to false' do
it 'should only log a warning' do
compressor = Backup::Compressor::Bzip2.new do |c|
c.best = false
end
compressor.level.should be_false
end
end
end
context 'when both fast and best options are used' do
before do
Backup::Logger.expects(:warn).twice.with(
instance_of(Backup::Errors::ConfigurationError)
)
end
context 'when both are set true' do
context 'when fast is set first' do
it 'should cause the best option to be set' do
Backup::Logger.expects(:warn).with(
"Backup::Compressor::Bzip2.level is being set to '1'"
)
Backup::Logger.expects(:warn).with(
"Backup::Compressor::Bzip2.level is being set to '9'"
)
compressor = Backup::Compressor::Bzip2.new do |c|
c.fast = true
c.best = true
end
compressor.level.should == 9
end
end
context 'when best is set first' do
it 'should cause the fast option to be set' do
Backup::Logger.expects(:warn).with(
"Backup::Compressor::Bzip2.level is being set to '1'"
)
Backup::Logger.expects(:warn).with(
"Backup::Compressor::Bzip2.level is being set to '9'"
)
compressor = Backup::Compressor::Bzip2.new do |c|
c.best = true
c.fast = true
end
compressor.level.should == 1
end
end
end
context 'when only one is set true' do
context 'when fast is set true before best' do
it 'should cause the fast option to be set' do
Backup::Logger.expects(:warn).with(
"Backup::Compressor::Bzip2.level is being set to '1'"
)
compressor = Backup::Compressor::Bzip2.new do |c|
c.fast = true
c.best = false
end
compressor.level.should == 1
end
end
context 'when fast is set true after best' do
it 'should cause the fast option to be set' do
Backup::Logger.expects(:warn).with(
"Backup::Compressor::Bzip2.level is being set to '1'"
)
compressor = Backup::Compressor::Bzip2.new do |c|
c.best = false
c.fast = true
end
compressor.level.should == 1
end
end
context 'when best is set true before fast' do
it 'should cause the best option to be set' do
Backup::Logger.expects(:warn).with(
"Backup::Compressor::Bzip2.level is being set to '9'"
)
compressor = Backup::Compressor::Bzip2.new do |c|
c.best = true
c.fast = false
end
compressor.level.should == 9
end
end
context 'when best is set true after fast' do
it 'should cause the best option to be set' do
Backup::Logger.expects(:warn).with(
"Backup::Compressor::Bzip2.level is being set to '9'"
)
compressor = Backup::Compressor::Bzip2.new do |c|
c.fast = false
c.best = true
end
compressor.level.should == 9
end
end
end
context 'when both are set false' do
it 'should only issue the two warnings' do
compressor = Backup::Compressor::Bzip2.new do |c|
c.fast = false
c.best = false
end
compressor.level.should be_false
end
end
end
end # describe 'fast and best options'
end # describe 'deprecations'
end