backup 3.0.23 → 3.0.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. data/Gemfile.lock +42 -45
  2. data/Guardfile +7 -4
  3. data/README.md +10 -7
  4. data/backup.gemspec +2 -2
  5. data/lib/backup.rb +27 -97
  6. data/lib/backup/archive.rb +14 -6
  7. data/lib/backup/cli/helpers.rb +52 -49
  8. data/lib/backup/cli/utility.rb +9 -1
  9. data/lib/backup/compressor/base.rb +10 -4
  10. data/lib/backup/compressor/bzip2.rb +22 -26
  11. data/lib/backup/compressor/custom.rb +53 -0
  12. data/lib/backup/compressor/gzip.rb +22 -23
  13. data/lib/backup/compressor/lzma.rb +15 -13
  14. data/lib/backup/compressor/pbzip2.rb +20 -17
  15. data/lib/backup/config.rb +6 -3
  16. data/lib/backup/configuration.rb +33 -0
  17. data/lib/backup/configuration/helpers.rb +114 -28
  18. data/lib/backup/configuration/store.rb +24 -0
  19. data/lib/backup/database/base.rb +0 -6
  20. data/lib/backup/database/mongodb.rb +27 -11
  21. data/lib/backup/database/mysql.rb +19 -14
  22. data/lib/backup/database/postgresql.rb +16 -11
  23. data/lib/backup/database/redis.rb +7 -11
  24. data/lib/backup/database/riak.rb +3 -6
  25. data/lib/backup/dependency.rb +5 -11
  26. data/lib/backup/model.rb +14 -5
  27. data/lib/backup/notifier/campfire.rb +3 -16
  28. data/lib/backup/notifier/hipchat.rb +1 -7
  29. data/lib/backup/notifier/mail.rb +1 -1
  30. data/lib/backup/packager.rb +29 -19
  31. data/lib/backup/pipeline.rb +110 -0
  32. data/lib/backup/storage/dropbox.rb +4 -7
  33. data/lib/backup/syncer/base.rb +8 -4
  34. data/lib/backup/syncer/cloud/base.rb +247 -0
  35. data/lib/backup/syncer/cloud/cloud_files.rb +78 -0
  36. data/lib/backup/syncer/cloud/s3.rb +68 -0
  37. data/lib/backup/syncer/rsync/base.rb +1 -4
  38. data/lib/backup/syncer/rsync/local.rb +9 -5
  39. data/lib/backup/syncer/rsync/pull.rb +1 -1
  40. data/lib/backup/syncer/rsync/push.rb +10 -5
  41. data/lib/backup/version.rb +1 -1
  42. data/spec-live/.gitignore +6 -0
  43. data/spec-live/README +7 -0
  44. data/spec-live/backups/config.rb +153 -0
  45. data/spec-live/backups/config.yml.template +43 -0
  46. data/spec-live/compressor/custom_spec.rb +30 -0
  47. data/spec-live/compressor/gzip_spec.rb +30 -0
  48. data/spec-live/notifier/mail_spec.rb +85 -0
  49. data/spec-live/spec_helper.rb +85 -0
  50. data/spec-live/storage/dropbox_spec.rb +151 -0
  51. data/spec-live/storage/local_spec.rb +83 -0
  52. data/spec-live/storage/scp_spec.rb +193 -0
  53. data/spec-live/syncer/cloud/s3_spec.rb +124 -0
  54. data/spec/archive_spec.rb +86 -31
  55. data/spec/cleaner_spec.rb +8 -0
  56. data/spec/cli/helpers_spec.rb +200 -75
  57. data/spec/cli/utility_spec.rb +11 -3
  58. data/spec/compressor/base_spec.rb +31 -10
  59. data/spec/compressor/bzip2_spec.rb +212 -57
  60. data/spec/compressor/custom_spec.rb +106 -0
  61. data/spec/compressor/gzip_spec.rb +212 -57
  62. data/spec/compressor/lzma_spec.rb +75 -35
  63. data/spec/compressor/pbzip2_spec.rb +93 -52
  64. data/spec/configuration/helpers_spec.rb +406 -0
  65. data/spec/configuration/store_spec.rb +39 -0
  66. data/spec/configuration_spec.rb +62 -0
  67. data/spec/database/base_spec.rb +19 -10
  68. data/spec/database/mongodb_spec.rb +195 -70
  69. data/spec/database/mysql_spec.rb +183 -64
  70. data/spec/database/postgresql_spec.rb +167 -53
  71. data/spec/database/redis_spec.rb +121 -46
  72. data/spec/database/riak_spec.rb +96 -27
  73. data/spec/dependency_spec.rb +2 -0
  74. data/spec/encryptor/base_spec.rb +10 -0
  75. data/spec/encryptor/gpg_spec.rb +29 -13
  76. data/spec/encryptor/open_ssl_spec.rb +40 -21
  77. data/spec/logger_spec.rb +4 -0
  78. data/spec/model_spec.rb +19 -2
  79. data/spec/notifier/base_spec.rb +32 -17
  80. data/spec/notifier/campfire_spec.rb +63 -45
  81. data/spec/notifier/hipchat_spec.rb +79 -56
  82. data/spec/notifier/mail_spec.rb +82 -46
  83. data/spec/notifier/prowl_spec.rb +53 -32
  84. data/spec/notifier/twitter_spec.rb +62 -41
  85. data/spec/packager_spec.rb +95 -36
  86. data/spec/pipeline_spec.rb +259 -0
  87. data/spec/spec_helper.rb +6 -5
  88. data/spec/storage/base_spec.rb +61 -41
  89. data/spec/storage/cloudfiles_spec.rb +69 -45
  90. data/spec/storage/dropbox_spec.rb +158 -36
  91. data/spec/storage/ftp_spec.rb +69 -45
  92. data/spec/storage/local_spec.rb +47 -23
  93. data/spec/storage/ninefold_spec.rb +55 -31
  94. data/spec/storage/rsync_spec.rb +67 -50
  95. data/spec/storage/s3_spec.rb +65 -41
  96. data/spec/storage/scp_spec.rb +65 -41
  97. data/spec/storage/sftp_spec.rb +65 -41
  98. data/spec/syncer/base_spec.rb +91 -4
  99. data/spec/syncer/cloud/base_spec.rb +511 -0
  100. data/spec/syncer/cloud/cloud_files_spec.rb +181 -0
  101. data/spec/syncer/cloud/s3_spec.rb +174 -0
  102. data/spec/syncer/rsync/base_spec.rb +46 -66
  103. data/spec/syncer/rsync/local_spec.rb +55 -26
  104. data/spec/syncer/rsync/pull_spec.rb +15 -4
  105. data/spec/syncer/rsync/push_spec.rb +59 -52
  106. data/templates/cli/utility/compressor/bzip2 +1 -4
  107. data/templates/cli/utility/compressor/custom +11 -0
  108. data/templates/cli/utility/compressor/gzip +1 -4
  109. data/templates/cli/utility/compressor/lzma +3 -0
  110. data/templates/cli/utility/compressor/pbzip2 +3 -0
  111. data/templates/cli/utility/database/mysql +4 -1
  112. data/templates/cli/utility/syncer/cloud_files +17 -19
  113. data/templates/cli/utility/syncer/s3 +18 -20
  114. metadata +38 -92
  115. data/lib/backup/configuration/base.rb +0 -15
  116. data/lib/backup/configuration/compressor/base.rb +0 -9
  117. data/lib/backup/configuration/compressor/bzip2.rb +0 -23
  118. data/lib/backup/configuration/compressor/gzip.rb +0 -23
  119. data/lib/backup/configuration/compressor/lzma.rb +0 -23
  120. data/lib/backup/configuration/compressor/pbzip2.rb +0 -28
  121. data/lib/backup/configuration/database/base.rb +0 -19
  122. data/lib/backup/configuration/database/mongodb.rb +0 -49
  123. data/lib/backup/configuration/database/mysql.rb +0 -42
  124. data/lib/backup/configuration/database/postgresql.rb +0 -41
  125. data/lib/backup/configuration/database/redis.rb +0 -39
  126. data/lib/backup/configuration/database/riak.rb +0 -29
  127. data/lib/backup/configuration/encryptor/base.rb +0 -9
  128. data/lib/backup/configuration/encryptor/gpg.rb +0 -17
  129. data/lib/backup/configuration/encryptor/open_ssl.rb +0 -32
  130. data/lib/backup/configuration/notifier/base.rb +0 -28
  131. data/lib/backup/configuration/notifier/campfire.rb +0 -25
  132. data/lib/backup/configuration/notifier/hipchat.rb +0 -41
  133. data/lib/backup/configuration/notifier/mail.rb +0 -112
  134. data/lib/backup/configuration/notifier/presently.rb +0 -25
  135. data/lib/backup/configuration/notifier/prowl.rb +0 -23
  136. data/lib/backup/configuration/notifier/twitter.rb +0 -21
  137. data/lib/backup/configuration/storage/base.rb +0 -18
  138. data/lib/backup/configuration/storage/cloudfiles.rb +0 -25
  139. data/lib/backup/configuration/storage/dropbox.rb +0 -58
  140. data/lib/backup/configuration/storage/ftp.rb +0 -29
  141. data/lib/backup/configuration/storage/local.rb +0 -17
  142. data/lib/backup/configuration/storage/ninefold.rb +0 -20
  143. data/lib/backup/configuration/storage/rsync.rb +0 -29
  144. data/lib/backup/configuration/storage/s3.rb +0 -25
  145. data/lib/backup/configuration/storage/scp.rb +0 -25
  146. data/lib/backup/configuration/storage/sftp.rb +0 -25
  147. data/lib/backup/configuration/syncer/base.rb +0 -10
  148. data/lib/backup/configuration/syncer/cloud.rb +0 -23
  149. data/lib/backup/configuration/syncer/cloud_files.rb +0 -30
  150. data/lib/backup/configuration/syncer/rsync/base.rb +0 -28
  151. data/lib/backup/configuration/syncer/rsync/local.rb +0 -11
  152. data/lib/backup/configuration/syncer/rsync/pull.rb +0 -11
  153. data/lib/backup/configuration/syncer/rsync/push.rb +0 -31
  154. data/lib/backup/configuration/syncer/s3.rb +0 -23
  155. data/lib/backup/notifier/presently.rb +0 -88
  156. data/lib/backup/syncer/cloud.rb +0 -187
  157. data/lib/backup/syncer/cloud_files.rb +0 -56
  158. data/lib/backup/syncer/s3.rb +0 -47
  159. data/spec/configuration/base_spec.rb +0 -35
  160. data/spec/configuration/compressor/bzip2_spec.rb +0 -29
  161. data/spec/configuration/compressor/gzip_spec.rb +0 -29
  162. data/spec/configuration/compressor/lzma_spec.rb +0 -29
  163. data/spec/configuration/compressor/pbzip2_spec.rb +0 -32
  164. data/spec/configuration/database/base_spec.rb +0 -17
  165. data/spec/configuration/database/mongodb_spec.rb +0 -56
  166. data/spec/configuration/database/mysql_spec.rb +0 -53
  167. data/spec/configuration/database/postgresql_spec.rb +0 -53
  168. data/spec/configuration/database/redis_spec.rb +0 -50
  169. data/spec/configuration/database/riak_spec.rb +0 -35
  170. data/spec/configuration/encryptor/gpg_spec.rb +0 -26
  171. data/spec/configuration/encryptor/open_ssl_spec.rb +0 -35
  172. data/spec/configuration/notifier/base_spec.rb +0 -32
  173. data/spec/configuration/notifier/campfire_spec.rb +0 -32
  174. data/spec/configuration/notifier/hipchat_spec.rb +0 -44
  175. data/spec/configuration/notifier/mail_spec.rb +0 -71
  176. data/spec/configuration/notifier/presently_spec.rb +0 -35
  177. data/spec/configuration/notifier/prowl_spec.rb +0 -29
  178. data/spec/configuration/notifier/twitter_spec.rb +0 -35
  179. data/spec/configuration/storage/cloudfiles_spec.rb +0 -41
  180. data/spec/configuration/storage/dropbox_spec.rb +0 -38
  181. data/spec/configuration/storage/ftp_spec.rb +0 -44
  182. data/spec/configuration/storage/local_spec.rb +0 -29
  183. data/spec/configuration/storage/ninefold_spec.rb +0 -32
  184. data/spec/configuration/storage/rsync_spec.rb +0 -41
  185. data/spec/configuration/storage/s3_spec.rb +0 -38
  186. data/spec/configuration/storage/scp_spec.rb +0 -41
  187. data/spec/configuration/storage/sftp_spec.rb +0 -41
  188. data/spec/configuration/syncer/cloud_files_spec.rb +0 -44
  189. data/spec/configuration/syncer/rsync/base_spec.rb +0 -33
  190. data/spec/configuration/syncer/rsync/local_spec.rb +0 -10
  191. data/spec/configuration/syncer/rsync/pull_spec.rb +0 -10
  192. data/spec/configuration/syncer/rsync/push_spec.rb +0 -43
  193. data/spec/configuration/syncer/s3_spec.rb +0 -38
  194. data/spec/notifier/presently_spec.rb +0 -181
  195. data/spec/syncer/cloud_files_spec.rb +0 -192
  196. data/spec/syncer/s3_spec.rb +0 -192
  197. data/templates/cli/utility/notifier/presently +0 -13
