backup-agoddard 3.0.27

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of backup-agoddard might be problematic. Click here for more details.

Files changed (190) hide show
  1. data/.gitignore +8 -0
  2. data/.travis.yml +10 -0
  3. data/Gemfile +28 -0
  4. data/Guardfile +23 -0
  5. data/LICENSE.md +24 -0
  6. data/README.md +478 -0
  7. data/backup.gemspec +32 -0
  8. data/bin/backup +11 -0
  9. data/lib/backup.rb +133 -0
  10. data/lib/backup/archive.rb +117 -0
  11. data/lib/backup/binder.rb +22 -0
  12. data/lib/backup/cleaner.rb +121 -0
  13. data/lib/backup/cli/helpers.rb +93 -0
  14. data/lib/backup/cli/utility.rb +255 -0
  15. data/lib/backup/compressor/base.rb +35 -0
  16. data/lib/backup/compressor/bzip2.rb +50 -0
  17. data/lib/backup/compressor/custom.rb +53 -0
  18. data/lib/backup/compressor/gzip.rb +50 -0
  19. data/lib/backup/compressor/lzma.rb +52 -0
  20. data/lib/backup/compressor/pbzip2.rb +59 -0
  21. data/lib/backup/config.rb +174 -0
  22. data/lib/backup/configuration.rb +33 -0
  23. data/lib/backup/configuration/helpers.rb +130 -0
  24. data/lib/backup/configuration/store.rb +24 -0
  25. data/lib/backup/database/base.rb +53 -0
  26. data/lib/backup/database/mongodb.rb +230 -0
  27. data/lib/backup/database/mysql.rb +160 -0
  28. data/lib/backup/database/postgresql.rb +144 -0
  29. data/lib/backup/database/redis.rb +136 -0
  30. data/lib/backup/database/riak.rb +67 -0
  31. data/lib/backup/dependency.rb +108 -0
  32. data/lib/backup/encryptor/base.rb +29 -0
  33. data/lib/backup/encryptor/gpg.rb +760 -0
  34. data/lib/backup/encryptor/open_ssl.rb +72 -0
  35. data/lib/backup/errors.rb +124 -0
  36. data/lib/backup/hooks.rb +68 -0
  37. data/lib/backup/logger.rb +152 -0
  38. data/lib/backup/model.rb +409 -0
  39. data/lib/backup/notifier/base.rb +81 -0
  40. data/lib/backup/notifier/campfire.rb +155 -0
  41. data/lib/backup/notifier/hipchat.rb +93 -0
  42. data/lib/backup/notifier/mail.rb +206 -0
  43. data/lib/backup/notifier/prowl.rb +65 -0
  44. data/lib/backup/notifier/pushover.rb +88 -0
  45. data/lib/backup/notifier/twitter.rb +70 -0
  46. data/lib/backup/package.rb +47 -0
  47. data/lib/backup/packager.rb +100 -0
  48. data/lib/backup/pipeline.rb +110 -0
  49. data/lib/backup/splitter.rb +75 -0
  50. data/lib/backup/storage/base.rb +99 -0
  51. data/lib/backup/storage/cloudfiles.rb +87 -0
  52. data/lib/backup/storage/cycler.rb +117 -0
  53. data/lib/backup/storage/dropbox.rb +178 -0
  54. data/lib/backup/storage/ftp.rb +119 -0
  55. data/lib/backup/storage/local.rb +82 -0
  56. data/lib/backup/storage/ninefold.rb +116 -0
  57. data/lib/backup/storage/rsync.rb +149 -0
  58. data/lib/backup/storage/s3.rb +94 -0
  59. data/lib/backup/storage/scp.rb +99 -0
  60. data/lib/backup/storage/sftp.rb +108 -0
  61. data/lib/backup/syncer/base.rb +46 -0
  62. data/lib/backup/syncer/cloud/base.rb +247 -0
  63. data/lib/backup/syncer/cloud/cloud_files.rb +78 -0
  64. data/lib/backup/syncer/cloud/s3.rb +68 -0
  65. data/lib/backup/syncer/rsync/base.rb +49 -0
  66. data/lib/backup/syncer/rsync/local.rb +55 -0
  67. data/lib/backup/syncer/rsync/pull.rb +36 -0
  68. data/lib/backup/syncer/rsync/push.rb +116 -0
  69. data/lib/backup/template.rb +46 -0
  70. data/lib/backup/version.rb +43 -0
  71. data/spec-live/.gitignore +6 -0
  72. data/spec-live/README +7 -0
  73. data/spec-live/backups/config.rb +83 -0
  74. data/spec-live/backups/config.yml.template +46 -0
  75. data/spec-live/backups/models.rb +184 -0
  76. data/spec-live/compressor/custom_spec.rb +30 -0
  77. data/spec-live/compressor/gzip_spec.rb +30 -0
  78. data/spec-live/encryptor/gpg_keys.rb +239 -0
  79. data/spec-live/encryptor/gpg_spec.rb +287 -0
  80. data/spec-live/notifier/mail_spec.rb +121 -0
  81. data/spec-live/spec_helper.rb +151 -0
  82. data/spec-live/storage/dropbox_spec.rb +151 -0
  83. data/spec-live/storage/local_spec.rb +83 -0
  84. data/spec-live/storage/scp_spec.rb +193 -0
  85. data/spec-live/syncer/cloud/s3_spec.rb +124 -0
  86. data/spec/archive_spec.rb +335 -0
  87. data/spec/cleaner_spec.rb +312 -0
  88. data/spec/cli/helpers_spec.rb +301 -0
  89. data/spec/cli/utility_spec.rb +411 -0
  90. data/spec/compressor/base_spec.rb +52 -0
  91. data/spec/compressor/bzip2_spec.rb +217 -0
  92. data/spec/compressor/custom_spec.rb +106 -0
  93. data/spec/compressor/gzip_spec.rb +217 -0
  94. data/spec/compressor/lzma_spec.rb +123 -0
  95. data/spec/compressor/pbzip2_spec.rb +165 -0
  96. data/spec/config_spec.rb +321 -0
  97. data/spec/configuration/helpers_spec.rb +247 -0
  98. data/spec/configuration/store_spec.rb +39 -0
  99. data/spec/configuration_spec.rb +62 -0
  100. data/spec/database/base_spec.rb +63 -0
  101. data/spec/database/mongodb_spec.rb +510 -0
  102. data/spec/database/mysql_spec.rb +411 -0
  103. data/spec/database/postgresql_spec.rb +353 -0
  104. data/spec/database/redis_spec.rb +334 -0
  105. data/spec/database/riak_spec.rb +176 -0
  106. data/spec/dependency_spec.rb +51 -0
  107. data/spec/encryptor/base_spec.rb +40 -0
  108. data/spec/encryptor/gpg_spec.rb +909 -0
  109. data/spec/encryptor/open_ssl_spec.rb +148 -0
  110. data/spec/errors_spec.rb +306 -0
  111. data/spec/hooks_spec.rb +35 -0
  112. data/spec/logger_spec.rb +367 -0
  113. data/spec/model_spec.rb +694 -0
  114. data/spec/notifier/base_spec.rb +104 -0
  115. data/spec/notifier/campfire_spec.rb +217 -0
  116. data/spec/notifier/hipchat_spec.rb +211 -0
  117. data/spec/notifier/mail_spec.rb +316 -0
  118. data/spec/notifier/prowl_spec.rb +138 -0
  119. data/spec/notifier/pushover_spec.rb +123 -0
  120. data/spec/notifier/twitter_spec.rb +153 -0
  121. data/spec/package_spec.rb +61 -0
  122. data/spec/packager_spec.rb +213 -0
  123. data/spec/pipeline_spec.rb +259 -0
  124. data/spec/spec_helper.rb +60 -0
  125. data/spec/splitter_spec.rb +120 -0
  126. data/spec/storage/base_spec.rb +166 -0
  127. data/spec/storage/cloudfiles_spec.rb +254 -0
  128. data/spec/storage/cycler_spec.rb +247 -0
  129. data/spec/storage/dropbox_spec.rb +480 -0
  130. data/spec/storage/ftp_spec.rb +271 -0
  131. data/spec/storage/local_spec.rb +259 -0
  132. data/spec/storage/ninefold_spec.rb +343 -0
  133. data/spec/storage/rsync_spec.rb +362 -0
  134. data/spec/storage/s3_spec.rb +245 -0
  135. data/spec/storage/scp_spec.rb +233 -0
  136. data/spec/storage/sftp_spec.rb +244 -0
  137. data/spec/syncer/base_spec.rb +109 -0
  138. data/spec/syncer/cloud/base_spec.rb +515 -0
  139. data/spec/syncer/cloud/cloud_files_spec.rb +181 -0
  140. data/spec/syncer/cloud/s3_spec.rb +174 -0
  141. data/spec/syncer/rsync/base_spec.rb +98 -0
  142. data/spec/syncer/rsync/local_spec.rb +149 -0
  143. data/spec/syncer/rsync/pull_spec.rb +98 -0
  144. data/spec/syncer/rsync/push_spec.rb +333 -0
  145. data/spec/version_spec.rb +21 -0
  146. data/templates/cli/utility/archive +25 -0
  147. data/templates/cli/utility/compressor/bzip2 +4 -0
  148. data/templates/cli/utility/compressor/custom +11 -0
  149. data/templates/cli/utility/compressor/gzip +4 -0
  150. data/templates/cli/utility/compressor/lzma +10 -0
  151. data/templates/cli/utility/compressor/pbzip2 +10 -0
  152. data/templates/cli/utility/config +32 -0
  153. data/templates/cli/utility/database/mongodb +18 -0
  154. data/templates/cli/utility/database/mysql +21 -0
  155. data/templates/cli/utility/database/postgresql +17 -0
  156. data/templates/cli/utility/database/redis +16 -0
  157. data/templates/cli/utility/database/riak +11 -0
  158. data/templates/cli/utility/encryptor/gpg +27 -0
  159. data/templates/cli/utility/encryptor/openssl +9 -0
  160. data/templates/cli/utility/model.erb +23 -0
  161. data/templates/cli/utility/notifier/campfire +12 -0
  162. data/templates/cli/utility/notifier/hipchat +15 -0
  163. data/templates/cli/utility/notifier/mail +22 -0
  164. data/templates/cli/utility/notifier/prowl +11 -0
  165. data/templates/cli/utility/notifier/pushover +11 -0
  166. data/templates/cli/utility/notifier/twitter +13 -0
  167. data/templates/cli/utility/splitter +7 -0
  168. data/templates/cli/utility/storage/cloud_files +22 -0
  169. data/templates/cli/utility/storage/dropbox +20 -0
  170. data/templates/cli/utility/storage/ftp +12 -0
  171. data/templates/cli/utility/storage/local +7 -0
  172. data/templates/cli/utility/storage/ninefold +9 -0
  173. data/templates/cli/utility/storage/rsync +11 -0
  174. data/templates/cli/utility/storage/s3 +19 -0
  175. data/templates/cli/utility/storage/scp +11 -0
  176. data/templates/cli/utility/storage/sftp +11 -0
  177. data/templates/cli/utility/syncer/cloud_files +46 -0
  178. data/templates/cli/utility/syncer/rsync_local +12 -0
  179. data/templates/cli/utility/syncer/rsync_pull +17 -0
  180. data/templates/cli/utility/syncer/rsync_push +17 -0
  181. data/templates/cli/utility/syncer/s3 +43 -0
  182. data/templates/general/links +11 -0
  183. data/templates/general/version.erb +2 -0
  184. data/templates/notifier/mail/failure.erb +9 -0
  185. data/templates/notifier/mail/success.erb +7 -0
  186. data/templates/notifier/mail/warning.erb +9 -0
  187. data/templates/storage/dropbox/authorization_url.erb +6 -0
  188. data/templates/storage/dropbox/authorized.erb +4 -0
  189. data/templates/storage/dropbox/cache_file_written.erb +10 -0
  190. metadata +277 -0