@@ -3,81 +3,236 @@
3
3
  require File.expand_path('../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Compressor::Gzip do
6
- let(:compressor) { Backup::Compressor::Gzip.new }
6
+ before do
7
+ Backup::Compressor::Gzip.any_instance.stubs(:utility).returns('gzip')
8
+ end
7
9
 
8
- describe 'setting configuration defaults' do
9
- after { Backup::Configuration::Compressor::Gzip.clear_defaults! }
10
+ it 'should be a subclass of Compressor::Base' do
11
+ Backup::Compressor::Gzip.
12
+ superclass.should == Backup::Compressor::Base
13
+ end
10
14
 
11
- it 'uses and overrides configuration defaults' do
12
- Backup::Configuration::Compressor::Gzip.best.should be_false
13
- Backup::Configuration::Compressor::Gzip.fast.should be_false
15
+ describe '#initialize' do
16
+ let(:compressor) { Backup::Compressor::Gzip.new }
14
17
 
15
- compressor = Backup::Compressor::Gzip.new
16
- compressor.best.should be_false
17
- compressor.fast.should be_false
18
+ after { Backup::Compressor::Gzip.clear_defaults! }
18
19
 
19
- Backup::Configuration::Compressor::Gzip.defaults do |c|
20
- c.best = true
21
- c.fast = true
20
+ it 'should load pre-configured defaults' do
21
+ Backup::Compressor::Gzip.any_instance.expects(:load_defaults!)
22
+ compressor
23
+ end
24
+
25
+ context 'when no pre-configured defaults have been set' do
26
+ it 'should use default values' do
27
+ compressor.level.should be_false
28
+
29
+ compressor.instance_variable_get(:@cmd).should == 'gzip'
30
+ compressor.instance_variable_get(:@ext).should == '.gz'
22
31
  end
23
- Backup::Configuration::Compressor::Gzip.best.should be_true
24
- Backup::Configuration::Compressor::Gzip.fast.should be_true
25
32
 
26
- compressor = Backup::Compressor::Gzip.new
27
- compressor.best.should be_true
28
- compressor.fast.should be_true
33
+ it 'should use the values given' do
34
+ compressor = Backup::Compressor::Gzip.new do |c|
35
+ c.level = 5
36
+ end
37
+ compressor.level.should == 5
29
38
 
30
- compressor = Backup::Compressor::Gzip.new do |c|
31
- c.best = false
39
+ compressor.instance_variable_get(:@cmd).should == 'gzip -5'
40
+ compressor.instance_variable_get(:@ext).should == '.gz'
32
41
  end
33
- compressor.best.should be_false
34
- compressor.fast.should be_true
42
+ end # context 'when no pre-configured defaults have been set'
35
43
 
36
- compressor = Backup::Compressor::Gzip.new do |c|
37
- c.fast = false
44
+ context 'when pre-configured defaults have been set' do
45
+ before do
46
+ Backup::Compressor::Gzip.defaults do |c|
47
+ c.level = 7
48
+ end
38
49
  end
39
- compressor.best.should be_true
40
- compressor.fast.should be_false
41
- end
42
- end # describe 'setting configuration defaults'
43
50
 
44
- describe '#compress_with' do
45
- before do
46
- compressor.expects(:log!)
47
- compressor.expects(:utility).with(:gzip).returns('gzip')
48
- end
51
+ it 'should use pre-configured defaults' do
52
+ compressor.level.should == 7
49
53
 
50
- it 'should yield with the --best option' do
51
- compressor.best = true
52
- compressor.compress_with do |cmd, ext|
53
- cmd.should == 'gzip --best'
54
- ext.should == '.gz'
54
+ compressor.instance_variable_get(:@cmd).should == 'gzip -7'
55
+ compressor.instance_variable_get(:@ext).should == '.gz'
55
56
  end
56
- end
57
57
 
58
- it 'should yield with the --fast option' do
59
- compressor.fast = true
60
- compressor.compress_with do |cmd, ext|
61
- cmd.should == 'gzip --fast'
62
- ext.should == '.gz'
58
+ it 'should override pre-configured defaults' do
59
+ compressor = Backup::Compressor::Gzip.new do |c|
60
+ c.level = 6
61
+ end
62
+ compressor.level.should == 6
63
+
64
+ compressor.instance_variable_get(:@cmd).should == 'gzip -6'
65
+ compressor.instance_variable_get(:@ext).should == '.gz'
63
66
  end
64
- end
67
+ end # context 'when pre-configured defaults have been set'
68
+ end # describe '#initialize'
69
+
70
+ describe 'deprecations' do
71
+ describe 'fast and best options' do
72
+ context 'when only the fast option is used' do
73
+ before do
74
+ Backup::Logger.expects(:warn).with(
75
+ instance_of(Backup::Errors::ConfigurationError)
76
+ )
77
+ end
65
78
 
66
- it 'should yield with the --best and --fast options' do
67
- compressor.best = true
68
- compressor.fast = true
69
- compressor.compress_with do |cmd, ext|
70
- cmd.should == 'gzip --best --fast'
71
- ext.should == '.gz'
79
+ context 'when set to true' do
80
+ it 'should log a warning and set `level` to 1' do
81
+ Backup::Logger.expects(:warn).with(
82
+ "Backup::Compressor::Gzip.level is being set to '1'"
83
+ )
84
+ compressor = Backup::Compressor::Gzip.new do |c|
85
+ c.fast = true
86
+ end
87
+ compressor.level.should be(1)
88
+ end
89
+ end
90
+
91
+ context 'when set to false' do
92
+ it 'should only log a warning' do
93
+ compressor = Backup::Compressor::Gzip.new do |c|
94
+ c.fast = false
95
+ end
96
+ compressor.level.should be_false
97
+ end
98
+ end
72
99
  end
73
- end
74
100
 
75
- it 'should yield with no options' do
76
- compressor.compress_with do |cmd, ext|
77
- cmd.should == 'gzip'
78
- ext.should == '.gz'
101
+ context 'when only the best option is used' do
102
+ before do
103
+ Backup::Logger.expects(:warn).with(
104
+ instance_of(Backup::Errors::ConfigurationError)
105
+ )
106
+ end
107
+
108
+ context 'when set to true' do
109
+ it 'should log a warning and set `level` to 1' do
110
+ Backup::Logger.expects(:warn).with(
111
+ "Backup::Compressor::Gzip.level is being set to '9'"
112
+ )
113
+ compressor = Backup::Compressor::Gzip.new do |c|
114
+ c.best = true
115
+ end
116
+ compressor.level.should be(9)
117
+ end
118
+ end
119
+
120
+ context 'when set to false' do
121
+ it 'should only log a warning' do
122
+ compressor = Backup::Compressor::Gzip.new do |c|
123
+ c.best = false
124
+ end
125
+ compressor.level.should be_false
126
+ end
127
+ end
128
+
79
129
  end
80
- end
81
- end # describe '#compress_with'
82
130
 
131
+ context 'when both fast and best options are used' do
132
+ before do
133
+ Backup::Logger.expects(:warn).twice.with(
134
+ instance_of(Backup::Errors::ConfigurationError)
135
+ )
136
+ end
137
+
138
+ context 'when both are set true' do
139
+ context 'when fast is set first' do
140
+ it 'should cause the best option to be set' do
141
+ Backup::Logger.expects(:warn).with(
142
+ "Backup::Compressor::Gzip.level is being set to '1'"
143
+ )
144
+ Backup::Logger.expects(:warn).with(
145
+ "Backup::Compressor::Gzip.level is being set to '9'"
146
+ )
147
+ compressor = Backup::Compressor::Gzip.new do |c|
148
+ c.fast = true
149
+ c.best = true
150
+ end
151
+ compressor.level.should == 9
152
+ end
153
+ end
154
+
155
+ context 'when best is set first' do
156
+ it 'should cause the fast option to be set' do
157
+ Backup::Logger.expects(:warn).with(
158
+ "Backup::Compressor::Gzip.level is being set to '1'"
159
+ )
160
+ Backup::Logger.expects(:warn).with(
161
+ "Backup::Compressor::Gzip.level is being set to '9'"
162
+ )
163
+ compressor = Backup::Compressor::Gzip.new do |c|
164
+ c.best = true
165
+ c.fast = true
166
+ end
167
+ compressor.level.should == 1
168
+ end
169
+ end
170
+ end
171
+
172
+ context 'when only one is set true' do
173
+ context 'when fast is set true before best' do
174
+ it 'should cause the fast option to be set' do
175
+ Backup::Logger.expects(:warn).with(
176
+ "Backup::Compressor::Gzip.level is being set to '1'"
177
+ )
178
+ compressor = Backup::Compressor::Gzip.new do |c|
179
+ c.fast = true
180
+ c.best = false
181
+ end
182
+ compressor.level.should == 1
183
+ end
184
+ end
185
+
186
+ context 'when fast is set true after best' do
187
+ it 'should cause the fast option to be set' do
188
+ Backup::Logger.expects(:warn).with(
189
+ "Backup::Compressor::Gzip.level is being set to '1'"
190
+ )
191
+ compressor = Backup::Compressor::Gzip.new do |c|
192
+ c.best = false
193
+ c.fast = true
194
+ end
195
+ compressor.level.should == 1
196
+ end
197
+ end
198
+
199
+ context 'when best is set true before fast' do
200
+ it 'should cause the best option to be set' do
201
+ Backup::Logger.expects(:warn).with(
202
+ "Backup::Compressor::Gzip.level is being set to '9'"
203
+ )
204
+ compressor = Backup::Compressor::Gzip.new do |c|
205
+ c.best = true
206
+ c.fast = false
207
+ end
208
+ compressor.level.should == 9
209
+ end
210
+ end
211
+
212
+ context 'when best is set true after fast' do
213
+ it 'should cause the best option to be set' do
214
+ Backup::Logger.expects(:warn).with(
215
+ "Backup::Compressor::Gzip.level is being set to '9'"
216
+ )
217
+ compressor = Backup::Compressor::Gzip.new do |c|
218
+ c.fast = false
219
+ c.best = true
220
+ end
221
+ compressor.level.should == 9
222
+ end
223
+ end
224
+ end
225
+
226
+ context 'when both are set false' do
227
+ it 'should only issue the two warnings' do
228
+ compressor = Backup::Compressor::Gzip.new do |c|
229
+ c.fast = false
230
+ c.best = false
231
+ end
232
+ compressor.level.should be_false
233
+ end
234
+ end
235
+ end
236
+ end # describe 'fast and best options'
237
+ end # describe 'deprecations'
83
238
  end
@@ -3,52 +3,83 @@
3
3
  require File.expand_path('../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Compressor::Lzma do
6
- let(:compressor) { Backup::Compressor::Lzma.new }
6
+ before do
7
+ Backup::Compressor::Lzma.any_instance.stubs(:utility).returns('lzma')
8
+ end
7
9
 
8
- describe 'setting configuration defaults' do
9
- after { Backup::Configuration::Compressor::Lzma.clear_defaults! }
10
+ it 'should be a subclass of Compressor::Base' do
11
+ Backup::Compressor::Lzma.
12
+ superclass.should == Backup::Compressor::Base
13
+ end
10
14
 
11
- it 'uses and overrides configuration defaults' do
12
- Backup::Configuration::Compressor::Lzma.best.should be_false
13
- Backup::Configuration::Compressor::Lzma.fast.should be_false
15
+ describe '#initialize' do
16
+ let(:compressor) { Backup::Compressor::Lzma.new }
14
17
 
15
- compressor = Backup::Compressor::Lzma.new
16
- compressor.best.should be_false
17
- compressor.fast.should be_false
18
+ after { Backup::Compressor::Lzma.clear_defaults! }
18
19
 
19
- Backup::Configuration::Compressor::Lzma.defaults do |c|
20
- c.best = true
21
- c.fast = true
20
+ it 'should load pre-configured defaults' do
21
+ Backup::Compressor::Lzma.any_instance.expects(:load_defaults!)
22
+ compressor
23
+ end
24
+
25
+ context 'when no pre-configured defaults have been set' do
26
+ it 'should use default values' do
27
+ compressor.best.should be_false
28
+ compressor.fast.should be_false
22
29
  end
23
- Backup::Configuration::Compressor::Lzma.best.should be_true
24
- Backup::Configuration::Compressor::Lzma.fast.should be_true
25
30
 
26
- compressor = Backup::Compressor::Lzma.new
27
- compressor.best.should be_true
28
- compressor.fast.should be_true
31
+ it 'should use the values given' do
32
+ compressor = Backup::Compressor::Lzma.new do |c|
33
+ c.best = true
34
+ c.fast = true
35
+ end
29
36
 
30
- compressor = Backup::Compressor::Lzma.new do |c|
31
- c.best = false
37
+ compressor.best.should be_true
38
+ compressor.fast.should be_true
32
39
  end
33
- compressor.best.should be_false
34
- compressor.fast.should be_true
40
+ end # context 'when no pre-configured defaults have been set'
35
41
 
36
- compressor = Backup::Compressor::Lzma.new do |c|
37
- c.fast = false
42
+ context 'when pre-configured defaults have been set' do
43
+ before do
44
+ Backup::Compressor::Lzma.defaults do |c|
45
+ c.best = true
46
+ c.fast = true
47
+ end
38
48
  end
39
- compressor.best.should be_true
40
- compressor.fast.should be_false
41
- end
42
- end # describe 'setting configuration defaults'
49
+
50
+ it 'should use pre-configured defaults' do
51
+ compressor.best.should be_true
52
+ compressor.fast.should be_true
53
+ end
54
+
55
+ it 'should override pre-configured defaults' do
56
+ compressor = Backup::Compressor::Lzma.new do |c|
57
+ c.best = false
58
+ c.fast = false
59
+ end
60
+
61
+ compressor.best.should be_false
62
+ compressor.fast.should be_false
63
+ end
64
+ end # context 'when pre-configured defaults have been set'
65
+ end # describe '#initialize'
43
66
 
44
67
  describe '#compress_with' do
45
68
  before do
46
- compressor.expects(:log!)
47
- compressor.expects(:utility).with(:lzma).returns('lzma')
69
+ Backup::Compressor::Lzma.any_instance.expects(:log!)
70
+
71
+ Backup::Logger.expects(:warn).with do |msg|
72
+ msg.should match(
73
+ /\[DEPRECATION WARNING\]\n Compressor::Lzma is being deprecated/
74
+ )
75
+ end
48
76
  end
49
77
 
50
78
  it 'should yield with the --best option' do
51
- compressor.best = true
79
+ compressor = Backup::Compressor::Lzma.new do |c|
80
+ c.best = true
81
+ end
82
+
52
83
  compressor.compress_with do |cmd, ext|
53
84
  cmd.should == 'lzma --best'
54
85
  ext.should == '.lzma'
@@ -56,28 +87,37 @@ describe Backup::Compressor::Lzma do
56
87
  end
57
88
 
58
89
  it 'should yield with the --fast option' do
59
- compressor.fast = true
90
+ compressor = Backup::Compressor::Lzma.new do |c|
91
+ c.fast = true
92
+ end
93
+
60
94
  compressor.compress_with do |cmd, ext|
61
95
  cmd.should == 'lzma --fast'
62
96
  ext.should == '.lzma'
63
97
  end
64
98
  end
65
99
 
66
- it 'should yield with the --best and --fast options' do
67
- compressor.best = true
68
- compressor.fast = true
100
+ it 'should prefer the --best option over --fast' do
101
+ compressor = Backup::Compressor::Lzma.new do |c|
102
+ c.best = true
103
+ c.fast = true
104
+ end
105
+
69
106
  compressor.compress_with do |cmd, ext|
70
- cmd.should == 'lzma --best --fast'
107
+ cmd.should == 'lzma --best'
71
108
  ext.should == '.lzma'
72
109
  end
73
110
  end
74
111
 
75
112
  it 'should yield with no options' do
113
+ compressor = Backup::Compressor::Lzma.new
114
+
76
115
  compressor.compress_with do |cmd, ext|
77
116
  cmd.should == 'lzma'
78
117
  ext.should == '.lzma'
79
118
  end
80
119
  end
120
+
81
121
  end # describe '#compress_with'
82
122
 
83
123
  end
@@ -3,66 +3,90 @@
3
3
  require File.expand_path('../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Compressor::Pbzip2 do
6
- let(:compressor) { Backup::Compressor::Pbzip2.new }
6
+ before do
7
+ Backup::Compressor::Pbzip2.any_instance.stubs(:utility).returns('pbzip2')
8
+ end
7
9
 
8
- describe 'setting configuration defaults' do
9
- after { Backup::Configuration::Compressor::Pbzip2.clear_defaults! }
10
+ it 'should be a subclass of Compressor::Base' do
11
+ Backup::Compressor::Pbzip2.
12
+ superclass.should == Backup::Compressor::Base
13
+ end
10
14
 
11
- it 'uses and overrides configuration defaults' do
12
- Backup::Configuration::Compressor::Pbzip2.best.should be_false
13
- Backup::Configuration::Compressor::Pbzip2.fast.should be_false
14
- Backup::Configuration::Compressor::Pbzip2.processors.should be_false
15
+ describe '#initialize' do
16
+ let(:compressor) { Backup::Compressor::Pbzip2.new }
15
17
 
16
- compressor = Backup::Compressor::Pbzip2.new
17
- compressor.best.should be_false
18
- compressor.fast.should be_false
19
- compressor.processors.should be_false
18
+ after { Backup::Compressor::Pbzip2.clear_defaults! }
20
19
 
21
- Backup::Configuration::Compressor::Pbzip2.defaults do |c|
22
- c.best = true
23
- c.fast = true
24
- c.processors = 2
20
+ it 'should load pre-configured defaults' do
21
+ Backup::Compressor::Pbzip2.any_instance.expects(:load_defaults!)
22
+ compressor
23
+ end
24
+
25
+ context 'when no pre-configured defaults have been set' do
26
+ it 'should use default values' do
27
+ compressor.best.should be_false
28
+ compressor.fast.should be_false
29
+ compressor.processors.should be_false
25
30
  end
26
- Backup::Configuration::Compressor::Pbzip2.best.should be_true
27
- Backup::Configuration::Compressor::Pbzip2.fast.should be_true
28
- Backup::Configuration::Compressor::Pbzip2.processors.should == 2
29
31
 
30
- compressor = Backup::Compressor::Pbzip2.new
31
- compressor.best.should be_true
32
- compressor.fast.should be_true
33
- compressor.processors.should == 2
32
+ it 'should use the values given' do
33
+ compressor = Backup::Compressor::Pbzip2.new do |c|
34
+ c.best = true
35
+ c.fast = true
36
+ c.processors = 2
37
+ end
34
38
 
35
- compressor = Backup::Compressor::Pbzip2.new do |c|
36
- c.best = false
39
+ compressor.best.should be_true
40
+ compressor.fast.should be_true
41
+ compressor.processors.should == 2
42
+ end
43
+ end # context 'when no pre-configured defaults have been set'
44
+
45
+ context 'when pre-configured defaults have been set' do
46
+ before do
47
+ Backup::Compressor::Pbzip2.defaults do |c|
48
+ c.best = true
49
+ c.fast = true
50
+ c.processors = 2
51
+ end
37
52
  end
38
- compressor.best.should be_false
39
- compressor.fast.should be_true
40
- compressor.processors.should == 2
41
53
 
42
- compressor = Backup::Compressor::Pbzip2.new do |c|
43
- c.fast = false
54
+ it 'should use pre-configured defaults' do
55
+ compressor.best.should be_true
56
+ compressor.fast.should be_true
57
+ compressor.processors.should == 2
44
58
  end
45
- compressor.best.should be_true
46
- compressor.fast.should be_false
47
- compressor.processors.should == 2
48
59
 
49
- compressor = Backup::Compressor::Pbzip2.new do |c|
50
- c.processors = false
60
+ it 'should override pre-configured defaults' do
61
+ compressor = Backup::Compressor::Pbzip2.new do |c|
62
+ c.best = false
63
+ c.fast = false
64
+ c.processors = 4
65
+ end
66
+
67
+ compressor.best.should be_false
68
+ compressor.fast.should be_false
69
+ compressor.processors.should == 4
51
70
  end
52
- compressor.best.should be_true
53
- compressor.fast.should be_true
54
- compressor.processors.should be_false
55
- end
56
- end # describe 'setting configuration defaults'
71
+ end # context 'when pre-configured defaults have been set'
72
+ end # describe '#initialize'
57
73
 
58
74
  describe '#compress_with' do
59
75
  before do
60
- compressor.expects(:log!)
61
- compressor.expects(:utility).with(:pbzip2).returns('pbzip2')
76
+ Backup::Compressor::Pbzip2.any_instance.expects(:log!)
77
+
78
+ Backup::Logger.expects(:warn).with do |msg|
79
+ msg.should match(
80
+ /\[DEPRECATION WARNING\]\n Compressor::Pbzip2 is being deprecated/
81
+ )
82
+ end
62
83
  end
63
84
 
64
85
  it 'should yield with the --best option' do
65
- compressor.best = true
86
+ compressor = Backup::Compressor::Pbzip2.new do |c|
87
+ c.best = true
88
+ end
89
+
66
90
  compressor.compress_with do |cmd, ext|
67
91
  cmd.should == 'pbzip2 --best'
68
92
  ext.should == '.bz2'
@@ -70,7 +94,10 @@ describe Backup::Compressor::Pbzip2 do
70
94
  end
71
95
 
72
96
  it 'should yield with the --fast option' do
73
- compressor.fast = true
97
+ compressor = Backup::Compressor::Pbzip2.new do |c|
98
+ c.fast = true
99
+ end
100
+
74
101
  compressor.compress_with do |cmd, ext|
75
102
  cmd.should == 'pbzip2 --fast'
76
103
  ext.should == '.bz2'
@@ -78,25 +105,34 @@ describe Backup::Compressor::Pbzip2 do
78
105
  end
79
106
 
80
107
  it 'should yield with the -p option' do
81
- compressor.processors = 2
108
+ compressor = Backup::Compressor::Pbzip2.new do |c|
109
+ c.processors = 2
110
+ end
111
+
82
112
  compressor.compress_with do |cmd, ext|
83
113
  cmd.should == 'pbzip2 -p2'
84
114
  ext.should == '.bz2'
85
115
  end
86
116
  end
87
117
 
88
- it 'should yield with the --best and --fast options' do
89
- compressor.best = true
90
- compressor.fast = true
118
+ it 'should prefer the --best option over --fast' do
119
+ compressor = Backup::Compressor::Pbzip2.new do |c|
120
+ c.best = true
121
+ c.fast = true
122
+ end
123
+
91
124
  compressor.compress_with do |cmd, ext|
92
- cmd.should == 'pbzip2 --best --fast'
125
+ cmd.should == 'pbzip2 --best'
93
126
  ext.should == '.bz2'
94
127
  end
95
128
  end
96
129
 
97
130
  it 'should yield with the --best and -p options' do
98
- compressor.best = true
99
- compressor.processors = 2
131
+ compressor = Backup::Compressor::Pbzip2.new do |c|
132
+ c.best = true
133
+ c.processors = 2
134
+ end
135
+
100
136
  compressor.compress_with do |cmd, ext|
101
137
  cmd.should == 'pbzip2 --best -p2'
102
138
  ext.should == '.bz2'
@@ -104,8 +140,11 @@ describe Backup::Compressor::Pbzip2 do
104
140
  end
105
141
 
106
142
  it 'should yield with the --fast and -p options' do
107
- compressor.fast = true
108
- compressor.processors = 2
143
+ compressor = Backup::Compressor::Pbzip2.new do |c|
144
+ c.fast = true
145
+ c.processors = 2
146
+ end
147
+
109
148
  compressor.compress_with do |cmd, ext|
110
149
  cmd.should == 'pbzip2 --fast -p2'
111
150
  ext.should == '.bz2'
@@ -113,6 +152,8 @@ describe Backup::Compressor::Pbzip2 do
113
152
  end
114
153
 
115
154
  it 'should yield with no options' do
155
+ compressor = Backup::Compressor::Pbzip2.new
156
+
116
157
  compressor.compress_with do |cmd, ext|
117
158
  cmd.should == 'pbzip2'
118
159
  ext.should == '.bz2'