@@ -0,0 +1,148 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Encryptor::OpenSSL do
6
+ let(:encryptor) do
7
+ Backup::Encryptor::OpenSSL.new do |e|
8
+ e.password = 'mypassword'
9
+ e.password_file = '/my/password/file'
10
+ e.base64 = true
11
+ e.salt = true
12
+ end
13
+ end
14
+
15
+ it 'should be a subclass of Encryptor::Base' do
16
+ Backup::Encryptor::OpenSSL.
17
+ superclass.should == Backup::Encryptor::Base
18
+ end
19
+
20
+ describe '#initialize' do
21
+ after { Backup::Encryptor::OpenSSL.clear_defaults! }
22
+
23
+ it 'should load pre-configured defaults' do
24
+ Backup::Encryptor::OpenSSL.any_instance.expects(:load_defaults!)
25
+ encryptor
26
+ end
27
+
28
+ context 'when no pre-configured defaults have been set' do
29
+ it 'should use the values given' do
30
+ encryptor.password.should == 'mypassword'
31
+ encryptor.password_file.should == '/my/password/file'
32
+ encryptor.base64.should == true
33
+ encryptor.salt.should == true
34
+ end
35
+
36
+ it 'should use default values if none are given' do
37
+ encryptor = Backup::Encryptor::OpenSSL.new
38
+ encryptor.password.should be_nil
39
+ encryptor.password_file.should be_nil
40
+ encryptor.base64.should be_false
41
+ encryptor.salt.should be_true
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::Encryptor::OpenSSL.defaults do |e|
48
+ e.password = 'default_password'
49
+ e.password_file = '/default/password/file'
50
+ e.base64 = 'default_base64'
51
+ e.salt = 'default_salt'
52
+ end
53
+ end
54
+
55
+ it 'should use pre-configured defaults' do
56
+ encryptor = Backup::Encryptor::OpenSSL.new
57
+ encryptor.password = 'default_password'
58
+ encryptor.password_file = '/default/password/file'
59
+ encryptor.base64 = 'default_base64'
60
+ encryptor.salt = 'default_salt'
61
+ end
62
+
63
+ it 'should override pre-configured defaults' do
64
+ encryptor.password.should == 'mypassword'
65
+ encryptor.password_file.should == '/my/password/file'
66
+ encryptor.base64.should == true
67
+ encryptor.salt.should == true
68
+ end
69
+ end # context 'when pre-configured defaults have been set'
70
+ end # describe '#initialize'
71
+
72
+ describe '#encrypt_with' do
73
+ it 'should yield the encryption command and extension' do
74
+ encryptor.expects(:log!)
75
+ encryptor.expects(:utility).with(:openssl).returns('openssl_cmd')
76
+ encryptor.expects(:options).returns('cmd_options')
77
+
78
+ encryptor.encrypt_with do |command, ext|
79
+ command.should == 'openssl_cmd cmd_options'
80
+ ext.should == '.enc'
81
+ end
82
+ end
83
+ end
84
+
85
+ describe '#options' do
86
+ let(:encryptor) { Backup::Encryptor::OpenSSL.new }
87
+
88
+ before do
89
+ # salt is true by default
90
+ encryptor.salt = false
91
+ end
92
+
93
+ context 'with no options given' do
94
+ it 'should always include cipher command' do
95
+ encryptor.send(:options).should match(/^aes-256-cbc\s.*$/)
96
+ end
97
+
98
+ it 'should add #password option whenever #password_file not given' do
99
+ encryptor.send(:options).should ==
100
+ "aes-256-cbc -k ''"
101
+ end
102
+ end
103
+
104
+ context 'when #password_file is given' do
105
+ before { encryptor.password_file = 'password_file' }
106
+
107
+ it 'should add #password_file option' do
108
+ encryptor.send(:options).should ==
109
+ 'aes-256-cbc -pass file:password_file'
110
+ end
111
+
112
+ it 'should add #password_file option even when #password given' do
113
+ encryptor.password = 'password'
114
+ encryptor.send(:options).should ==
115
+ 'aes-256-cbc -pass file:password_file'
116
+ end
117
+ end
118
+
119
+ context 'when #password is given (without #password_file given)' do
120
+ before { encryptor.password = 'password' }
121
+
122
+ it 'should include the given password in the #password option' do
123
+ encryptor.send(:options).should ==
124
+ "aes-256-cbc -k 'password'"
125
+ end
126
+ end
127
+
128
+ context 'when #base64 is true' do
129
+ before { encryptor.base64 = true }
130
+
131
+ it 'should add the option' do
132
+ encryptor.send(:options).should ==
133
+ "aes-256-cbc -base64 -k ''"
134
+ end
135
+ end
136
+
137
+ context 'when #salt is true' do
138
+ before { encryptor.salt = true }
139
+
140
+ it 'should add the option' do
141
+ encryptor.send(:options).should ==
142
+ "aes-256-cbc -salt -k ''"
143
+ end
144
+ end
145
+
146
+ end # describe '#options'
147
+
148
+ end
@@ -0,0 +1,306 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../spec_helper.rb', __FILE__)
4
+
5
+ # Note: none of these tests require the use of the ErrorsHelper
6
+ describe 'Errors::Error' do
7
+ let(:klass) { Backup::Errors::Error }
8
+
9
+ it 'allow errors to cascade through the system' do
10
+ class ErrorA < klass; end
11
+ class ErrorB < klass; end
12
+ class ErrorC < klass; end
13
+ class ErrorD < klass; end
14
+
15
+ expect do
16
+ begin
17
+ begin
18
+ begin
19
+ raise ErrorA, 'an error occurred in Zone A'
20
+ rescue => err
21
+ raise ErrorB.wrap(err, <<-EOS)
22
+ an error occurred in Zone B
23
+
24
+ the following error should give a reason
25
+ EOS
26
+ end
27
+ rescue => err
28
+ raise ErrorC.wrap(err)
29
+ end
30
+ rescue => err
31
+ raise ErrorD.wrap(err, 'an error occurred in Zone D')
32
+ end
33
+ end.to raise_error(ErrorD,
34
+ "ErrorD: an error occurred in Zone D\n" +
35
+ " Reason: ErrorC\n" +
36
+ " ErrorB: an error occurred in Zone B\n" +
37
+ " \n" +
38
+ " the following error should give a reason\n" +
39
+ " Reason: ErrorA\n" +
40
+ " an error occurred in Zone A"
41
+ )
42
+ end
43
+
44
+ describe '#initialize' do
45
+
46
+ it 'creates a StandardError' do
47
+ klass.new.should be_a_kind_of StandardError
48
+ end
49
+
50
+ context 'when given a message' do
51
+
52
+ it 'formats a simple message' do
53
+ err = klass.new('error message')
54
+ err.message.should == 'Error: error message'
55
+ end
56
+
57
+ it 'formats a multi-line message' do
58
+ err = klass.new(" error message\n" +
59
+ " This is a multi-line error message.\n" +
60
+ "It should be properly indented. ")
61
+
62
+ err.message.should == "Error: error message\n" +
63
+ " This is a multi-line error message.\n" +
64
+ " It should be properly indented."
65
+ end
66
+
67
+ context 'when given an original error' do
68
+
69
+ it 'includes the original error' do
70
+ orig_err = StandardError.new('original message')
71
+ err = klass.new('error message', orig_err)
72
+ err.message.should == "Error: error message\n" +
73
+ " Reason: StandardError\n" +
74
+ " original message"
75
+ end
76
+
77
+ it 'formats all messages' do
78
+ orig_err = StandardError.new(" original message\n" +
79
+ " This is a multi-line error message.\n" +
80
+ "It should be properly indented.")
81
+ err = klass.new(" error message\n" +
82
+ " This is a multi-line error message.\n" +
83
+ "It should be properly indented. ", orig_err)
84
+
85
+ err.message.should == "Error: error message\n" +
86
+ " This is a multi-line error message.\n" +
87
+ " It should be properly indented.\n" +
88
+ " Reason: StandardError\n" +
89
+ " original message\n" +
90
+ " This is a multi-line error message.\n" +
91
+ " It should be properly indented."
92
+ end
93
+
94
+ it 'uses the original error backtrace' do
95
+ begin
96
+ raise StandardError.new
97
+ rescue => err
98
+ klass.new(nil, err).backtrace.
99
+ should == err.backtrace
100
+ end
101
+ end
102
+
103
+ it 'reports if original error had no message' do
104
+ orig_err = StandardError.new
105
+ err = klass.new('error message', orig_err)
106
+ err.message.should == "Error: error message\n" +
107
+ " Reason: StandardError (no message given)"
108
+ end
109
+
110
+ end # context 'when given an original error'
111
+
112
+ context 'when given an original Errors::Error' do
113
+ let(:subklass) do
114
+ class SubKlass < klass; end
115
+ SubKlass
116
+ end
117
+
118
+ it 'includes the original error' do
119
+ orig_err = subklass.new('original message')
120
+ err = klass.new('error message', orig_err)
121
+ err.message.should == "Error: error message\n" +
122
+ " Reason: SubKlass\n" +
123
+ " original message"
124
+ end
125
+
126
+ it 'formats all messages' do
127
+ orig_err = subklass.new(" original message\n" +
128
+ " This is a multi-line error message.\n" +
129
+ "It should be properly indented.")
130
+ err = klass.new(" error message\n" +
131
+ " This is a multi-line error message.\n" +
132
+ "It should be properly indented. ", orig_err)
133
+
134
+ err.message.should == "Error: error message\n" +
135
+ " This is a multi-line error message.\n" +
136
+ " It should be properly indented.\n" +
137
+ " Reason: SubKlass\n" +
138
+ " original message\n" +
139
+ " This is a multi-line error message.\n" +
140
+ " It should be properly indented."
141
+ end
142
+
143
+ it 'uses the original error backtrace' do
144
+ begin
145
+ raise subklass.new
146
+ rescue => err
147
+ klass.new(nil, err).backtrace.
148
+ should == err.backtrace
149
+ end
150
+ end
151
+
152
+ it 'reports if original error had no message' do
153
+ orig_err = subklass.new
154
+ err = klass.new('error message', orig_err)
155
+ err.message.should == "Error: error message\n" +
156
+ " Reason: SubKlass (no message given)"
157
+ end
158
+
159
+ end # context 'when given an original Errors::Error'
160
+
161
+ end # context 'when given a message'
162
+
163
+ context 'when given no message' do
164
+
165
+ it 'strips the module namespace from the default message' do
166
+ err = klass.new
167
+ err.message.should == 'Error'
168
+ end
169
+
170
+ context 'when given an original error' do
171
+
172
+ it 'uses the original error message' do
173
+ orig_err = StandardError.new
174
+ err = klass.new(nil, orig_err)
175
+ err.message.should == 'Error: StandardError'
176
+
177
+ orig_err = StandardError.new('original message')
178
+ err = klass.new(nil, orig_err)
179
+ err.message.should == 'Error: StandardError: original message'
180
+
181
+ orig_err = StandardError.new(" original message\n" +
182
+ " This is a multi-line error message.\n" +
183
+ "It should be properly indented.")
184
+ err = klass.new(nil, orig_err)
185
+ err.message.should == "Error: StandardError: original message\n" +
186
+ " This is a multi-line error message.\n" +
187
+ " It should be properly indented."
188
+ end
189
+
190
+ end # context 'when given an original error'
191
+
192
+ context 'when given an original Errors::Error' do
193
+ let(:subklass) do
194
+ class SubKlass < klass; end
195
+ SubKlass
196
+ end
197
+
198
+ it 'uses the original error message' do
199
+ orig_err = subklass.new
200
+ err = klass.new(nil, orig_err)
201
+ err.message.should == 'Error: SubKlass'
202
+
203
+ orig_err = subklass.new('original message')
204
+ err = klass.new(nil, orig_err)
205
+ err.message.should == 'Error: SubKlass: original message'
206
+
207
+ orig_err = subklass.new(" original message\n" +
208
+ " This is a multi-line error message.\n" +
209
+ "It should be properly indented.")
210
+ err = klass.new(nil, orig_err)
211
+ err.message.should == "Error: SubKlass: original message\n" +
212
+ " This is a multi-line error message.\n" +
213
+ " It should be properly indented."
214
+ end
215
+
216
+ end # context 'when given an original Errors::Error'
217
+
218
+ end # context 'when given no message'
219
+
220
+ end # describe '#initialize'
221
+
222
+ describe '#wrap' do
223
+ describe 'swaps the parameters to provide a cleaner way to' do
224
+
225
+ it 'raise a wrapped error with a message' do
226
+ orig_err = StandardError.new <<-EOS
227
+ original message
228
+ This is a multi-line error message.
229
+ It should be properly indented.
230
+ EOS
231
+
232
+ expect do
233
+ raise klass.wrap(orig_err), <<-EOS
234
+ error message
235
+ This is a multi-line error message.
236
+ It should be properly indented.
237
+ EOS
238
+ end.to raise_error(klass,
239
+ "Error: error message\n" +
240
+ " This is a multi-line error message.\n" +
241
+ " It should be properly indented.\n" +
242
+ " Reason: StandardError\n" +
243
+ " original message\n" +
244
+ " This is a multi-line error message.\n" +
245
+ " It should be properly indented."
246
+ )
247
+ end
248
+
249
+ it 'return a wrapped error with a message' do
250
+ orig_err = StandardError.new <<-EOS
251
+ original message
252
+ This is a multi-line error message.
253
+ It should be properly indented.
254
+ EOS
255
+
256
+ err = klass.wrap(orig_err, <<-EOS)
257
+ error message
258
+ This will wrap the original error
259
+ and it's message will be given below
260
+ EOS
261
+
262
+ err.message.should ==
263
+ "Error: error message\n" +
264
+ " This will wrap the original error\n" +
265
+ " and it's message will be given below\n" +
266
+ " Reason: StandardError\n" +
267
+ " original message\n" +
268
+ " This is a multi-line error message.\n" +
269
+ " It should be properly indented."
270
+ end
271
+
272
+ end # describe 'swaps the parameters to provide a cleaner way to'
273
+ end # describe '#wrap'
274
+
275
+ end # describe 'Errors::Error'
276
+
277
+ describe 'ErrorHelper' do
278
+ let(:base) { Backup::Errors }
279
+
280
+ it 'dynamically creates namespaces and subclasses of Errors::Error' do
281
+ Backup::Errors::FooBarError.new.
282
+ should be_a_kind_of base::Error
283
+ Backup::Errors::Foo::Bar::Error.new.
284
+ should be_a_kind_of base::Error
285
+ end
286
+
287
+ context 'new error classes created within new namespaces' do
288
+ it 'retain the added portion of namespace in their messages' do
289
+ orig_err = StandardError.new('original message')
290
+ err = base::FooMod::FooError.new('error message', orig_err)
291
+ err.message.should ==
292
+ "FooMod::FooError: error message\n" +
293
+ " Reason: StandardError\n" +
294
+ " original message"
295
+
296
+ err2 = base::Foo::Bar::Mod::FooBarError.wrap(err, 'foobar message')
297
+ err2.message.should ==
298
+ "Foo::Bar::Mod::FooBarError: foobar message\n" +
299
+ " Reason: FooMod::FooError\n" +
300
+ " error message\n" +
301
+ " Reason: StandardError\n" +
302
+ " original message"
303
+ end
304
+ end
305
+
306
+ end # describe ErrorHelper